Skip to content

Commit a24e633

Browse files
committed
refactor: rpc: set TxToJSON default verbosity to SHOW_DETAILS
`TxToJSON()` and `TxToUniv()` are only to be called when we want to decode the transaction (i.e. its details) into JSON. If `TxVerbosity` is `SHOW_TXID`, the function should not have been (and currently is not) called in the first place. There is no behaviour change, current logic simply assumes anything less than `TxVerbosity::SHOW_DETAILS_AND_PREVOUT` equals `TxVerbosity::SHOW_DETAILS`. With this change, the assumptions and intent become more explicit.
1 parent 77a3603 commit a24e633

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/core_write.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool i
170170

171171
void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo, TxVerbosity verbosity)
172172
{
173+
CHECK_NONFATAL(verbosity >= TxVerbosity::SHOW_DETAILS);
174+
173175
entry.pushKV("txid", tx.GetHash().GetHex());
174176
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
175177
// Transaction version is actually unsigned in consensus checks, just signed in memory,

src/rpc/rawtransaction.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ using node::PSBTAnalysis;
5454
using node::ReadBlockFromDisk;
5555
using node::UndoReadFromDisk;
5656

57-
static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, Chainstate& active_chainstate, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_TXID)
57+
static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry,
58+
Chainstate& active_chainstate, const CTxUndo* txundo = nullptr,
59+
TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS)
5860
{
61+
CHECK_NONFATAL(verbosity >= TxVerbosity::SHOW_DETAILS);
5962
// Call into TxToUniv() in bitcoin-common to decode the transaction hex.
6063
//
6164
// Blockchain contextual information (confirmations and blocktime) is not

0 commit comments

Comments
 (0)