rpc: add decoded tx details to gettransaction with extra wallet fields
What changed, and why it matters
This commit is a documentation-only cleanup for Bitcoin Core's RPC help text. It makes the help description for the wallet's gettransaction RPC match the actual fields returned, and lets the shared DecodeTxDoc helper show an extra 'ischange' field only when used in wallet contexts. There is no code behavior change, no bug fix, and no security impact.
No action required; this is a non-security documentation/help-text refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors DecodeTxDoc() in src/rpc/rawtransaction_util.cpp to accept a boolean ‘wallet’ parameter. When wallet=true, the returned RPCResult vector includes the optional ‘ischange’ field in vout; when wallet=false it does not. getrawtransaction and decoderawtransaction now call DecodeTxDoc(…, wallet=false), while wallet’s gettransaction calls DecodeTxDoc(…, wallet=true). Previously gettransaction’s help used an ELISION placeholder. This only affects RPC help documentation generation; runtime transaction decoding and output construction are unchanged.
Changed components
src/rpc/rawtransaction.cppsrc/rpc/rawtransaction_util.cppsrc/rpc/rawtransaction_util.hsrc/wallet/rpc/transactions.cppInspect captured patch +18 / −13
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 28329000..c82c9b6a 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -242,7 +242,7 @@ static RPCHelpMan getrawtransaction()
{RPCResult::Type::NUM, "time", /*optional=*/true, "Same as \"blocktime\""},
{RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded data for 'txid'"},
},
- DecodeTxDoc(/*txid_field_doc=*/"The transaction id (same as provided)")),
+ DecodeTxDoc(/*txid_field_doc=*/"The transaction id (same as provided)", /*wallet=*/false)),
},
RPCResult{"for verbosity = 2",
RPCResult::Type::OBJ, "", "",
@@ -415,7 +415,7 @@ static RPCHelpMan decoderawtransaction()
},
RPCResult{
RPCResult::Type::OBJ, "", "",
- DecodeTxDoc(/*txid_field_doc=*/"The transaction id"),
+ DecodeTxDoc(/*txid_field_doc=*/"The transaction id", /*wallet=*/false),
},
RPCExamples{
HelpExampleCli("decoderawtransaction", "\"hexstring\"")
diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp
index 075d8f31..a746c72c 100644
--- a/src/rpc/rawtransaction_util.cpp
+++ b/src/rpc/rawtransaction_util.cpp
@@ -335,7 +335,7 @@ void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const
}
}
-std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
+std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc, bool wallet)
{
return {
{RPCResult::Type::STR_HEX, "txid", txid_field_doc},
@@ -366,13 +366,17 @@ std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
}},
{RPCResult::Type::ARR, "vout", "",
{
- {RPCResult::Type::OBJ, "", "",
- {
- {RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
- {RPCResult::Type::NUM, "n", "index"},
- {RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
- {RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only if wallet transaction and true for selected rpcwallet)"},
- }},
+ {RPCResult::Type::OBJ, "", "", Cat(
+ {
+ {RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
+ {RPCResult::Type::NUM, "n", "index"},
+ {RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
+ },
+ wallet ?
+ std::vector<RPCResult>{{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only present if true)"}} :
+ std::vector<RPCResult>{}
+ )
+ },
}},
};
}
diff --git a/src/rpc/rawtransaction_util.h b/src/rpc/rawtransaction_util.h
index 1a673f98..3d917489 100644
--- a/src/rpc/rawtransaction_util.h
+++ b/src/rpc/rawtransaction_util.h
@@ -56,7 +56,7 @@ void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in);
/** Create a transaction from univalue parameters */
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, std::optional<bool> rbf);
-/** Explain the UniValue "decoded" transaction object **/
-std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc);
+/** Explain the UniValue "decoded" transaction object, may include extra fields if processed by wallet **/
+std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc, bool wallet);
#endif // BITCOIN_RPC_RAWTRANSACTION_UTIL_H
diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp
index 36044afd..4c2451b1 100644
--- a/src/wallet/rpc/transactions.cpp
+++ b/src/wallet/rpc/transactions.cpp
@@ -6,6 +6,7 @@
#include <key_io.h>
#include <policy/rbf.h>
#include <rpc/util.h>
+#include <rpc/rawtransaction_util.h>
#include <rpc/blockchain.h>
#include <util/vector.h>
#include <wallet/receive.h>
@@ -738,7 +739,7 @@ RPCHelpMan gettransaction()
{RPCResult::Type::STR_HEX, "hex", "Raw data for transaction"},
{RPCResult::Type::OBJ, "decoded", /*optional=*/true, "The decoded transaction (only present when `verbose` is passed)",
{
- {RPCResult::Type::ELISION, "", "Equivalent to the RPC decoderawtransaction method, or the RPC getrawtransaction method when `verbose` is passed."},
+ DecodeTxDoc(/*txid_field_doc=*/"The transaction id", /*wallet=*/true),
}},
RESULT_LAST_PROCESSED_BLOCK,
})
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.