/
genesis.go
65 lines (55 loc) · 1.88 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
package types
import (
"fmt"
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
)
// DefaultIndex is the default global index
const DefaultIndex uint64 = 1
// DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
PortId: PortID,
// PriceList: []Price{},
SymbolRequestList: []SymbolRequest{},
PriceFeederInfoList: []PriceFeederInfo{},
GasPriceList: []GasPrice{},
// 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 {
if err := host.PortIdentifierValidator(gs.PortId); err != nil {
return err
}
// Check for duplicated index in symbolRequest
symbolRequestIndexMap := make(map[string]struct{})
for _, elem := range gs.SymbolRequestList {
index := string(SymbolRequestKey(elem.Symbol))
if _, ok := symbolRequestIndexMap[index]; ok {
return fmt.Errorf("duplicated index for symbolRequest")
}
symbolRequestIndexMap[index] = struct{}{}
}
// Check for duplicated index in priceFeederInfo
priceFeederInfoIndexMap := make(map[string]struct{})
for _, elem := range gs.PriceFeederInfoList {
index := string(PriceFeederInfoKey(elem.Name))
if _, ok := priceFeederInfoIndexMap[index]; ok {
return fmt.Errorf("duplicated index for priceFeederInfo")
}
priceFeederInfoIndexMap[index] = struct{}{}
}
// Check for duplicated index in gasPrice
gasPriceIndexMap := make(map[string]struct{})
for _, elem := range gs.GasPriceList {
index := string(GasPriceKey(elem.PriceFeeder, elem.ChainId))
if _, ok := gasPriceIndexMap[index]; ok {
return fmt.Errorf("duplicated index for gasPrice")
}
gasPriceIndexMap[index] = struct{}{}
}
// this line is used by starport scaffolding # genesis/types/validate
return gs.Params.Validate()
}