mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-10 15:47:17 +02:00
refactor: Introduce TxDocOptions
This prepares the function to be more flexible, when more options are passed in the future.
This commit is contained in:
@@ -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\"")
|
||||
|
||||
@@ -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>{}
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user