From fa4d5891b964059a58cb0a9d016cc6791c4fe34b Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 10 Mar 2026 16:35:03 +0100 Subject: [PATCH] refactor: Introduce TxDocOptions This prepares the function to be more flexible, when more options are passed in the future. --- src/rpc/rawtransaction.cpp | 4 ++-- src/rpc/rawtransaction_util.cpp | 6 +++--- src/rpc/rawtransaction_util.h | 8 +++++++- src/wallet/rpc/transactions.cpp | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 5885422be7c..3632cc49ba4 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 467289fc14c..89fc1e271ca 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 DecodeTxDoc(const std::string& txid_field_doc, bool wallet) +std::vector 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 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::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only present if true)"}} : std::vector{} ) diff --git a/src/rpc/rawtransaction_util.h b/src/rpc/rawtransaction_util.h index 7bd051220a7..ed1efd0b6a5 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 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 DecodeTxDoc(const std::string& txid_field_doc, bool wallet); +std::vector 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 34ebdea79c7..2160562b90e 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, })