From a25adc251fade1df92eaf10375cf5fb80e331f3e Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Tue, 11 Jun 2024 15:25:51 -0600 Subject: [PATCH 1/3] Remove the extra d chars from the wait-tx examples. --- client/rpc/tx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/rpc/tx.go b/client/rpc/tx.go index 102d70ae3d6d..94e9c5134254 100644 --- a/client/rpc/tx.go +++ b/client/rpc/tx.go @@ -102,10 +102,10 @@ func WaitTxCmd() *cobra.Command { Short: "Wait for a transaction to be included in a block", Long: `Subscribes to a CometBFT WebSocket connection and waits for a transaction event with the given hash.`, Example: fmt.Sprintf(`By providing the transaction hash: -$ %[1]sd q wait-tx [hash] +$ %[1]s q wait-tx [hash] Or, by piping a "tx" command: -$ %[1]sd tx [flags] | %[1]sd q wait-tx +$ %[1]s tx [flags] | %[1]s q wait-tx `, version.AppName), Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { From 6d10c74c586441ffa7689c455739a706ef105efb Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Tue, 11 Jun 2024 15:53:11 -0600 Subject: [PATCH 2/3] Fix the wait-tx command to properly parse the hash out of json. --- client/rpc/tx.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/client/rpc/tx.go b/client/rpc/tx.go index 94e9c5134254..9bdce23bfbda 100644 --- a/client/rpc/tx.go +++ b/client/rpc/tx.go @@ -200,13 +200,21 @@ $ %[1]s tx [flags] | %[1]s q wait-tx } func parseHashFromInput(in []byte) ([]byte, error) { - var resultTx coretypes.ResultTx - if err := json.Unmarshal(in, &resultTx); err == nil { + // The content of in is expected to be the result of a tx command which should be using GenerateOrBroadcastTxCLI. + // That outputs a sdk.TxResponse as either the json or yaml. As json, we can't unmarshal it back into that struct, + // though, because the height field ends up quoted which confuses json.Unmarshal (because it's for an int64 field). + + // Try to find the txhash from json ouptut. + resultTx := make(map[string]json.RawMessage) + if err := json.Unmarshal(in, &resultTx); err == nil && len(resultTx["txhash"]) > 0 { // input was JSON, return the hash - return resultTx.Hash, nil + hash := strings.Trim(strings.TrimSpace(string(resultTx["txhash"])), `"`) + if len(hash) > 0 { + return hex.DecodeString(hash) + } } - // try to parse the hash from the output of a tx command + // Try to find the txhash from yaml output. lines := strings.Split(string(in), "\n") for _, line := range lines { if strings.HasPrefix(line, "txhash:") { From 03cf150776e12c5f2b74bd08ddd98df9cacb4e74 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Tue, 11 Jun 2024 16:05:04 -0600 Subject: [PATCH 3/3] Add changelog entry. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5d1ce7be6b7..f86571dba6ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,6 +114,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (server) [#18994](https://github.com/cosmos/cosmos-sdk/pull/18994) Update server context directly rather than a reference to a sub-object * [#19833](https://github.com/cosmos/cosmos-sdk/pull/19833) Fix some places in which we call Remove inside a Walk. * [#19851](https://github.com/cosmos/cosmos-sdk/pull/19851) Fix some places in which we call Remove inside a Walk (x/staking and x/gov). +* [#20631](https://github.com/cosmos/cosmos-sdk/pull/20631) Fix json parsing in the wait-tx command. ### API Breaking Changes