Skip to content

Commit ad1c3bd

Browse files
committed
[move only] move DecodeTxDoc() to a common util file for sharing
1 parent d633db5 commit ad1c3bd

File tree

3 files changed

+46
-42
lines changed

3 files changed

+46
-42
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -82,48 +82,6 @@ static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue&
8282
}
8383
}
8484

85-
static std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
86-
{
87-
return {
88-
{RPCResult::Type::STR_HEX, "txid", txid_field_doc},
89-
{RPCResult::Type::STR_HEX, "hash", "The transaction hash (differs from txid for witness transactions)"},
90-
{RPCResult::Type::NUM, "size", "The serialized transaction size"},
91-
{RPCResult::Type::NUM, "vsize", "The virtual transaction size (differs from size for witness transactions)"},
92-
{RPCResult::Type::NUM, "weight", "The transaction's weight (between vsize*4-3 and vsize*4)"},
93-
{RPCResult::Type::NUM, "version", "The version"},
94-
{RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
95-
{RPCResult::Type::ARR, "vin", "",
96-
{
97-
{RPCResult::Type::OBJ, "", "",
98-
{
99-
{RPCResult::Type::STR_HEX, "coinbase", /*optional=*/true, "The coinbase value (only if coinbase transaction)"},
100-
{RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id (if not coinbase transaction)"},
101-
{RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number (if not coinbase transaction)"},
102-
{RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script (if not coinbase transaction)",
103-
{
104-
{RPCResult::Type::STR, "asm", "Disassembly of the signature script"},
105-
{RPCResult::Type::STR_HEX, "hex", "The raw signature script bytes, hex-encoded"},
106-
}},
107-
{RPCResult::Type::ARR, "txinwitness", /*optional=*/true, "",
108-
{
109-
{RPCResult::Type::STR_HEX, "hex", "hex-encoded witness data (if any)"},
110-
}},
111-
{RPCResult::Type::NUM, "sequence", "The script sequence number"},
112-
}},
113-
}},
114-
{RPCResult::Type::ARR, "vout", "",
115-
{
116-
{RPCResult::Type::OBJ, "", "",
117-
{
118-
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
119-
{RPCResult::Type::NUM, "n", "index"},
120-
{RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
121-
{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only if wallet transaction and true for selected rpcwallet)"},
122-
}},
123-
}},
124-
};
125-
}
126-
12785
static std::vector<RPCArg> CreateTxDoc()
12886
{
12987
return {

src/rpc/rawtransaction_util.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,45 @@ void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const
334334
result.pushKV("errors", std::move(vErrors));
335335
}
336336
}
337+
338+
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
339+
{
340+
return {
341+
{RPCResult::Type::STR_HEX, "txid", txid_field_doc},
342+
{RPCResult::Type::STR_HEX, "hash", "The transaction hash (differs from txid for witness transactions)"},
343+
{RPCResult::Type::NUM, "size", "The serialized transaction size"},
344+
{RPCResult::Type::NUM, "vsize", "The virtual transaction size (differs from size for witness transactions)"},
345+
{RPCResult::Type::NUM, "weight", "The transaction's weight (between vsize*4-3 and vsize*4)"},
346+
{RPCResult::Type::NUM, "version", "The version"},
347+
{RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
348+
{RPCResult::Type::ARR, "vin", "",
349+
{
350+
{RPCResult::Type::OBJ, "", "",
351+
{
352+
{RPCResult::Type::STR_HEX, "coinbase", /*optional=*/true, "The coinbase value (only if coinbase transaction)"},
353+
{RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id (if not coinbase transaction)"},
354+
{RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number (if not coinbase transaction)"},
355+
{RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script (if not coinbase transaction)",
356+
{
357+
{RPCResult::Type::STR, "asm", "Disassembly of the signature script"},
358+
{RPCResult::Type::STR_HEX, "hex", "The raw signature script bytes, hex-encoded"},
359+
}},
360+
{RPCResult::Type::ARR, "txinwitness", /*optional=*/true, "",
361+
{
362+
{RPCResult::Type::STR_HEX, "hex", "hex-encoded witness data (if any)"},
363+
}},
364+
{RPCResult::Type::NUM, "sequence", "The script sequence number"},
365+
}},
366+
}},
367+
{RPCResult::Type::ARR, "vout", "",
368+
{
369+
{RPCResult::Type::OBJ, "", "",
370+
{
371+
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
372+
{RPCResult::Type::NUM, "n", "index"},
373+
{RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
374+
{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only if wallet transaction and true for selected rpcwallet)"},
375+
}},
376+
}},
377+
};
378+
}

src/rpc/rawtransaction_util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <addresstype.h>
99
#include <consensus/amount.h>
10+
#include <rpc/util.h>
1011
#include <map>
1112
#include <string>
1213
#include <optional>
@@ -55,4 +56,7 @@ void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in);
5556
/** Create a transaction from univalue parameters */
5657
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, std::optional<bool> rbf);
5758

59+
/** Explain the UniValue "decoded" transaction object **/
60+
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc);
61+
5862
#endif // BITCOIN_RPC_RAWTRANSACTION_UTIL_H

0 commit comments

Comments
 (0)