github.com/Finschia/finschia-sdk@v0.48.1/x/genutil/legacy/v043/migrate.go (about)

     1  package v043
     2  
     3  import (
     4  	"github.com/Finschia/finschia-sdk/client"
     5  	v040bank "github.com/Finschia/finschia-sdk/x/bank/legacy/v040"
     6  	v043bank "github.com/Finschia/finschia-sdk/x/bank/legacy/v043"
     7  	bank "github.com/Finschia/finschia-sdk/x/bank/types"
     8  	"github.com/Finschia/finschia-sdk/x/genutil/types"
     9  	v040gov "github.com/Finschia/finschia-sdk/x/gov/legacy/v040"
    10  	v043gov "github.com/Finschia/finschia-sdk/x/gov/legacy/v043"
    11  	gov "github.com/Finschia/finschia-sdk/x/gov/types"
    12  )
    13  
    14  // Migrate migrates exported state from v0.40 to a v0.43 genesis state.
    15  func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap {
    16  	// Migrate x/gov.
    17  	if appState[v040gov.ModuleName] != nil {
    18  		// unmarshal relative source genesis application state
    19  		var oldGovState gov.GenesisState
    20  		clientCtx.Codec.MustUnmarshalJSON(appState[v040gov.ModuleName], &oldGovState)
    21  
    22  		// delete deprecated x/gov genesis state
    23  		delete(appState, v040gov.ModuleName)
    24  
    25  		// Migrate relative source genesis application state and marshal it into
    26  		// the respective key.
    27  		appState[v043gov.ModuleName] = clientCtx.Codec.MustMarshalJSON(v043gov.MigrateJSON(&oldGovState))
    28  	}
    29  
    30  	if appState[v040bank.ModuleName] != nil {
    31  		// unmarshal relative source genesis application state
    32  		var oldBankState bank.GenesisState
    33  		clientCtx.Codec.MustUnmarshalJSON(appState[v040bank.ModuleName], &oldBankState)
    34  
    35  		// delete deprecated x/bank genesis state
    36  		delete(appState, v040bank.ModuleName)
    37  
    38  		// Migrate relative source genesis application state and marshal it into
    39  		// the respective key.
    40  		appState[v043bank.ModuleName] = clientCtx.Codec.MustMarshalJSON(v043bank.MigrateJSON(&oldBankState))
    41  	}
    42  
    43  	return appState
    44  }