-
Notifications
You must be signed in to change notification settings - Fork 198
/
genesis.go
64 lines (57 loc) · 2.08 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
package types
import (
"fmt"
host "github.com/cosmos/ibc-go/v5/modules/core/24-host"
)
// DefaultIndex is the default capability global index
const DefaultIndex uint64 = 1
// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
PortId: PortID,
UserRedemptionRecordList: []UserRedemptionRecord{},
UserRedemptionRecordCount: 0,
EpochUnbondingRecordList: []EpochUnbondingRecord{},
DepositRecordList: []DepositRecord{},
DepositRecordCount: 0,
// this line is used by starport scaffolding # genesis/types/default
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
if err := host.PortIdentifierValidator(gs.PortId); err != nil {
return err
}
// Check for duplicated ID in userRedemptionRecord
userRedemptionRecordIdMap := make(map[string]bool)
for _, elem := range gs.UserRedemptionRecordList {
if _, ok := userRedemptionRecordIdMap[elem.Id]; ok {
return fmt.Errorf("duplicated id for userRedemptionRecord")
}
userRedemptionRecordIdMap[elem.Id] = true
}
// Check for duplicated ID in epochUnbondingRecord
epochUnbondingRecordIdMap := make(map[uint64]bool)
for _, elem := range gs.EpochUnbondingRecordList {
if _, ok := epochUnbondingRecordIdMap[elem.EpochNumber]; ok {
return fmt.Errorf("duplicated id for epochUnbondingRecord")
}
epochUnbondingRecordIdMap[elem.EpochNumber] = true
}
// Check for duplicated ID in depositRecord
depositRecordIdMap := make(map[uint64]bool)
depositRecordCount := gs.GetDepositRecordCount()
for _, elem := range gs.DepositRecordList {
if _, ok := depositRecordIdMap[elem.Id]; ok {
return fmt.Errorf("duplicated id for depositRecord")
}
if elem.Id >= depositRecordCount {
return fmt.Errorf("depositRecord id should be lower or equal than the last id")
}
depositRecordIdMap[elem.Id] = true
}
// this line is used by starport scaffolding # genesis/types/validate
return gs.Params.Validate()
}