refactor: Introduce TxDocOptions

This prepares the function to be more flexible, when more options are
passed in the future.
This commit is contained in:
MarcoFalke
2026-03-10 16:35:03 +01:00
parent fa8250e961
commit fa4d5891b9
4 changed files with 13 additions and 7 deletions

View File

@@ -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\"")

View File

@@ -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>{}
)

View File

@@ -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

View File

@@ -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,
})