-
Notifications
You must be signed in to change notification settings - Fork 31
/
genesis.go
74 lines (63 loc) · 1.72 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
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewGenesisState is the constructor function for GenesisState
func NewGenesisState(params Params, denom string) *GenesisState {
return &GenesisState{
Params: params,
StandardDenom: denom,
}
}
// DefaultGenesisState creates a default GenesisState object
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
StandardDenom: sdk.DefaultBondDenom,
Sequence: 1,
}
}
// ValidateGenesis validates the given genesis state
func ValidateGenesis(data GenesisState) error {
if err := sdk.ValidateDenom(data.StandardDenom); err != nil {
return err
}
var poolIds = make(map[string]bool, len(data.Pool))
var lptDenoms = make(map[string]bool, len(data.Pool))
var maxSequence = uint64(0)
for _, pool := range data.Pool {
if poolIds[pool.Id] {
return fmt.Errorf("duplicate pool: %s", pool.Id)
}
if lptDenoms[pool.LptDenom] {
return fmt.Errorf("duplicate lptDenom: %s", pool.LptDenom)
}
poolIds[pool.Id] = true
lptDenoms[pool.LptDenom] = true
//validate the liquidity pool token denom
seq, err := ParseLptDenom(pool.LptDenom)
if err != nil {
return err
}
if seq > maxSequence {
maxSequence = seq
}
//validate the token denom
if err := sdk.ValidateDenom(pool.CounterpartyDenom); err != nil {
return err
}
//validate the token denom
if err := sdk.ValidateDenom(pool.StandardDenom); err != nil {
return err
}
//validate the address
if _, err := sdk.AccAddressFromBech32(pool.EscrowAddress); err != nil {
return err
}
}
if maxSequence+1 != data.Sequence {
return fmt.Errorf("invalid sequence: %d", data.Sequence)
}
return data.Params.Validate()
}