/
genesis.go
64 lines (54 loc) · 1.85 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
package keeper
import (
"context"
cosmosMath "cosmossdk.io/math"
state "github.com/allora-network/allora-chain/x/emissions"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// InitGenesis initializes the module state from a genesis state.
func (k *Keeper) InitGenesis(ctx context.Context, data *state.GenesisState) error {
// ensure the module account exists
stakingModuleAccount := k.authKeeper.GetModuleAccount(ctx, state.AlloraStakingAccountName)
k.authKeeper.SetModuleAccount(ctx, stakingModuleAccount)
requestsModuleAccount := k.authKeeper.GetModuleAccount(ctx, state.AlloraRequestsAccountName)
k.authKeeper.SetModuleAccount(ctx, requestsModuleAccount)
alloraRewardsModuleAccount := k.authKeeper.GetModuleAccount(ctx, state.AlloraRewardsAccountName)
k.authKeeper.SetModuleAccount(ctx, alloraRewardsModuleAccount)
if err := k.SetLastRewardsUpdate(ctx, 0); err != nil {
return err
}
if err := k.SetTotalStake(ctx, cosmosMath.NewUint(0)); err != nil {
return err
}
// reserve topic ID 0 for future use
if _, err := k.IncrementTopicId(ctx); err != nil {
return err
}
// add core team to the whitelists
if err := k.addCoreTeamToWhitelists(ctx, data.CoreTeamAddresses); err != nil {
return err
}
return nil
}
// ExportGenesis exports the module state to a genesis state.
func (k *Keeper) ExportGenesis(ctx context.Context) (*state.GenesisState, error) {
params, err := k.GetParams(ctx)
if err != nil {
return nil, err
}
return &state.GenesisState{
Params: params,
}, nil
}
func (k *Keeper) addCoreTeamToWhitelists(ctx context.Context, coreTeamAddresses []string) error {
for _, addr := range coreTeamAddresses {
accAddress, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return err
}
k.AddWhitelistAdmin(ctx, accAddress)
k.AddToTopicCreationWhitelist(ctx, accAddress)
k.AddToWeightSettingWhitelist(ctx, accAddress)
}
return nil
}