-
Notifications
You must be signed in to change notification settings - Fork 198
/
genesis.go
60 lines (50 loc) · 1.84 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 "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
commontypes "github.com/lavanet/lava/common/types"
"github.com/lavanet/lava/x/timerstore/types"
)
// this line is used by starport scaffolding # genesis/types/import
// DefaultIndex is the default capability global index
const DefaultIndex uint64 = 1
// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
// this line is used by starport scaffolding # genesis/types/default
Params: DefaultParams(),
RefillRewardsTS: *types.DefaultGenesis(),
BasePays: []BasePayGenesis{},
IprpcSubscriptions: []string{},
MinIprpcCost: sdk.NewCoin(commontypes.TokenDenom, sdk.ZeroInt()),
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
// this line is used by starport scaffolding # genesis/types/validate
timeEntries := gs.RefillRewardsTS.GetTimeEntries()
if len(timeEntries) > 1 {
return fmt.Errorf(`there should be up to one timer in RefillRewardsTS
at all times. amount of timers found: %v`, len(timeEntries))
}
unique := map[string]struct{}{}
for _, sub := range gs.IprpcSubscriptions {
_, err := sdk.AccAddressFromBech32(sub)
if err != nil {
return fmt.Errorf("invalid subscription address. err: %s", err.Error())
}
_, ok := unique[sub]
if ok {
return fmt.Errorf("iprpc subscription address is duplicated. address: %s", sub)
}
unique[sub] = struct{}{}
}
if gs.MinIprpcCost.Denom != commontypes.TokenDenom {
return fmt.Errorf("invalid min iprpc cost denom. MinIprpcCost: %s", gs.MinIprpcCost.String())
}
if gs.MinIprpcCost.Amount.IsNegative() {
return fmt.Errorf("negative min iprpc cost. MinIprpcCost: %s", gs.MinIprpcCost.String())
}
return gs.Params.Validate()
}