/
genesis.go
53 lines (45 loc) · 1.23 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
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
DepositList: []Deposit{},
WithdrawalList: []Withdrawal{},
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
for _, w := range gs.WithdrawalList {
_, err := sdk.AccAddressFromBech32(w.Address)
if err != nil {
return fmt.Errorf("invalid withdrawal address %s", w.Address)
}
found := false
for _, d := range gs.DepositList {
_, err := sdk.AccAddressFromBech32(w.Address)
if err != nil {
return fmt.Errorf("invalid deposit address %s", d.Creator)
}
if w.Address == d.Creator &&
w.MarketUID == d.MarketUID &&
w.ParticipationIndex == d.ParticipationIndex {
found = true
}
}
if !found {
return fmt.Errorf("the deposit for the depositor address %s, "+
"market uid %s and participation index %d not found for the withdrawal",
w.Address,
w.MarketUID,
w.ParticipationIndex)
}
}
// TODO: extend validations for market existence
// and etc.
return gs.Params.Validate()
}