-
Notifications
You must be signed in to change notification settings - Fork 16
/
genesis.go
102 lines (89 loc) · 3.01 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package types
import (
"fmt"
)
// DefaultIndex is the default capability global index
const DefaultIndex uint64 = 1
// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
ContractsList: []Contracts{},
ActiveDealsList: []ActiveDeals{},
ProvidersList: []Providers{},
PayBlocksList: []PayBlocks{},
ClientUsageList: []ClientUsage{},
StraysList: []Strays{},
FidCidList: []FidCid{},
// 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 contracts
contractsIndexMap := make(map[string]struct{})
for _, elem := range gs.ContractsList {
index := string(ContractsKey(elem.Cid))
if _, ok := contractsIndexMap[index]; ok {
return fmt.Errorf("duplicated index for contracts")
}
contractsIndexMap[index] = struct{}{}
}
// Check for duplicated index in activeDeals
activeDealsIndexMap := make(map[string]struct{})
for _, elem := range gs.ActiveDealsList {
index := string(ActiveDealsKey(elem.Cid))
if _, ok := activeDealsIndexMap[index]; ok {
return fmt.Errorf("duplicated index for activeDeals")
}
activeDealsIndexMap[index] = struct{}{}
}
// Check for duplicated index in providers
providersIndexMap := make(map[string]struct{})
for _, elem := range gs.ProvidersList {
index := string(ProvidersKey(elem.Address))
if _, ok := providersIndexMap[index]; ok {
return fmt.Errorf("duplicated index for providers")
}
providersIndexMap[index] = struct{}{}
}
// Check for duplicated index in payBlocks
payBlocksIndexMap := make(map[string]struct{})
for _, elem := range gs.PayBlocksList {
index := string(PayBlocksKey(elem.Blockid))
if _, ok := payBlocksIndexMap[index]; ok {
return fmt.Errorf("duplicated index for payBlocks")
}
payBlocksIndexMap[index] = struct{}{}
}
// Check for duplicated index in clientUsage
clientUsageIndexMap := make(map[string]struct{})
for _, elem := range gs.ClientUsageList {
index := string(ClientUsageKey(elem.Address))
if _, ok := clientUsageIndexMap[index]; ok {
return fmt.Errorf("duplicated index for clientUsage")
}
clientUsageIndexMap[index] = struct{}{}
}
// Check for duplicated index in strays
straysIndexMap := make(map[string]struct{})
for _, elem := range gs.StraysList {
index := string(StraysKey(elem.Cid))
if _, ok := straysIndexMap[index]; ok {
return fmt.Errorf("duplicated index for strays")
}
straysIndexMap[index] = struct{}{}
}
// Check for duplicated index in fidCid
fidCidIndexMap := make(map[string]struct{})
for _, elem := range gs.FidCidList {
index := string(FidCidKey(elem.Fid))
if _, ok := fidCidIndexMap[index]; ok {
return fmt.Errorf("duplicated index for fidCid")
}
fidCidIndexMap[index] = struct{}{}
}
// this line is used by starport scaffolding # genesis/types/validate
return gs.Params.Validate()
}