From dcd578183d195562b440fdb615a79a7d706677c7 Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 25 Jun 2020 03:30:13 -0400 Subject: [PATCH] Allow JSON input for proof specs in tendermint client (#6506) * Allow JSON input for proof specs in tendermint client * fix build --- x/ibc/07-tendermint/client/cli/tx.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/x/ibc/07-tendermint/client/cli/tx.go b/x/ibc/07-tendermint/client/cli/tx.go index bd82a0f13e1b..e9cc6a1d101d 100644 --- a/x/ibc/07-tendermint/client/cli/tx.go +++ b/x/ibc/07-tendermint/client/cli/tx.go @@ -42,8 +42,8 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command { Short: "create new tendermint client", Long: `Create a new tendermint IBC client. - 'trust-level' flag can be a fraction (eg: '1/3') or 'default' - - 'proof-specs' flag can be a comma-separated list of strings (eg: 'ics23:simple,ics23:iavl') or 'default'`, - Example: fmt.Sprintf("%s tx ibc %s create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift] --trust-level default --from node0 --home ../node0/cli --chain-id $CID", version.ClientName, ibctmtypes.SubModuleName), + - 'proof-specs' flag can be JSON input, a path to a .json file or 'default'`, + Example: fmt.Sprintf("%s tx ibc %s create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift] --trust-level default --proof-specs [path/to/proof-specs.json] --from node0 --home ../node0/cli --chain-id $CID", version.ClientName, ibctmtypes.SubModuleName), Args: cobra.ExactArgs(5), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) @@ -57,7 +57,7 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command { // check for file path if JSON input is not provided contents, err := ioutil.ReadFile(args[1]) if err != nil { - return errors.New("neither JSON input nor path to .json file were provided") + return errors.New("neither JSON input nor path to .json file were provided for consensus header") } if err := cdc.UnmarshalJSON(contents, &header); err != nil { return errors.Wrap(err, "error unmarshalling consensus header file") @@ -97,15 +97,17 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command { } spc := viper.GetString(flagProofSpecs) - - // Currently supports SDK chain or simple kvstore tendermint chain - switch spc { - case "default": + if spc == "default" { specs = commitmenttypes.GetSDKSpecs() - case "simple": - specs = []*ics23.ProofSpec{ics23.TendermintSpec} - default: - return fmt.Errorf("proof spec: %s isn't supported", spc) + } else if err := cdc.UnmarshalJSON([]byte(spc), &specs); err != nil { + // check for file path if JSON input not provided + contents, err := ioutil.ReadFile(spc) + if err != nil { + return errors.New("neither JSON input nor path to .json file was provided for proof specs flag") + } + if err := cdc.UnmarshalJSON(contents, &specs); err != nil { + return errors.Wrap(err, "error unmarshalling proof specs file") + } } msg := ibctmtypes.NewMsgCreateClient(