-
Notifications
You must be signed in to change notification settings - Fork 55
/
genesis.go
71 lines (59 loc) 路 1.52 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
package types
import (
"errors"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// DefaultGenesis returns the default genesis state.
func DefaultGenesis() *GenesisState {
return &GenesisState{
Airdrops: []Airdrop{},
ClaimRecords: []ClaimRecord{},
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
for _, a := range gs.Airdrops {
if err := a.Validate(); err != nil {
return err
}
}
for _, r := range gs.ClaimRecords {
if err := r.Validate(); err != nil {
return err
}
}
return nil
}
// Validate validates an airdrop object.
func (a Airdrop) Validate() error {
if _, err := sdk.AccAddressFromBech32(a.SourceAddress); err != nil {
return err
}
if a.StartTime.After(a.EndTime) {
return errors.New("end time must be greater than start time")
}
for _, c := range a.Conditions {
switch c {
case ConditionTypeDeposit, ConditionTypeSwap,
ConditionTypeLiquidStake, ConditionTypeVote:
default:
return fmt.Errorf("unknown condition type %T", c)
}
}
return nil
}
// Validate validates claim record object.
func (r ClaimRecord) Validate() error {
if _, err := sdk.AccAddressFromBech32(r.Recipient); err != nil {
return err
}
if !r.InitialClaimableCoins.IsAllPositive() {
return fmt.Errorf("initial claimable amount must be positive: %s", r.InitialClaimableCoins.String())
}
if err := r.ClaimableCoins.Validate(); err != nil {
return fmt.Errorf("invalid claimable coins: %w", err)
}
return nil
}