/
genesis.go
41 lines (32 loc) · 1.23 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
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/bnb-chain/greenfield/x/sp/types"
)
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
depositAmount := sdk.ZeroInt()
for _, sp := range genState.StorageProviders {
k.SetStorageProvider(ctx, &sp)
switch sp.GetStatus() {
case types.STATUS_IN_SERVICE,
types.STATUS_IN_JAILED:
depositAmount = depositAmount.Add(sp.GetTotalDeposit())
default:
panic("invalid initialization storage provider status in genesis block")
}
}
depositCoins := sdk.NewCoins(sdk.NewCoin(genState.Params.DepositDenom, depositAmount))
spDepositPool := k.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
if spDepositPool == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
// if account has zero balance it probably means it's not set, so we set it
depositBalance := k.bankKeeper.GetAllBalances(ctx, spDepositPool.GetAddress())
if depositBalance.IsZero() {
k.accountKeeper.SetModuleAccount(ctx, spDepositPool)
}
if !depositBalance.IsEqual(depositCoins) {
panic(fmt.Sprintf("sp deposit pool balance is different from sp deposit coins: %s <-> %s", depositBalance.String(), depositCoins.String()))
}
}