mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
ff709d73e1
* add proto for allowed sdk denoms -> evm conversion * add validation for AllowedNativeCoinERC20Token * add validation for AllowedNativeCoinERC20Tokens * add AllowedNativeDenoms into params & genesis * add evmutil Params.Validate() test * fix eip712 ante test * update changelog * update internal testnet genesis.json * update state & param specs updates to the sections describing functionality will be updated once that functionality actually exists... :) * update field decimal -> decimals field now matches erc20 spec * add validation decimals will cast to uint8 * add v2 store migration for evmutil * create & register evmutil migrations * adds migrator to evmutil's keeper * sets up Migrate1To2 migration * registers migration in module * updates GetParams to properly handle historic block queries * add unit test for GetParams with historic store
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package keeper
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/x/evmutil/types"
|
|
)
|
|
|
|
// GetParams returns the total set of evm parameters.
|
|
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
|
|
k.paramSubspace.GetParamSetIfExists(ctx, ¶ms)
|
|
return params
|
|
}
|
|
|
|
// SetParams sets the evm parameters to the param space.
|
|
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
|
k.paramSubspace.SetParamSet(ctx, ¶ms)
|
|
}
|
|
|
|
// GetEnabledConversionPairFromERC20Address returns an ConversionPair from the internal contract address.
|
|
func (k Keeper) GetEnabledConversionPairFromERC20Address(
|
|
ctx sdk.Context,
|
|
address types.InternalEVMAddress,
|
|
) (types.ConversionPair, error) {
|
|
params := k.GetParams(ctx)
|
|
for _, pair := range params.EnabledConversionPairs {
|
|
if bytes.Equal(pair.KavaERC20Address, address.Bytes()) {
|
|
return pair, nil
|
|
}
|
|
}
|
|
|
|
return types.ConversionPair{}, errorsmod.Wrap(types.ErrConversionNotEnabled, address.String())
|
|
}
|
|
|
|
// GetEnabledConversionPairFromDenom returns an ConversionPair from the sdk.Coin denom.
|
|
func (k Keeper) GetEnabledConversionPairFromDenom(
|
|
ctx sdk.Context,
|
|
denom string,
|
|
) (types.ConversionPair, error) {
|
|
params := k.GetParams(ctx)
|
|
for _, pair := range params.EnabledConversionPairs {
|
|
if pair.Denom == denom {
|
|
return pair, nil
|
|
}
|
|
}
|
|
|
|
return types.ConversionPair{}, errorsmod.Wrap(types.ErrConversionNotEnabled, denom)
|
|
}
|