3535#include < util/bip32.h>
3636#include < util/strencodings.h>
3737#include < util/string.h>
38+ #include < util/vector.h>
3839#include < validation.h>
3940#include < validationinterface.h>
4041
@@ -77,6 +78,54 @@ static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue&
7778 }
7879}
7980
81+ static std::vector<RPCResult> DecodeTxDoc (const std::string& txid_field_doc)
82+ {
83+ return {
84+ {RPCResult::Type::STR_HEX, " txid" , txid_field_doc},
85+ {RPCResult::Type::STR_HEX, " hash" , " The transaction hash (differs from txid for witness transactions)" },
86+ {RPCResult::Type::NUM, " size" , " The serialized transaction size" },
87+ {RPCResult::Type::NUM, " vsize" , " The virtual transaction size (differs from size for witness transactions)" },
88+ {RPCResult::Type::NUM, " weight" , " The transaction's weight (between vsize*4-3 and vsize*4)" },
89+ {RPCResult::Type::NUM, " version" , " The version" },
90+ {RPCResult::Type::NUM_TIME, " locktime" , " The lock time" },
91+ {RPCResult::Type::ARR, " vin" , " " ,
92+ {
93+ {RPCResult::Type::OBJ, " " , " " ,
94+ {
95+ {RPCResult::Type::STR_HEX, " coinbase" , /* optional=*/ true , " The coinbase value (only if coinbase transaction)" },
96+ {RPCResult::Type::STR_HEX, " txid" , /* optional=*/ true , " The transaction id (if not coinbase transaction)" },
97+ {RPCResult::Type::NUM, " vout" , /* optional=*/ true , " The output number (if not coinbase transaction)" },
98+ {RPCResult::Type::OBJ, " scriptSig" , /* optional=*/ true , " The script (if not coinbase transaction)" ,
99+ {
100+ {RPCResult::Type::STR, " asm" , " asm" },
101+ {RPCResult::Type::STR_HEX, " hex" , " hex" },
102+ }},
103+ {RPCResult::Type::ARR, " txinwitness" , /* optional=*/ true , " " ,
104+ {
105+ {RPCResult::Type::STR_HEX, " hex" , " hex-encoded witness data (if any)" },
106+ }},
107+ {RPCResult::Type::NUM, " sequence" , " The script sequence number" },
108+ }},
109+ }},
110+ {RPCResult::Type::ARR, " vout" , " " ,
111+ {
112+ {RPCResult::Type::OBJ, " " , " " ,
113+ {
114+ {RPCResult::Type::STR_AMOUNT, " value" , " The value in " + CURRENCY_UNIT},
115+ {RPCResult::Type::NUM, " n" , " index" },
116+ {RPCResult::Type::OBJ, " scriptPubKey" , " " ,
117+ {
118+ {RPCResult::Type::STR, " asm" , " the asm" },
119+ {RPCResult::Type::STR, " desc" , " Inferred descriptor for the output" },
120+ {RPCResult::Type::STR_HEX, " hex" , " the hex" },
121+ {RPCResult::Type::STR, " type" , " The type, eg 'pubkeyhash'" },
122+ {RPCResult::Type::STR, " address" , /* optional=*/ true , " The Bitcoin address (only if a well-defined address exists)" },
123+ }},
124+ }},
125+ }},
126+ };
127+ }
128+
80129static std::vector<RPCArg> CreateTxDoc ()
81130{
82131 return {
@@ -118,7 +167,7 @@ static RPCHelpMan getrawtransaction()
118167{
119168 return RPCHelpMan{
120169 " getrawtransaction" ,
121- " \n Return the raw transaction data.\n "
170+ " Return the raw transaction data.\n "
122171
123172 " \n By default, this call only returns a transaction if it is in the mempool. If -txindex is enabled\n "
124173 " and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.\n "
@@ -127,7 +176,7 @@ static RPCHelpMan getrawtransaction()
127176 " \n Hint: Use gettransaction for wallet transactions.\n "
128177
129178 " \n If verbose is 'true', returns an Object with information about 'txid'.\n "
130- " If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.\n " ,
179+ " If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'." ,
131180 {
132181 {" txid" , RPCArg::Type::STR_HEX, RPCArg::Optional::NO, " The transaction id" },
133182 {" verbose" , RPCArg::Type::BOOL, RPCArg::Default{false }, " If false, return a string, otherwise return a json object" },
@@ -138,58 +187,17 @@ static RPCHelpMan getrawtransaction()
138187 RPCResult::Type::STR, " data" , " The serialized, hex-encoded data for 'txid'"
139188 },
140189 RPCResult{" if verbose is set to true" ,
141- // When updating this documentation, update `decoderawtransaction` in the same way.
142190 RPCResult::Type::OBJ, " " , " " ,
191+ Cat<std::vector<RPCResult>>(
143192 {
144193 {RPCResult::Type::BOOL, " in_active_chain" , /* optional=*/ true , " Whether specified block is in the active chain or not (only present with explicit \" blockhash\" argument)" },
145- {RPCResult::Type::STR_HEX, " hex" , " The serialized, hex-encoded data for 'txid'" },
146- {RPCResult::Type::STR_HEX, " txid" , " The transaction id (same as provided)" },
147- {RPCResult::Type::STR_HEX, " hash" , " The transaction hash (differs from txid for witness transactions)" },
148- {RPCResult::Type::NUM, " size" , " The serialized transaction size" },
149- {RPCResult::Type::NUM, " vsize" , " The virtual transaction size (differs from size for witness transactions)" },
150- {RPCResult::Type::NUM, " weight" , " The transaction's weight (between vsize*4-3 and vsize*4)" },
151- {RPCResult::Type::NUM, " version" , " The version" },
152- {RPCResult::Type::NUM_TIME, " locktime" , " The lock time" },
153- {RPCResult::Type::ARR, " vin" , " " ,
154- {
155- {RPCResult::Type::OBJ, " " , " " ,
156- {
157- {RPCResult::Type::STR_HEX, " coinbase" , /* optional=*/ true , " The coinbase value (only if coinbase transaction)" },
158- {RPCResult::Type::STR_HEX, " txid" , /* optional=*/ true , " The transaction id (if not coinbase transaction)" },
159- {RPCResult::Type::NUM, " vout" , /* optional=*/ true , " The output number (if not coinbase transaction)" },
160- {RPCResult::Type::OBJ, " scriptSig" , /* optional=*/ true , " The script (if not coinbase transaction)" ,
161- {
162- {RPCResult::Type::STR, " asm" , " asm" },
163- {RPCResult::Type::STR_HEX, " hex" , " hex" },
164- }},
165- {RPCResult::Type::ARR, " txinwitness" , /* optional=*/ true , " " ,
166- {
167- {RPCResult::Type::STR_HEX, " hex" , " hex-encoded witness data (if any)" },
168- }},
169- {RPCResult::Type::NUM, " sequence" , " The script sequence number" },
170- }},
171- }},
172- {RPCResult::Type::ARR, " vout" , " " ,
173- {
174- {RPCResult::Type::OBJ, " " , " " ,
175- {
176- {RPCResult::Type::STR_AMOUNT, " value" , " The value in " + CURRENCY_UNIT},
177- {RPCResult::Type::NUM, " n" , " index" },
178- {RPCResult::Type::OBJ, " scriptPubKey" , " " ,
179- {
180- {RPCResult::Type::STR, " asm" , " the asm" },
181- {RPCResult::Type::STR, " desc" , " Inferred descriptor for the output" },
182- {RPCResult::Type::STR_HEX, " hex" , " the hex" },
183- {RPCResult::Type::STR, " type" , " The type, eg 'pubkeyhash'" },
184- {RPCResult::Type::STR, " address" , /* optional=*/ true , " The Bitcoin address (only if a well-defined address exists)" },
185- }},
186- }},
187- }},
188194 {RPCResult::Type::STR_HEX, " blockhash" , /* optional=*/ true , " the block hash" },
189195 {RPCResult::Type::NUM, " confirmations" , /* optional=*/ true , " The confirmations" },
190196 {RPCResult::Type::NUM_TIME, " blocktime" , /* optional=*/ true , " The block time expressed in " + UNIX_EPOCH_TIME},
191197 {RPCResult::Type::NUM, " time" , /* optional=*/ true , " Same as \" blocktime\" " },
192- }
198+ {RPCResult::Type::STR_HEX, " hex" , " The serialized, hex-encoded data for 'txid'" },
199+ },
200+ DecodeTxDoc (/* txid_field_doc=*/ " The transaction id (same as provided)" )),
193201 },
194202 },
195203 RPCExamples{
@@ -309,7 +317,7 @@ static RPCHelpMan createrawtransaction()
309317static RPCHelpMan decoderawtransaction ()
310318{
311319 return RPCHelpMan{" decoderawtransaction" ,
312- " \n Return a JSON object representing the serialized, hex-encoded transaction.\n " ,
320+ " Return a JSON object representing the serialized, hex-encoded transaction." ,
313321 {
314322 {" hexstring" , RPCArg::Type::STR_HEX, RPCArg::Optional::NO, " The transaction hex string" },
315323 {" iswitness" , RPCArg::Type::BOOL, RPCArg::DefaultHint{" depends on heuristic tests" }, " Whether the transaction hex is a serialized witness transaction.\n "
@@ -322,51 +330,7 @@ static RPCHelpMan decoderawtransaction()
322330 },
323331 RPCResult{
324332 RPCResult::Type::OBJ, " " , " " ,
325- {
326- // When updating this documentation, update `getrawtransaction` in the same way.
327- {RPCResult::Type::STR_HEX, " txid" , " The transaction id" },
328- {RPCResult::Type::STR_HEX, " hash" , " The transaction hash (differs from txid for witness transactions)" },
329- {RPCResult::Type::NUM, " size" , " The serialized transaction size" },
330- {RPCResult::Type::NUM, " vsize" , " The virtual transaction size (differs from size for witness transactions)" },
331- {RPCResult::Type::NUM, " weight" , " The transaction's weight (between vsize*4-3 and vsize*4)" },
332- {RPCResult::Type::NUM, " version" , " The version" },
333- {RPCResult::Type::NUM_TIME, " locktime" , " The lock time" },
334- {RPCResult::Type::ARR, " vin" , " " ,
335- {
336- {RPCResult::Type::OBJ, " " , " " ,
337- {
338- {RPCResult::Type::STR_HEX, " coinbase" , /* optional=*/ true , " The coinbase value (only if coinbase transaction)" },
339- {RPCResult::Type::STR_HEX, " txid" , /* optional=*/ true , " The transaction id (if not coinbase transaction)" },
340- {RPCResult::Type::NUM, " vout" , /* optional=*/ true , " The output number (if not coinbase transaction)" },
341- {RPCResult::Type::OBJ, " scriptSig" , /* optional=*/ true , " The script (if not coinbase transaction)" ,
342- {
343- {RPCResult::Type::STR, " asm" , " asm" },
344- {RPCResult::Type::STR_HEX, " hex" , " hex" },
345- }},
346- {RPCResult::Type::ARR, " txinwitness" , /* optional=*/ true , " " ,
347- {
348- {RPCResult::Type::STR_HEX, " hex" , " hex-encoded witness data (if any)" },
349- }},
350- {RPCResult::Type::NUM, " sequence" , " The script sequence number" },
351- }},
352- }},
353- {RPCResult::Type::ARR, " vout" , " " ,
354- {
355- {RPCResult::Type::OBJ, " " , " " ,
356- {
357- {RPCResult::Type::STR_AMOUNT, " value" , " The value in " + CURRENCY_UNIT},
358- {RPCResult::Type::NUM, " n" , " index" },
359- {RPCResult::Type::OBJ, " scriptPubKey" , " " ,
360- {
361- {RPCResult::Type::STR, " asm" , " the asm" },
362- {RPCResult::Type::STR, " desc" , " Inferred descriptor for the output" },
363- {RPCResult::Type::STR_HEX, " hex" , " the hex" },
364- {RPCResult::Type::STR, " type" , " The type, eg 'pubkeyhash'" },
365- {RPCResult::Type::STR, " address" , /* optional=*/ true , " The Bitcoin address (only if a well-defined address exists)" },
366- }},
367- }},
368- }},
369- }
333+ DecodeTxDoc (/* txid_field_doc=*/ " The transaction id" ),
370334 },
371335 RPCExamples{
372336 HelpExampleCli (" decoderawtransaction" , " \" hexstring\" " )
0 commit comments