-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.go
62 lines (54 loc) · 1.72 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
58
59
60
61
62
package keeper
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/incubus-network/nemo/x/issuance/types"
)
// GetParams returns the params from the store
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
var p types.Params
k.paramSubspace.GetParamSet(ctx, &p)
return p
}
// SetParams sets params on the store
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSubspace.SetParamSet(ctx, ¶ms)
}
// GetAsset returns an asset from the params and a boolean for if it was found
func (k Keeper) GetAsset(ctx sdk.Context, denom string) (types.Asset, bool) {
params := k.GetParams(ctx)
for _, asset := range params.Assets {
if asset.Denom == denom {
return asset, true
}
}
return types.Asset{}, false
}
// SetAsset sets an asset in the params
func (k Keeper) SetAsset(ctx sdk.Context, asset types.Asset) {
params := k.GetParams(ctx)
for i := range params.Assets {
if params.Assets[i].Denom == asset.Denom {
params.Assets[i] = asset
}
}
k.SetParams(ctx, params)
}
// GetRateLimit returns the rete-limit parameters for the input denom
func (k Keeper) GetRateLimit(ctx sdk.Context, denom string) (types.RateLimit, error) {
asset, found := k.GetAsset(ctx, denom)
if !found {
errorsmod.Wrap(types.ErrAssetNotFound, denom)
}
return asset.RateLimit, nil
}
// SynchronizeBlockList resets the block list to empty for any asset that is not blockable - could happen if this value is changed via governance
func (k Keeper) SynchronizeBlockList(ctx sdk.Context) {
params := k.GetParams(ctx)
for _, asset := range params.Assets {
if !asset.Blockable && len(asset.BlockedAddresses) > 0 {
asset.BlockedAddresses = []string{}
k.SetAsset(ctx, asset)
}
}
}