-
Notifications
You must be signed in to change notification settings - Fork 61
/
genesis.go
72 lines (58 loc) · 1.79 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
package airdrop
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/quicksilver-zone/quicksilver/x/airdrop/keeper"
"github.com/quicksilver-zone/quicksilver/x/airdrop/types"
)
// InitGenesis initializes the airdrop module's state from a provided genesis
// state.
// This function will panic on failure.
func InitGenesis(ctx sdk.Context, k *keeper.Keeper, genState types.GenesisState) {
k.SetParams(ctx, genState.Params)
sum := uint64(0)
zsum := make(map[string]uint64)
for _, cr := range genState.ClaimRecords {
zsum[cr.ChainId] += cr.MaxAllocation
sum += cr.MaxAllocation
if err := k.SetClaimRecord(ctx, *cr); err != nil {
panic(err)
}
}
moduleBalance := k.GetModuleAccountBalance(ctx)
if sum > moduleBalance.Amount.Uint64() {
panic(fmt.Sprintf("insufficient airdrop module account balance for airdrop module account %s, expected %d", k.GetModuleAccountAddress(ctx), sum))
}
for _, zd := range genState.ZoneDrops {
zs, ok := zsum[zd.ChainId]
if !ok {
panic("zone sum not found")
}
if zs != zd.Allocation {
panic(fmt.Sprintf("zone sum does not match zone allocation; got %d, allocated %d", zs, zd.Allocation))
}
zonedropAddress := k.GetZoneDropAccountAddress(zd.ChainId)
err := k.SendCoinsFromModuleToAccount(
ctx,
types.ModuleName,
zonedropAddress,
sdk.NewCoins(
sdk.NewCoin(
k.BondDenom(ctx),
sdk.NewIntFromUint64(zd.Allocation),
),
),
)
if err != nil {
panic(err)
}
k.SetZoneDrop(ctx, *zd)
}
}
// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *types.GenesisState {
params := k.GetParams(ctx)
zoneDrops := k.AllZoneDrops(ctx)
claimRecords := k.AllClaimRecords(ctx)
return types.NewGenesisState(params, zoneDrops, claimRecords)
}