-
Notifications
You must be signed in to change notification settings - Fork 91
/
genesis.go
49 lines (40 loc) · 1.14 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
package types
import (
"fmt"
)
// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
BlockRateLimitConfig: BlockRateLimitConfiguration{},
ClobPairs: []ClobPair{},
EquityTierLimitConfig: EquityTierLimitConfiguration{},
LiquidationsConfig: LiquidationsConfig_Default,
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
// Check for duplicated id in clobPair
clobPairIdMap := make(map[uint32]struct{})
expectedId := uint32(0)
for _, clobPair := range gs.ClobPairs {
if _, ok := clobPairIdMap[clobPair.Id]; ok {
return fmt.Errorf("duplicated id for clobPair")
}
clobPairIdMap[clobPair.Id] = struct{}{}
if clobPair.Id != expectedId {
return fmt.Errorf("found gap in clobPair id")
}
expectedId = expectedId + 1
}
if err := gs.BlockRateLimitConfig.Validate(); err != nil {
return err
}
if err := gs.EquityTierLimitConfig.Validate(); err != nil {
return err
}
if err := gs.LiquidationsConfig.Validate(); err != nil {
return err
}
return nil
}