-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
genesis.go
49 lines (38 loc) · 1.17 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
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
// InitGenesis initializes the bank module's state from a given genesis state.
func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) {
k.SetParams(ctx, genState.Params)
var totalSupply sdk.Coins
genState.Balances = types.SanitizeGenesisBalances(genState.Balances)
for _, balance := range genState.Balances {
addr, err := sdk.AccAddressFromBech32(balance.Address)
if err != nil {
panic(err)
}
if err := k.setBalances(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 = totalSupply
}
k.setSupply(ctx, genState.Supply)
for _, meta := range genState.DenomMetadata {
k.SetDenomMetaData(ctx, meta)
}
}
// ExportGenesis returns the bank module's genesis state.
func (k BaseKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return types.NewGenesisState(
k.GetParams(ctx),
k.GetAccountsBalances(ctx),
k.GetTotalSupply(ctx),
k.GetAllDenomMetaData(ctx),
)
}