From 5795e74110570850895c5c7e54f1d11f3e27a60f Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Tue, 4 Feb 2025 13:50:41 +0200 Subject: [PATCH 1/2] auth: Improve cli tx decoding with fallback to direct txBytes protobuf unmarshaling IIRC before it supported just signBytes --- x/auth/client/cli/decode.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index 0b6337bb7742..41480d575f46 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" ) const flagHex = "hex" @@ -32,12 +33,7 @@ func GetDecodeCommand() *cobra.Command { return err } - tx, err := clientCtx.TxConfig.TxDecoder()(txBytes) - if err != nil { - return err - } - - json, err := clientCtx.TxConfig.TxJSONEncoder()(tx) + json, err := decodeTxAndGetJSON(clientCtx, txBytes) if err != nil { return err } @@ -52,3 +48,19 @@ func GetDecodeCommand() *cobra.Command { return cmd } + +func decodeTxAndGetJSON(clientCtx client.Context, txBytes []byte) ([]byte, error) { + // First try decoding with TxDecoder + tx, err := clientCtx.TxConfig.TxDecoder()(txBytes) + if err == nil { + return clientCtx.TxConfig.TxJSONEncoder()(tx) + } + + // Fallback to direct unmarshaling + var sdkTx sdktx.Tx + if err := clientCtx.Codec.Unmarshal(txBytes, &sdkTx); err != nil { + return nil, err + } + + return clientCtx.Codec.MarshalJSON(&sdkTx) +} From e956b5015f045aacd29ac7a801cbe75641a2a6a8 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Tue, 4 Feb 2025 19:51:05 +0200 Subject: [PATCH 2/2] Update x/auth/client/cli/decode.go Co-authored-by: Alex | Interchain Labs --- x/auth/client/cli/decode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index 41480d575f46..3e305ffc7164 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -59,7 +59,7 @@ func decodeTxAndGetJSON(clientCtx client.Context, txBytes []byte) ([]byte, error // Fallback to direct unmarshaling var sdkTx sdktx.Tx if err := clientCtx.Codec.Unmarshal(txBytes, &sdkTx); err != nil { - return nil, err + return nil, fmt.Errorf("failed to directly unmarshal txBytes: %w", err) } return clientCtx.Codec.MarshalJSON(&sdkTx)