github.com/cosmos/cosmos-sdk@v0.50.10/x/bank/migrations/v4/store.go (about)

     1  package v4
     2  
     3  import (
     4  	"cosmossdk.io/core/store"
     5  
     6  	"github.com/cosmos/cosmos-sdk/codec"
     7  	sdk "github.com/cosmos/cosmos-sdk/types"
     8  	"github.com/cosmos/cosmos-sdk/x/bank/exported"
     9  	"github.com/cosmos/cosmos-sdk/x/bank/types"
    10  )
    11  
    12  const ModuleName = "bank"
    13  
    14  var ParamsKey = []byte{0x05}
    15  
    16  // MigrateStore migrates the x/bank module state from the consensus version 3 to
    17  // version 4. Specifically, it takes the parameters that are currently stored
    18  // and managed by the x/params module and stores them directly into the x/bank
    19  // module state.
    20  func MigrateStore(ctx sdk.Context, storeService store.KVStoreService, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error {
    21  	var currParams types.Params
    22  	legacySubspace.GetParamSet(ctx, &currParams)
    23  
    24  	// SendEnabled is migrated to the x/bank module store, so delete from the params
    25  	currParams = types.NewParams(currParams.DefaultSendEnabled)
    26  
    27  	if err := currParams.Validate(); err != nil {
    28  		return err
    29  	}
    30  
    31  	bz, err := cdc.Marshal(&currParams)
    32  	if err != nil {
    33  		return err
    34  	}
    35  
    36  	store := storeService.OpenKVStore(ctx)
    37  	return store.Set(ParamsKey, bz)
    38  }