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

Add the option of emitting amino encoded json from the CLI #7221

Merged
merged 13 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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: 23 additions & 1 deletion x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ recommended to set such parameters manually.

cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit")
cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT")
cmd.Flags().Bool(flagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint")
flags.AddTxFlagsToCmd(cmd)
cmd.Flags().String(flags.FlagChainID, "", "network chain ID")

Expand Down Expand Up @@ -146,11 +147,32 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) error {

sigOnly, _ := cmd.Flags().GetBool(flagSigOnly)

json, err := marshalSignatureJSON(txCfg, txBuilder, sigOnly)
aminoJSON, err := cmd.Flags().GetBool(flagAmino)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can ignore the error IMHO

zmanian marked this conversation as resolved.
Show resolved Hide resolved

if err != nil {
return err
}
zmanian marked this conversation as resolved.
Show resolved Hide resolved

var json []byte

if aminoJSON {
stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBuilder.GetTx())
if err != nil {
return err
}

json, err = clientCtx.LegacyAmino.MarshalJSON(stdTx)
if err != nil {
return err
}

} else {
json, err = marshalSignatureJSON(txCfg, txBuilder, sigOnly)
if err != nil {
return err
}
}

outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument)
if outputDoc == "" {
cmd.Printf("%s\n", json)
Expand Down
25 changes: 24 additions & 1 deletion x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
flagMultisig = "multisig"
flagAppend = "append"
flagSigOnly = "signature-only"
flagAmino = "amino"
)

// GetSignBatchCommand returns the transaction sign-batch command.
Expand Down Expand Up @@ -187,6 +188,7 @@ be generated via the 'multisign' command.
cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit")
cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT")
cmd.Flags().String(flags.FlagChainID, "", "The network chain ID")
cmd.Flags().Bool(flagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint")
cmd.MarkFlagRequired(flags.FlagFrom)
flags.AddTxFlagsToCmd(cmd)

Expand Down Expand Up @@ -257,11 +259,32 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error {
return err
}

json, err := marshalSignatureJSON(txCfg, txBuilder, generateSignatureOnly)
aminoJSON, err := cmd.Flags().GetBool(flagAmino)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

zmanian marked this conversation as resolved.
Show resolved Hide resolved

if err != nil {
return err
}
Comment on lines 265 to 267
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err != nil {
return err
}


var json []byte

if aminoJSON {
stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBuilder.GetTx())
if err != nil {
return err
}

json, err = clientCtx.LegacyAmino.MarshalJSON(stdTx)
if err != nil {
return err
}

zmanian marked this conversation as resolved.
Show resolved Hide resolved
} else {
json, err = marshalSignatureJSON(txCfg, txBuilder, generateSignatureOnly)
if err != nil {
return err
}
}

outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument)
if outputDoc == "" {
cmd.Printf("%s\n", json)
Expand Down