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

     1  package v3
     2  
     3  import (
     4  	storetypes "cosmossdk.io/store/types"
     5  
     6  	"github.com/cosmos/cosmos-sdk/codec"
     7  	sdk "github.com/cosmos/cosmos-sdk/types"
     8  	paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
     9  	"github.com/cosmos/cosmos-sdk/x/staking/exported"
    10  	"github.com/cosmos/cosmos-sdk/x/staking/types"
    11  )
    12  
    13  // subspace contains the method needed for migrations of the
    14  // legacy Params subspace
    15  type subspace interface {
    16  	GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet)
    17  	HasKeyTable() bool
    18  	WithKeyTable(paramtypes.KeyTable) paramtypes.Subspace
    19  	Set(ctx sdk.Context, key []byte, value interface{})
    20  }
    21  
    22  // MigrateStore performs in-place store migrations from v0.43/v0.44/v0.45 to v0.46.
    23  // The migration includes:
    24  //
    25  // - Setting the MinCommissionRate param in the paramstore
    26  func MigrateStore(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec, paramstore exported.Subspace) error {
    27  	migrateParamsStore(ctx, paramstore.(subspace))
    28  
    29  	return nil
    30  }
    31  
    32  func migrateParamsStore(ctx sdk.Context, paramstore subspace) {
    33  	if paramstore.HasKeyTable() {
    34  		paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate)
    35  	} else {
    36  		paramstore.WithKeyTable(types.ParamKeyTable())
    37  		paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate)
    38  	}
    39  }