/
params.go
57 lines (45 loc) · 1.16 KB
/
params.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
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/settlus/chain/x/oracle/types"
)
// GetParams get all parameters as types.Params
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramstore.GetParamSet(ctx, ¶ms)
if params.VotePeriod == 0 {
return types.DefaultParams()
}
return params
}
// SetParams set the params
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
if err := params.Validate(); err != nil {
return err
}
k.paramstore.SetParamSet(ctx, ¶ms)
return nil
}
// GetChains returns the list of whitelist chains in params
func (k Keeper) GetChains(ctx sdk.Context) []*types.Chain {
params := k.GetParams(ctx)
wl := params.GetWhitelist()
if wl == nil {
return nil
}
return wl
}
// GetChain returns the chain with the given chain id
func (k Keeper) GetChain(ctx sdk.Context, chainId string) (*types.Chain, error) {
params := k.GetParams(ctx)
wl := params.GetWhitelist()
if len(wl) == 0 {
return nil, fmt.Errorf("whitelist is not set")
}
for _, chain := range wl {
if chain.ChainId == chainId {
return chain, nil
}
}
return nil, types.ErrChainNotFound
}