Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow JSON input for proof specs in tendermint client #6506

Merged
merged 3 commits into from
Jun 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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