-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
65 lines (52 loc) · 1.83 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
package dvm
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furya-network/furya/x/dvm/keeper"
"github.com/furya-network/furya/x/dvm/types"
)
// InitGenesis initializes the module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// Set the key vault
k.SetKeyVault(ctx, genState.KeyVault)
// set active pubkeys change proposals
for i := range genState.ActivePubkeysChangeProposals {
proposal := genState.ActivePubkeysChangeProposals[i]
k.SetActivePubkeysChangeProposal(ctx, proposal)
}
// set finished pubkeys change proposals
for i := range genState.FinishedPubkeysChangeProposals {
proposal := genState.FinishedPubkeysChangeProposals[i]
k.SetFinishedPubkeysChangeProposal(ctx, proposal)
}
// set proposal statistics
k.SetProposalStats(ctx, genState.ProposalStats)
// set parameters
k.SetParams(ctx, genState.Params)
}
// ExportGenesis returns the module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()
// load the key vault
keys, found := k.GetKeyVault(ctx)
if found {
genesis.KeyVault = keys
}
// load active pubkeys change proposals
activeProposals, err := k.GetAllActivePubkeysChangeProposals(ctx)
if err != nil {
panic(err)
}
genesis.ActivePubkeysChangeProposals = append(genesis.ActivePubkeysChangeProposals, activeProposals...)
// load finished pubkeys change proposals
finishedProposals, err := k.GetAllFinishedPubkeysChangeProposals(ctx)
if err != nil {
panic(err)
}
genesis.FinishedPubkeysChangeProposals = append(genesis.FinishedPubkeysChangeProposals, finishedProposals...)
// load proposal statistics
genesis.ProposalStats = k.GetProposalStats(ctx)
// load the default Params
genesis.Params = k.GetParams(ctx)
return genesis
}