github.com/Finschia/finschia-sdk@v0.48.1/x/bank/keeper/genesis.go (about) 1 package keeper 2 3 import ( 4 "fmt" 5 6 sdk "github.com/Finschia/finschia-sdk/types" 7 "github.com/Finschia/finschia-sdk/types/query" 8 "github.com/Finschia/finschia-sdk/x/bank/types" 9 ) 10 11 // InitGenesis initializes the bank module's state from a given genesis state. 12 func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { 13 k.SetParams(ctx, genState.Params) 14 15 totalSupply := sdk.Coins{} 16 17 genState.Balances = types.SanitizeGenesisBalances(genState.Balances) 18 for _, balance := range genState.Balances { 19 addr := balance.GetAddress() 20 21 if err := k.initBalances(ctx, addr, balance.Coins); err != nil { 22 panic(fmt.Errorf("error on setting balances %w", err)) 23 } 24 25 totalSupply = totalSupply.Add(balance.Coins...) 26 } 27 28 if !genState.Supply.Empty() && !genState.Supply.IsEqual(totalSupply) { 29 panic(fmt.Errorf("genesis supply is incorrect, expected %v, got %v", genState.Supply, totalSupply)) 30 } 31 32 for _, supply := range totalSupply { 33 k.setSupply(ctx, supply) 34 } 35 36 for _, meta := range genState.DenomMetadata { 37 k.SetDenomMetaData(ctx, meta) 38 } 39 } 40 41 // ExportGenesis returns the bank module's genesis state. 42 func (k BaseKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { 43 totalSupply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.MaxLimit}) 44 if err != nil { 45 panic(fmt.Errorf("unable to fetch total supply %v", err)) 46 } 47 48 return types.NewGenesisState( 49 k.GetParams(ctx), 50 k.GetAccountsBalances(ctx), 51 totalSupply, 52 k.GetAllDenomMetaData(ctx), 53 ) 54 }