-
Notifications
You must be signed in to change notification settings - Fork 17
/
genesis.go
77 lines (67 loc) · 2.02 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
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{
WhoIsList: []Whois{},
NamesList: []Names{},
BidsList: []Bids{},
ForSaleList: []Forsale{},
InitList: []Init{},
Params: DefaultParams(),
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
// Check for duplicated index in whois
whoisIndexMap := make(map[string]struct{})
for _, elem := range gs.WhoIsList {
index := string(WhoisKey(elem.Index))
if _, ok := whoisIndexMap[index]; ok {
return fmt.Errorf("duplicated index for whois")
}
whoisIndexMap[index] = struct{}{}
}
// Check for duplicated index in names
namesIndexMap := make(map[string]struct{})
for _, elem := range gs.NamesList {
index := string(NamesKey(elem.Name, elem.Tld))
if _, ok := namesIndexMap[index]; ok {
return fmt.Errorf("duplicated index for names")
}
namesIndexMap[index] = struct{}{}
}
// Check for duplicated index in bids
bidsIndexMap := make(map[string]struct{})
for _, elem := range gs.BidsList {
index := string(BidsKey(elem.Index))
if _, ok := bidsIndexMap[index]; ok {
return fmt.Errorf("duplicated index for bids")
}
bidsIndexMap[index] = struct{}{}
}
// Check for duplicated index in forsale
forsaleIndexMap := make(map[string]struct{})
for _, elem := range gs.ForSaleList {
index := string(ForsaleKey(elem.Name))
if _, ok := forsaleIndexMap[index]; ok {
return fmt.Errorf("duplicated index for forsale")
}
forsaleIndexMap[index] = struct{}{}
}
// Check for duplicated index in init
initIndexMap := make(map[string]struct{})
for _, elem := range gs.InitList {
index := string(InitKey(elem.Address))
if _, ok := initIndexMap[index]; ok {
return fmt.Errorf("duplicated index for init")
}
initIndexMap[index] = struct{}{}
}
return gs.Params.Validate()
}