2023-01-04 14:28:45 +00:00
|
|
|
package v4
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/evmos/ethermint/x/evm/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MigrateStore migrates the x/evm module state from the consensus version 3 to
|
|
|
|
// version 4. Specifically, it takes the parameters that are currently stored
|
|
|
|
// and managed by the Cosmos SDK params module and stores them directly into the x/evm module state.
|
|
|
|
func MigrateStore(
|
|
|
|
ctx sdk.Context,
|
|
|
|
storeKey storetypes.StoreKey,
|
|
|
|
legacySubspace types.Subspace,
|
|
|
|
cdc codec.BinaryCodec,
|
|
|
|
) error {
|
|
|
|
var (
|
|
|
|
store = ctx.KVStore(storeKey)
|
2023-01-12 08:52:55 +00:00
|
|
|
params types.Params
|
2023-01-04 14:28:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
legacySubspace.GetParamSetIfExists(ctx, ¶ms)
|
|
|
|
|
|
|
|
if err := params.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
chainCfgBz := cdc.MustMarshal(¶ms.ChainConfig)
|
2023-01-12 08:52:55 +00:00
|
|
|
extraEIPsBz := cdc.MustMarshal(&types.ExtraEIPs{EIPs: types.AvailableExtraEIPs})
|
2023-01-04 14:28:45 +00:00
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
store.Set(types.ParamStoreKeyEVMDenom, []byte(params.EvmDenom))
|
|
|
|
store.Set(types.ParamStoreKeyExtraEIPs, extraEIPsBz)
|
|
|
|
store.Set(types.ParamStoreKeyChainConfig, chainCfgBz)
|
2023-01-04 14:28:45 +00:00
|
|
|
|
|
|
|
if params.AllowUnprotectedTxs {
|
2023-01-12 08:52:55 +00:00
|
|
|
store.Set(types.ParamStoreKeyAllowUnprotectedTxs, []byte{0x01})
|
2023-01-04 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if params.EnableCall {
|
2023-01-12 08:52:55 +00:00
|
|
|
store.Set(types.ParamStoreKeyEnableCall, []byte{0x01})
|
2023-01-04 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if params.EnableCreate {
|
2023-01-12 08:52:55 +00:00
|
|
|
store.Set(types.ParamStoreKeyEnableCreate, []byte{0x01})
|
2023-01-04 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|