cosmos-sdk/x/bank/keeper/genesis.go

58 lines
1.5 KiB
Go
Raw Normal View History

2020-07-12 23:55:58 -07:00
package keeper
import (
2020-01-30 13:31:16 -08:00
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
2020-01-30 13:31:16 -08:00
// InitGenesis initializes the bank module's state from a given genesis state.
func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) {
2020-07-12 23:55:58 -07:00
k.SetParams(ctx, genState.Params)
2020-01-30 13:31:16 -08:00
totalSupply := sdk.Coins{}
genState.Balances = types.SanitizeGenesisBalances(genState.Balances)
2020-01-30 13:31:16 -08:00
for _, balance := range genState.Balances {
Change `address` from bytes to bech32 strings (#7242) * init * Fix bank proto messages * missing conversions * remove casttype for addresses * Fix tests * Fix consaddress * more test fixes * Fix tests * fixed tests * migrate missing proto declarations * format * Fix format * Fix alignment * Fix more tests * Fix ibc merge issue * Fix fmt * Fix more tests * Fix missing address declarations * Fix staking tests * Fix more tests * Fix config * fixed tests * Fix more tests * Update staking grpc tests * Fix merge issue * fixed failing tests in x/distr * fixed sim tests * fixed failing tests * Fix bugs * Add logs * fixed slashing issue * Fix staking grpc tests * Fix all bank tests :) * Fix tests in distribution * Fix more tests in distr * Fix slashing tests * Fix statking tests * Fix evidence tests * Fix gov tests * Fix bug in create vesting account * Fix test * remove fmt * fixed gov tests * fixed x/ibc tests * fixed x/ibc-transfer tests * fixed staking tests * fixed staking tests * fixed test * fixed distribution issue * fix pagination test * fmt * lint * fix build * fix format * revert tally tests * revert tally tests * lint * Fix sim test * revert * revert * fixed tally issue * fix tests * revert * fmt * refactor * remove `GetAddress()` * remove fmt * revert fmt.Striger usage * Fix tests * Fix rest test * disable interfacer lint check * make proto-format * add nolint rule * remove stray println Co-authored-by: aleem1314 <aleem.md789@gmail.com> Co-authored-by: atheesh <atheesh@vitwit.com>
2020-09-25 03:25:37 -07:00
addr, err := sdk.AccAddressFromBech32(balance.Address)
if err != nil {
2020-01-30 13:31:16 -08:00
panic(err)
}
if err := k.initBalances(ctx, addr, balance.Coins); err != nil {
panic(fmt.Errorf("error on setting balances %w", err))
}
totalSupply = totalSupply.Add(balance.Coins...)
}
if !genState.Supply.Empty() && !genState.Supply.IsEqual(totalSupply) {
panic(fmt.Errorf("genesis supply is incorrect, expected %v, got %v", genState.Supply, totalSupply))
2020-01-30 13:31:16 -08:00
}
for _, supply := range totalSupply {
k.setSupply(ctx, supply)
}
for _, meta := range genState.DenomMetadata {
k.SetDenomMetaData(ctx, meta)
}
}
2020-01-30 13:31:16 -08:00
// ExportGenesis returns the bank module's genesis state.
func (k BaseKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
totalSupply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.MaxLimit})
if err != nil {
panic(fmt.Errorf("unable to fetch total supply %v", err))
}
return types.NewGenesisState(
k.GetParams(ctx),
k.GetAccountsBalances(ctx),
totalSupply,
k.GetAllDenomMetaData(ctx),
)
}