-
Notifications
You must be signed in to change notification settings - Fork 28
/
genesis.go
57 lines (49 loc) · 1.64 KB
/
genesis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package marketplace
import (
"fmt"
"github.com/OmniFlix/omniflixhub/x/marketplace/keeper"
"github.com/OmniFlix/omniflixhub/x/marketplace/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
if err := genState.ValidateGenesis(); err != nil {
panic(err.Error())
}
for _, l := range genState.Listings {
k.SetListing(ctx, l)
k.SetWithOwner(ctx, l.GetOwner(), l.GetId())
k.SetWithNFTID(ctx, l.GetNftId(), l.GetId())
k.SetWithPriceDenom(ctx, l.Price.GetDenom(), l.GetId())
}
k.SetListingCount(ctx, genState.ListingCount)
k.SetParams(ctx, genState.Params)
for _, al := range genState.Auctions {
k.SetAuctionListing(ctx, al)
k.SetAuctionListingWithOwner(ctx, al.GetOwner(), al.GetId())
k.SetAuctionListingWithNFTID(ctx, al.GetNftId(), al.GetId())
k.SetAuctionListingWithPriceDenom(ctx, al.StartPrice.GetDenom(), al.GetId())
}
for _, b := range genState.Bids {
k.SetBid(ctx, b)
}
k.SetNextAuctionNumber(ctx, genState.NextAuctionNumber)
// check if the module account exists
moduleAcc := k.GetMarketplaceAccount(ctx)
if moduleAcc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
}
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return types.NewGenesisState(
k.GetAllListings(ctx),
k.GetListingCount(ctx),
k.GetParams(ctx),
k.GetAllAuctionListings(ctx),
k.GetAllBids(ctx),
k.GetNextAuctionNumber(ctx),
)
}
func DefaultGenesisState() *types.GenesisState {
return types.NewGenesisState([]types.Listing{}, 0, types.DefaultParams(), []types.AuctionListing{}, []types.Bid{}, 1)
}