Skip to content

Commit

Permalink
Allow JSON input for proof specs in tendermint client (#6506)
Browse files Browse the repository at this point in the history
* Allow JSON input for proof specs in tendermint client

* fix build
  • Loading branch information
AdityaSripal authored Jun 25, 2020
1 parent 01b89bd commit dcd5781
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions x/ibc/07-tendermint/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/<app>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/<app>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())
Expand All @@ -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")
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit dcd5781

Please sign in to comment.