-
Notifications
You must be signed in to change notification settings - Fork 15
/
genesis.go
78 lines (65 loc) · 1.99 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
73
74
75
76
77
78
package account
import (
"fmt"
app "github.com/TruStory/truchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// GenesisState defines genesis data for the module
type GenesisState struct {
AppAccounts []AppAccount `json:"app_accounts"`
Params Params `json:"params"`
}
// NewGenesisState creates a new genesis state.
func NewGenesisState() GenesisState {
return GenesisState{
AppAccounts: nil,
Params: DefaultParams(),
}
}
// DefaultGenesisState returns a default genesis state
func DefaultGenesisState() GenesisState { return NewGenesisState() }
// InitGenesis initializes account state from genesis file
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) {
for _, acc := range data.AppAccounts {
keeper.setAppAccount(ctx, acc)
if acc.IsJailed {
keeper.setJailEndTimeAccount(ctx, acc.JailEndTime, acc.PrimaryAddress())
}
}
keeper.SetParams(ctx, data.Params)
err := initUserGrowthPool(ctx, keeper)
if err != nil {
panic(err)
}
}
func initUserGrowthPool(ctx sdk.Context, keeper Keeper) sdk.Error {
userGrowthAcc := keeper.supplyKeeper.GetModuleAccount(ctx, UserGrowthPoolName)
if userGrowthAcc.GetCoins().Empty() {
amount := app.NewShanevCoin(5_000_000)
err := keeper.supplyKeeper.MintCoins(ctx, UserGrowthPoolName, sdk.NewCoins(amount))
if err != nil {
return err
}
}
return nil
}
// ExportGenesis exports the genesis state
func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState {
return GenesisState{
AppAccounts: keeper.AppAccounts(ctx),
Params: keeper.GetParams(ctx),
}
}
// ValidateGenesis validates the genesis state data
func ValidateGenesis(data GenesisState) error {
if len(data.Params.Registrar) == 0 {
return fmt.Errorf("Param: Registrar, must be a valid address")
}
if data.Params.MaxSlashCount < 1 {
return fmt.Errorf("Param: MaxSlashCount, must have a positive value")
}
if data.Params.JailDuration.Seconds() < 1 {
return fmt.Errorf("Param: JailTime, must have a positive value")
}
return nil
}