-
Notifications
You must be signed in to change notification settings - Fork 15
/
genesis.go
91 lines (71 loc) · 2.3 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package fiattokenfactory
import (
"github.com/circlefin/noble-fiattokenfactory/x/fiattokenfactory/keeper"
"github.com/circlefin/noble-fiattokenfactory/x/fiattokenfactory/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// InitGenesis initializes the module's state from a provided genesis state.
func InitGenesis(ctx sdk.Context, k *keeper.Keeper, bankKeeper types.BankKeeper, genState types.GenesisState) {
for _, elem := range genState.BlacklistedList {
k.SetBlacklisted(ctx, elem)
}
if genState.Paused != nil {
k.SetPaused(ctx, *genState.Paused)
}
if genState.MasterMinter != nil {
k.SetMasterMinter(ctx, *genState.MasterMinter)
}
for _, elem := range genState.MintersList {
k.SetMinters(ctx, elem)
}
if genState.Pauser != nil {
k.SetPauser(ctx, *genState.Pauser)
}
if genState.Blacklister != nil {
k.SetBlacklister(ctx, *genState.Blacklister)
}
if genState.Owner != nil {
k.SetOwner(ctx, *genState.Owner)
}
for _, elem := range genState.MinterControllerList {
k.SetMinterController(ctx, elem)
}
if genState.MintingDenom != nil {
_, found := bankKeeper.GetDenomMetaData(ctx, genState.MintingDenom.Denom)
if !found {
panic(sdkerrors.Wrapf(types.ErrDenomNotRegistered, "fiattokenfactory minting denom %s is not registered in bank module denom_metadata", genState.MintingDenom.Denom))
}
k.SetMintingDenom(ctx, *genState.MintingDenom)
}
k.SetParams(ctx, genState.Params)
}
// ExportGenesis returns the module's exported GenesisState
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)
genesis.BlacklistedList = k.GetAllBlacklisted(ctx)
paused := k.GetPaused(ctx)
genesis.Paused = &paused
masterMinter, found := k.GetMasterMinter(ctx)
if found {
genesis.MasterMinter = &masterMinter
}
genesis.MintersList = k.GetAllMinters(ctx)
pauser, found := k.GetPauser(ctx)
if found {
genesis.Pauser = &pauser
}
blacklister, found := k.GetBlacklister(ctx)
if found {
genesis.Blacklister = &blacklister
}
owner, found := k.GetOwner(ctx)
if found {
genesis.Owner = &owner
}
genesis.MinterControllerList = k.GetAllMinterControllers(ctx)
mintingDenom := k.GetMintingDenom(ctx)
genesis.MintingDenom = &mintingDenom
return genesis
}