-
Notifications
You must be signed in to change notification settings - Fork 49
/
genesis.go
71 lines (60 loc) · 2.34 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
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// DefaultIndex is the default global index
const DefaultIndex uint64 = 1
// DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
StreamRecordList: []StreamRecord{},
PaymentAccountCountList: []PaymentAccountCount{},
PaymentAccountList: []PaymentAccount{},
AutoSettleRecordList: []AutoSettleRecord{},
// this line is used by starport scaffolding # genesis/types/default
Params: DefaultParams(),
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
// Check for duplicated index in streamRecord
streamRecordIndexMap := make(map[string]struct{})
for _, elem := range gs.StreamRecordList {
index := string(StreamRecordKey(sdk.MustAccAddressFromHex(elem.Account)))
if _, ok := streamRecordIndexMap[index]; ok {
return fmt.Errorf("duplicated index for streamRecord")
}
streamRecordIndexMap[index] = struct{}{}
}
// Check for duplicated index in paymentAccountCount
paymentAccountCountIndexMap := make(map[string]struct{})
for _, elem := range gs.PaymentAccountCountList {
index := string(PaymentAccountCountKey(sdk.MustAccAddressFromHex(elem.Owner)))
if _, ok := paymentAccountCountIndexMap[index]; ok {
return fmt.Errorf("duplicated index for paymentAccountCount")
}
paymentAccountCountIndexMap[index] = struct{}{}
}
// Check for duplicated index in paymentAccount
paymentAccountIndexMap := make(map[string]struct{})
for _, elem := range gs.PaymentAccountList {
index := string(PaymentAccountKey(sdk.MustAccAddressFromHex(elem.Addr)))
if _, ok := paymentAccountIndexMap[index]; ok {
return fmt.Errorf("duplicated index for paymentAccount")
}
paymentAccountIndexMap[index] = struct{}{}
}
// Check for duplicated index in autoSettleRecord
autoSettleRecordIndexMap := make(map[string]struct{})
for _, elem := range gs.AutoSettleRecordList {
index := string(AutoSettleRecordKey(elem.Timestamp, sdk.MustAccAddressFromHex(elem.Addr)))
if _, ok := autoSettleRecordIndexMap[index]; ok {
return fmt.Errorf("duplicated index for autoSettleRecord")
}
autoSettleRecordIndexMap[index] = struct{}{}
}
// this line is used by starport scaffolding # genesis/types/validate
return gs.Params.Validate()
}