2023-01-23 19:01:28 +00:00
|
|
|
package v5
|
|
|
|
|
|
|
|
import (
|
2023-03-13 07:04:10 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/evm/types"
|
2023-01-23 19:01:28 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
2023-03-13 07:04:10 +00:00
|
|
|
v5types "github.com/cerc-io/laconicd/x/evm/migrations/v5/types"
|
2023-01-23 19:01:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MigrateStore migrates the x/evm module state from the consensus version 4 to
|
|
|
|
// version 5. Specifically, it takes the parameters that are currently stored
|
|
|
|
// in separate keys and stores them directly into the x/evm module state using
|
|
|
|
// a single params key.
|
|
|
|
func MigrateStore(
|
|
|
|
ctx sdk.Context,
|
|
|
|
storeKey storetypes.StoreKey,
|
|
|
|
cdc codec.BinaryCodec,
|
|
|
|
) error {
|
|
|
|
var (
|
|
|
|
extraEIPs v5types.V5ExtraEIPs
|
|
|
|
chainConfig types.ChainConfig
|
|
|
|
params types.Params
|
|
|
|
)
|
|
|
|
|
|
|
|
store := ctx.KVStore(storeKey)
|
|
|
|
|
|
|
|
denom := string(store.Get(types.ParamStoreKeyEVMDenom))
|
|
|
|
|
|
|
|
extraEIPsBz := store.Get(types.ParamStoreKeyExtraEIPs)
|
|
|
|
cdc.MustUnmarshal(extraEIPsBz, &extraEIPs)
|
|
|
|
|
2023-01-23 19:11:05 +00:00
|
|
|
// revert ExtraEIP change for Evmos testnet
|
|
|
|
if ctx.ChainID() == "evmos_9000-4" {
|
|
|
|
extraEIPs.EIPs = []int64{}
|
|
|
|
}
|
|
|
|
|
2023-01-23 19:01:28 +00:00
|
|
|
chainCfgBz := store.Get(types.ParamStoreKeyChainConfig)
|
|
|
|
cdc.MustUnmarshal(chainCfgBz, &chainConfig)
|
|
|
|
|
|
|
|
params.EvmDenom = denom
|
|
|
|
params.ExtraEIPs = extraEIPs.EIPs
|
|
|
|
params.ChainConfig = chainConfig
|
|
|
|
params.EnableCreate = store.Has(types.ParamStoreKeyEnableCreate)
|
|
|
|
params.EnableCall = store.Has(types.ParamStoreKeyEnableCall)
|
|
|
|
params.AllowUnprotectedTxs = store.Has(types.ParamStoreKeyAllowUnprotectedTxs)
|
|
|
|
|
|
|
|
store.Delete(types.ParamStoreKeyChainConfig)
|
|
|
|
store.Delete(types.ParamStoreKeyExtraEIPs)
|
|
|
|
store.Delete(types.ParamStoreKeyEVMDenom)
|
|
|
|
store.Delete(types.ParamStoreKeyEnableCreate)
|
|
|
|
store.Delete(types.ParamStoreKeyEnableCall)
|
|
|
|
store.Delete(types.ParamStoreKeyAllowUnprotectedTxs)
|
|
|
|
|
|
|
|
if err := params.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
bz := cdc.MustMarshal(¶ms)
|
|
|
|
|
|
|
|
store.Set(types.KeyPrefixParams, bz)
|
|
|
|
return nil
|
|
|
|
}
|