-
Notifications
You must be signed in to change notification settings - Fork 833
/
genesis.go
62 lines (50 loc) · 1.67 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
package claims
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tharsis/evmos/v2/x/claims/keeper"
"github.com/tharsis/evmos/v2/x/claims/types"
)
// InitGenesis initializes the claim module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) {
totalEscrowed := sdk.ZeroInt()
sumClaims := sdk.ZeroInt()
// ensure claim module account is set on genesis
if acc := k.GetModuleAccountAccount(ctx); acc == nil {
panic("the claim module account has not been set")
}
// set the start time to the current block time by default
if data.Params.AirdropStartTime.IsZero() {
data.Params.AirdropStartTime = ctx.BlockTime()
}
k.SetParams(ctx, data.Params)
escrowedCoins := k.GetModuleAccountBalances(ctx)
if escrowedCoins != nil {
totalEscrowed = escrowedCoins.AmountOfNoDenomValidation(data.Params.ClaimsDenom)
}
for _, claimsRecord := range data.ClaimsRecords {
addr, _ := sdk.AccAddressFromBech32(claimsRecord.Address)
cr := types.ClaimsRecord{
InitialClaimableAmount: claimsRecord.InitialClaimableAmount,
ActionsCompleted: claimsRecord.ActionsCompleted,
}
k.SetClaimsRecord(ctx, addr, cr)
sumClaims = sumClaims.Add(cr.InitialClaimableAmount)
}
if !sumClaims.Equal(totalEscrowed) {
panic(
fmt.Errorf(
"sum of claimable amount ≠ escrowed module account amount (%s ≠ %s)",
sumClaims, totalEscrowed,
),
)
}
}
// ExportGenesis returns the claim module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return &types.GenesisState{
Params: k.GetParams(ctx),
ClaimsRecords: k.GetClaimsRecords(ctx),
}
}