-
Notifications
You must be signed in to change notification settings - Fork 4
/
params.go
executable file
·56 lines (46 loc) · 1.26 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
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
const (
DefaultFromExchange = "minigeo"
DefaultToExchange = "loki"
)
var KeyExchangeRates = []byte("ExchangeRates")
// ParamKeyTable param table for coinswap module.
func ParamKeyTable() paramstypes.KeyTable {
return paramstypes.NewKeyTable().RegisterParamSet(&Params{})
}
func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {
return paramstypes.ParamSetPairs{
paramstypes.NewParamSetPair(KeyExchangeRates, &p.ExchangeRates, validateExchangeRates),
}
}
func DefaultParams() Params {
return Params{
ExchangeRates: []Exchange{
{
From: DefaultFromExchange,
To: DefaultToExchange,
RateMultiplier: sdk.NewDec(1),
},
},
}
}
func validateExchangeRates(i interface{}) error {
exchanges, ok := i.([]Exchange)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
for _, ex := range exchanges {
if !ex.RateMultiplier.IsPositive() && !ex.RateMultiplier.IsZero() {
return fmt.Errorf("rate multiplier %s must be positive or zero", ex)
}
if ex.From == "" || ex.To == "" {
return fmt.Errorf("one or both denoms are empty. From: %s, To: %s", ex.From, ex.To)
}
}
return nil
}