-
Notifications
You must be signed in to change notification settings - Fork 28
/
genesis.go
60 lines (51 loc) · 1.64 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
package types
import (
"fmt"
)
// DefaultIndex is the default global index
const DefaultIndex uint64 = 1
// DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
CampaignList: []Campaign{},
Params: DefaultParams(),
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
// Check for duplicated index in campaign
campaignIndexMap := make(map[string]struct{})
for _, elem := range gs.CampaignList {
index := string(GetCampaignKey(elem.UID))
if _, ok := campaignIndexMap[index]; ok {
return fmt.Errorf("duplicated index for campaign")
}
campaignIndexMap[index] = struct{}{}
}
rewardIndexMap := make(map[string]struct{})
for _, elem := range gs.RewardList {
index := string(GetRewardKey(elem.UID))
if _, ok := rewardIndexMap[index]; ok {
return fmt.Errorf("duplicated index for reward")
}
rewardIndexMap[index] = struct{}{}
}
rewardByRecCatIndexMap := make(map[string]struct{})
for _, elem := range gs.RewardByCategoryList {
index := string(GetRewardKey(elem.UID))
if _, ok := rewardByRecCatIndexMap[index]; ok {
return fmt.Errorf("duplicated index for reward by receiver and category")
}
rewardByRecCatIndexMap[index] = struct{}{}
}
rewardByCampaignIndexMap := make(map[string]struct{})
for _, elem := range gs.RewardByCampaignList {
index := string(GetRewardKey(elem.UID))
if _, ok := rewardByCampaignIndexMap[index]; ok {
return fmt.Errorf("duplicated index for reward by campaign")
}
rewardByCampaignIndexMap[index] = struct{}{}
}
return gs.Params.Validate()
}