From 3d0a9bc2f47d44159a9363bcaa9bdea15e2f1188 Mon Sep 17 00:00:00 2001 From: Ruaridh Date: Tue, 23 Feb 2021 19:40:31 +0000 Subject: [PATCH] connect Migrate func to cmd, remove unused flags (#851) --- migrate/cmd.go | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/migrate/cmd.go b/migrate/cmd.go index da94549e..c050832a 100644 --- a/migrate/cmd.go +++ b/migrate/cmd.go @@ -2,7 +2,6 @@ package migrate import ( "fmt" - "time" "github.com/spf13/cobra" @@ -11,55 +10,28 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/kava-labs/kava/migrate/v0_11" tmtypes "github.com/tendermint/tendermint/types" -) -const ( - flagGenesisTime = "genesis-time" - flagChainID = "chain-id" + "github.com/kava-labs/kava/migrate/v0_13" ) // MigrateGenesisCmd returns a command to execute genesis state migration. func MigrateGenesisCmd(_ *server.Context, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "migrate [genesis-file]", - Short: "Migrate genesis file from kava v0.10 to v0.11", - Long: "Migrate the source genesis into the current version, sorts it, and print to STDOUT. If not provided, chain-id is set to kava-4 and genesis time is set to 2020-10-15T:14:00:00Z", - Example: fmt.Sprintf(`%s migrate /path/to/genesis.json --chain-id=new-chain-id --genesis-time=1998-01-01T00:00:00Z`, version.ServerName), + Short: "Migrate genesis file from kava v0.11 (or v0.12) to v0.13", + Long: "Migrate the source genesis into the current version, sorts it, and print to STDOUT.", + Example: fmt.Sprintf(`%s migrate /path/to/genesis.json`, version.ServerName), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - // 1) Unmarshal existing genesis.json - importGenesis := args[0] genDoc, err := tmtypes.GenesisDocFromFile(importGenesis) if err != nil { return fmt.Errorf("failed to read genesis document from file %s: %w", importGenesis, err) } - // 2) Migrate state from kava v0.3 to v0.8 - - newGenDoc := v0_11.Migrate(*genDoc) - - // 3) Create and output a new genesis file - - genesisTime := cmd.Flag(flagGenesisTime).Value.String() - if genesisTime != "" { - var t time.Time - - err := t.UnmarshalText([]byte(genesisTime)) - if err != nil { - return fmt.Errorf("failed to unmarshal genesis time: %w", err) - } - - newGenDoc.GenesisTime = t - } - - chainID := cmd.Flag(flagChainID).Value.String() - if chainID != "" { - newGenDoc.ChainID = chainID - } + newGenDoc := v0_13.Migrate(*genDoc) bz, err := cdc.MarshalJSONIndent(newGenDoc, "", " ") if err != nil { @@ -76,8 +48,5 @@ func MigrateGenesisCmd(_ *server.Context, cdc *codec.Codec) *cobra.Command { }, } - cmd.Flags().String(flagGenesisTime, "", "override genesis_time with this flag") - cmd.Flags().String(flagChainID, "", "override chain_id with this flag") - return cmd }