0g-chain/x/issuance/keeper/params.go
Ruaridh ffef832d45
Upgrade to sdk v0.44.5 and add IBC (#1106)
- Upgrade cosmos-sdk to v0.44.5 from v0.39.2
- Add Legacy Tx Endpoint for backwards compatibility
- Add IBC v1.2.3 Support

Co-authored-by: DracoLi <draco@dracoli.com>
Co-authored-by: drklee3 <derrick@dlee.dev>
Co-authored-by: denalimarsh <denalimarsh@gmail.com>
Co-authored-by: Draco Li <draco@kava.io>
Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
Co-authored-by: Denali Marsh <denali@kava.io>
2022-01-07 17:39:27 -07:00

63 lines
1.7 KiB
Go

package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/kava-labs/kava/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, &params)
}
// 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 {
sdkerrors.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)
}
}
}