-
Notifications
You must be signed in to change notification settings - Fork 170
/
genesis.go
46 lines (38 loc) · 1.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
package uibc
import (
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
func NewGenesisState(params Params, outflows sdk.DecCoins, outflowSum sdk.Dec) *GenesisState {
return &GenesisState{
Params: params,
Outflows: outflows,
TotalOutflowSum: outflowSum,
}
}
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
Outflows: nil,
TotalOutflowSum: sdk.NewDec(0),
}
}
// Validate performs basic valida`tion of the interchain accounts GenesisState
func (gs GenesisState) Validate() error {
if err := gs.Params.Validate(); err != nil {
return err
}
for _, o := range gs.Outflows {
if o.Amount.IsNil() {
return sdkerrors.ErrInvalidRequest.Wrap("ibc denom outflow must be defined")
}
if err := o.Validate(); err != nil {
return err
}
}
if gs.TotalOutflowSum.IsNegative() {
return fmt.Errorf("total outflow sum cannot be negative : %s ", gs.TotalOutflowSum.String())
}
return nil
}