From df7d60182833cb4f161017f3830570f6b6b572dc Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Tue, 1 Sep 2020 18:19:03 -0700 Subject: [PATCH 1/8] Add the option of emitting amino encoded json --- x/auth/client/cli/tx_multisign.go | 19 ++++++++++++++++++- x/auth/client/cli/tx_sign.go | 20 +++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index a7c866f616fb..06b4e8aab4c1 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -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") @@ -146,11 +147,27 @@ 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) + if err != nil { return err } + var json []byte + + if aminoJSON { + json, err = clientCtx.LegacyAmino.MarshalJSON(txBuilder.GetTx()) + 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) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index b5bceecb2fa0..236453041030 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -18,6 +18,7 @@ const ( flagMultisig = "multisig" flagAppend = "append" flagSigOnly = "signature-only" + flagAmino = "amino" ) // GetSignBatchCommand returns the transaction sign-batch command. @@ -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) @@ -257,11 +259,27 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { return err } - json, err := marshalSignatureJSON(txCfg, txBuilder, generateSignatureOnly) + aminoJSON, err := cmd.Flags().GetBool(flagAmino) + if err != nil { return err } + var json []byte + + if aminoJSON { + json, err = clientCtx.LegacyAmino.MarshalJSON(txBuilder.GetTx()) + if err != nil { + return err + } + + } 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) From 1b1eb57915103e6155397ad0dc5dd05236bfa63a Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Tue, 1 Sep 2020 22:22:19 -0700 Subject: [PATCH 2/8] Update AMINO JSON serialization with ConvertTxToStdTx --- x/auth/client/cli/tx_multisign.go | 7 ++++++- x/auth/client/cli/tx_sign.go | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 06b4e8aab4c1..b0828cf68fc8 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -156,7 +156,12 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) error { var json []byte if aminoJSON { - json, err = clientCtx.LegacyAmino.MarshalJSON(txBuilder.GetTx()) + stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBuilder.GetTx()) + if err != nil { + return err + } + + json, err = clientCtx.LegacyAmino.MarshalJSON(stdTx) if err != nil { return err } diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 236453041030..801e72a0c918 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -268,7 +268,12 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { var json []byte if aminoJSON { - json, err = clientCtx.LegacyAmino.MarshalJSON(txBuilder.GetTx()) + stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBuilder.GetTx()) + if err != nil { + return err + } + + json, err = clientCtx.LegacyAmino.MarshalJSON(stdTx) if err != nil { return err } From 9469598de4d2abbe775a17c577cb851ffd5114fe Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Wed, 2 Sep 2020 22:37:48 -0700 Subject: [PATCH 3/8] Make the Amino flag more self documenting by serializing the BroadcastRequest type instead of StdTx --- x/auth/client/cli/tx_multisign.go | 9 ++++++--- x/auth/client/cli/tx_sign.go | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index b0828cf68fc8..34f7d9d93755 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -18,6 +18,7 @@ import ( signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/version" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" + "github.com/cosmos/cosmos-sdk/x/auth/client/rest" "github.com/cosmos/cosmos-sdk/x/auth/signing" ) @@ -161,11 +162,13 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) error { return err } - json, err = clientCtx.LegacyAmino.MarshalJSON(stdTx) - if err != nil { - return err + req := rest.BroadcastReq{ + Tx: stdTx, + Mode: "block|sync|async", } + json, _ = clientCtx.LegacyAmino.MarshalJSON(req) + } else { json, err = marshalSignatureJSON(txCfg, txBuilder, sigOnly) if err != nil { diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 801e72a0c918..0318861b5e9a 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -12,6 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" + "github.com/cosmos/cosmos-sdk/x/auth/client/rest" ) const ( @@ -273,11 +274,13 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { return err } - json, err = clientCtx.LegacyAmino.MarshalJSON(stdTx) - if err != nil { - return err + req := rest.BroadcastReq{ + Tx: stdTx, + Mode: "block|sync|async", } + json, err = clientCtx.LegacyAmino.MarshalJSON(req) + } else { json, err = marshalSignatureJSON(txCfg, txBuilder, generateSignatureOnly) if err != nil { From f344fdb8504d56e0810fe68c7cb78edb1c390300 Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Tue, 8 Sep 2020 20:39:03 -0700 Subject: [PATCH 4/8] Handle amino encoding error --- x/auth/client/cli/tx_sign.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 0318861b5e9a..119bcce6ce50 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -280,6 +280,9 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { } json, err = clientCtx.LegacyAmino.MarshalJSON(req) + if err != nil { + return err + } } else { json, err = marshalSignatureJSON(txCfg, txBuilder, generateSignatureOnly) From ca1d55694ef7a5378340aca455d931c5b34e445f Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Tue, 15 Sep 2020 23:47:54 -0700 Subject: [PATCH 5/8] Update x/auth/client/cli/tx_multisign.go Co-authored-by: Alessio Treglia --- x/auth/client/cli/tx_multisign.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 34f7d9d93755..a72118bef3fa 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -150,9 +150,6 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) error { aminoJSON, err := cmd.Flags().GetBool(flagAmino) - if err != nil { - return err - } var json []byte From ebb14b448aa0c4f59506875ffe972cc72c634c07 Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Tue, 15 Sep 2020 23:48:05 -0700 Subject: [PATCH 6/8] Update x/auth/client/cli/tx_sign.go Co-authored-by: Alessio Treglia --- x/auth/client/cli/tx_sign.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 119bcce6ce50..94b4c7991f38 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -283,7 +283,6 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { if err != nil { return err } - } else { json, err = marshalSignatureJSON(txCfg, txBuilder, generateSignatureOnly) if err != nil { From fe9c271c15a05fd0fea950ee13fa3ab7175b3b3f Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Tue, 6 Oct 2020 07:51:58 -0700 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Alessio Treglia --- x/auth/client/cli/tx_multisign.go | 2 +- x/auth/client/cli/tx_sign.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index afdd3efcbaab..473c980d2eeb 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -149,7 +149,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) error { sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) - aminoJSON, err := cmd.Flags().GetBool(flagAmino) + aminoJSON, _ := cmd.Flags().GetBool(flagAmino) var json []byte diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 94b4c7991f38..7046c495d663 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -260,7 +260,7 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error { return err } - aminoJSON, err := cmd.Flags().GetBool(flagAmino) + aminoJSON, _ := cmd.Flags().GetBool(flagAmino) if err != nil { return err From c821343ad2d3ab3b6d0da5f10a70d132f7ca0f75 Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Thu, 15 Oct 2020 07:54:50 -0700 Subject: [PATCH 8/8] Fix go format --- x/auth/client/cli/tx_multisign.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 473c980d2eeb..fc5e907de0a2 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -151,7 +151,6 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) error { aminoJSON, _ := cmd.Flags().GetBool(flagAmino) - var json []byte if aminoJSON {