What changed, and why it matters
This commit is a simple code cleanup: it replaces a function that took two separate arguments with a small options structure. The behavior of the software is unchanged; only the internal organization of the code is different. There is no security issue here.
No action required; this is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors DecodeTxDoc(std::string txid_field_doc, bool wallet) into TxDoc(TxDocOptions opts). It introduces a TxDocOptions struct with default values matching the previous defaults (txid_field_doc defaults to “The transaction id”, wallet defaults to false) and updates call sites to use the new API. The generated RPC help documentation and runtime behavior are functionally identical.
Changed components
src/rpc/rawtransaction.cppsrc/rpc/rawtransaction_util.cppsrc/rpc/rawtransaction_util.hsrc/wallet/rpc/transactions.cppInspect captured patch +13 / −7
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 5885422b..3632cc49 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -248,7 +248,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)", /*wallet=*/false)),
+ TxDoc({.txid_field_doc="The transaction id (same as provided)"})),
},
RPCResult{"for verbosity = 2",
RPCResult::Type::OBJ, "", "",
@@ -422,7 +422,7 @@ static RPCHelpMan decoderawtransaction()
},
RPCResult{
RPCResult::Type::OBJ, "", "",
- DecodeTxDoc(/*txid_field_doc=*/"The transaction id", /*wallet=*/false),
+ TxDoc(),
},
RPCExamples{
HelpExampleCli("decoderawtransaction", "\"hexstring\"")
diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp
index 467289fc..89fc1e27 100644
--- a/src/rpc/rawtransaction_util.cpp
+++ b/src/rpc/rawtransaction_util.cpp
@@ -344,10 +344,10 @@ void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const
}
}
-std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc, bool wallet)
+std::vector<RPCResult> TxDoc(const TxDocOptions& opts)
{
return {
- {RPCResult::Type::STR_HEX, "txid", txid_field_doc},
+ {RPCResult::Type::STR_HEX, "txid", opts.txid_field_doc},
{RPCResult::Type::STR_HEX, "hash", "The transaction hash (differs from txid for witness transactions)"},
{RPCResult::Type::NUM, "size", "The serialized transaction size"},
{RPCResult::Type::NUM, "vsize", "The virtual transaction size (differs from size for witness transactions)"},
@@ -381,7 +381,7 @@ std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc, bool walle
{RPCResult::Type::NUM, "n", "index"},
{RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
},
- wallet ?
+ opts.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 7bd05122..ed1efd0b 100644
--- a/src/rpc/rawtransaction_util.h
+++ b/src/rpc/rawtransaction_util.h
@@ -56,7 +56,13 @@ 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, uint32_t version);
+struct TxDocOptions {
+ /// The description of the txid field
+ std::string txid_field_doc{"The transaction id"};
+ /// Include wallet-related fields (e.g. ischange on outputs)
+ bool wallet{false};
+};
/** 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);
+std::vector<RPCResult> TxDoc(const TxDocOptions& opts = {});
#endif // BITCOIN_RPC_RAWTRANSACTION_UTIL_H
diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp
index 34ebdea7..2160562b 100644
--- a/src/wallet/rpc/transactions.cpp
+++ b/src/wallet/rpc/transactions.cpp
@@ -705,7 +705,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)",
{
- DecodeTxDoc(/*txid_field_doc=*/"The transaction id", /*wallet=*/true),
+ TxDoc({.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.