/
genesis.go
68 lines (57 loc) · 2.16 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
package distribution
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/omexapp/omexchain/x/distribution/types"
)
// InitGenesis sets distribution information for genesis
func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, data types.GenesisState) {
keeper.SetFeePool(ctx, data.FeePool)
keeper.SetParams(ctx, data.Params)
keeper.SetPreviousProposerConsAddr(ctx, data.PreviousProposer)
for _, dwi := range data.DelegatorWithdrawInfos {
keeper.SetDelegatorWithdrawAddr(ctx, dwi.DelegatorAddress, dwi.WithdrawAddress)
}
moduleHoldings := sdk.SysCoins{}
for _, acc := range data.ValidatorAccumulatedCommissions {
keeper.SetValidatorAccumulatedCommission(ctx, acc.ValidatorAddress, acc.Accumulated)
moduleHoldings = moduleHoldings.Add(acc.Accumulated...)
}
moduleHoldings = moduleHoldings.Add(data.FeePool.CommunityPool...)
// check if the module account exists
moduleAcc := keeper.GetDistributionAccount(ctx)
if moduleAcc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
if moduleAcc.GetCoins().IsZero() {
if err := moduleAcc.SetCoins(moduleHoldings); err != nil {
panic(err)
}
supplyKeeper.SetModuleAccount(ctx, moduleAcc)
}
}
// ExportGenesis returns a GenesisState for a given context and keeper.
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
feePool := keeper.GetFeePool(ctx)
params := keeper.GetParams(ctx)
dwi := make([]types.DelegatorWithdrawInfo, 0)
keeper.IterateDelegatorWithdrawAddrs(ctx, func(del sdk.AccAddress, addr sdk.AccAddress) (stop bool) {
dwi = append(dwi, types.DelegatorWithdrawInfo{
DelegatorAddress: del,
WithdrawAddress: addr,
})
return false
})
pp := keeper.GetPreviousProposerConsAddr(ctx)
acc := make([]types.ValidatorAccumulatedCommissionRecord, 0)
keeper.IterateValidatorAccumulatedCommissions(ctx,
func(addr sdk.ValAddress, commission types.ValidatorAccumulatedCommission) (stop bool) {
acc = append(acc, types.ValidatorAccumulatedCommissionRecord{
ValidatorAddress: addr,
Accumulated: commission,
})
return false
},
)
return types.NewGenesisState(params, feePool, dwi, pp, acc)
}