0g-chain/x/auction/genesis.go

35 lines
832 B
Go
Raw Normal View History

2019-11-25 19:46:02 +00:00
package auction
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// InitGenesis - initializes the store state from genesis data
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) {
keeper.SetNextAuctionID(ctx, data.NextAuctionID)
2019-11-25 19:46:02 +00:00
keeper.SetParams(ctx, data.AuctionParams)
for _, a := range data.Auctions {
keeper.SetAuction(ctx, a)
}
}
// ExportGenesis returns a GenesisState for a given context and keeper.
func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState {
nextAuctionID, err := keeper.GetNextAuctionID(ctx)
if err != nil {
panic(err)
}
2019-11-25 19:46:02 +00:00
params := keeper.GetParams(ctx)
var genAuctions GenesisAuctions
2019-12-21 01:04:04 +00:00
keeper.IterateAuctions(ctx, func(a Auction) bool {
genAuctions = append(genAuctions, a)
return false
})
2019-11-25 19:46:02 +00:00
return NewGenesisState(nextAuctionID, params, genAuctions)
2019-11-25 19:46:02 +00:00
}