github.com/cosmos/cosmos-sdk@v0.50.10/x/crisis/migrations/v2/migrate.go (about)

     1  package v2
     2  
     3  import (
     4  	storetypes "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/types/errors"
     9  	"github.com/cosmos/cosmos-sdk/x/crisis/exported"
    10  )
    11  
    12  const (
    13  	ModuleName = "crisis"
    14  )
    15  
    16  var (
    17  	ConstantFee    = []byte("ConstantFee")
    18  	ConstantFeeKey = []byte{0x01}
    19  )
    20  
    21  // MigrateStore migrates the x/crisis module state from the consensus version 1 to
    22  // version 2. Specifically, it takes the `ConstantFee` parameter that is currently stored
    23  // and managed by the x/params module and stores it directly into the x/crisis
    24  // module state.
    25  func MigrateStore(ctx sdk.Context, storeService storetypes.KVStoreService, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error {
    26  	store := storeService.OpenKVStore(ctx)
    27  	var currConstantFee sdk.Coin
    28  	legacySubspace.Get(ctx, ConstantFee, &currConstantFee)
    29  
    30  	if !currConstantFee.IsValid() {
    31  		return errors.ErrInvalidCoins.Wrap("constant fee")
    32  	}
    33  
    34  	bz, err := cdc.Marshal(&currConstantFee)
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	return store.Set(ConstantFeeKey, bz)
    40  }