github.com/Finschia/finschia-sdk@v0.49.1/x/foundation/keeper/internal/migrations/v2/store.go (about)

     1  package v2
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/Finschia/finschia-sdk/codec"
     7  	storetypes "github.com/Finschia/finschia-sdk/store/types"
     8  	sdk "github.com/Finschia/finschia-sdk/types"
     9  	"github.com/Finschia/finschia-sdk/x/foundation"
    10  )
    11  
    12  // MigrateStore performs in-place store migrations from v1 to v2.
    13  func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, subspace Subspace) error {
    14  	store := ctx.KVStore(storeKey)
    15  
    16  	// migrate params
    17  	if err := migrateParams(ctx, store, cdc, subspace); err != nil {
    18  		return err
    19  	}
    20  
    21  	return nil
    22  }
    23  
    24  func migrateParams(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec, subspace Subspace) error {
    25  	bz := store.Get(ParamsKey)
    26  	if bz == nil {
    27  		return fmt.Errorf("params not found")
    28  	}
    29  	store.Delete(ParamsKey)
    30  
    31  	var params foundation.Params
    32  	if err := cdc.Unmarshal(bz, &params); err != nil {
    33  		return err
    34  	}
    35  
    36  	subspace.SetParamSet(ctx, &params)
    37  
    38  	return nil
    39  }