Skip to content

Commit 1a54c06

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24716: rpc: Fix documentation assertion for getrawtransaction
71038a1 rpc: Fix documentation assertion for `getrawtransaction` (laanwj) Pull request description: When `getrawtransaction` is successfully used on a coinbase transaction, there is an assertion error. This is very unlikely but happens in the `interface_usdt_utxocache.py` test in #24358. This does the following: - Add missing "coinbase" documentation. - Synchronize documentation between `getrawtransaction` and `decoderawtransaction`, the two users of `TxToUniv` that have detailed documentation. `decodepsbt` and `getblock` also uses it but fortunately elides this block. - Change "vout[].amount" to `STR_AMOUNT` for consistency. - Add maintainer comment to keep the two places synchronized. It might be possible to get smarter with deduplication, but there are some extra fields that prevent the obvious way. ACKs for top commit: jonatack: ACK 71038a1 Tree-SHA512: 962236130455d805190ff9a5c971e4e25c17db35614a90ce340264ec953b0ad7fb814eb33ae430b5073955a8a350f72bdd67ba93e35f9c70e5175b836a767a35
2 parents c8ac7e6 + 71038a1 commit 1a54c06

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static RPCHelpMan getrawtransaction()
138138
RPCResult::Type::STR, "data", "The serialized, hex-encoded data for 'txid'"
139139
},
140140
RPCResult{"if verbose is set to true",
141+
// When updating this documentation, update `decoderawtransaction` in the same way.
141142
RPCResult::Type::OBJ, "", "",
142143
{
143144
{RPCResult::Type::BOOL, "in_active_chain", /*optional=*/true, "Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)"},
@@ -153,31 +154,32 @@ static RPCHelpMan getrawtransaction()
153154
{
154155
{RPCResult::Type::OBJ, "", "",
155156
{
156-
{RPCResult::Type::STR_HEX, "txid", "The transaction id"},
157-
{RPCResult::Type::NUM, "vout", "The output number"},
158-
{RPCResult::Type::OBJ, "scriptSig", "The script",
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)",
159161
{
160162
{RPCResult::Type::STR, "asm", "asm"},
161163
{RPCResult::Type::STR_HEX, "hex", "hex"},
162164
}},
163-
{RPCResult::Type::NUM, "sequence", "The script sequence number"},
164165
{RPCResult::Type::ARR, "txinwitness", /*optional=*/true, "",
165166
{
166167
{RPCResult::Type::STR_HEX, "hex", "hex-encoded witness data (if any)"},
167168
}},
169+
{RPCResult::Type::NUM, "sequence", "The script sequence number"},
168170
}},
169171
}},
170172
{RPCResult::Type::ARR, "vout", "",
171173
{
172174
{RPCResult::Type::OBJ, "", "",
173175
{
174-
{RPCResult::Type::NUM, "value", "The value in " + CURRENCY_UNIT},
176+
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
175177
{RPCResult::Type::NUM, "n", "index"},
176178
{RPCResult::Type::OBJ, "scriptPubKey", "",
177179
{
178180
{RPCResult::Type::STR, "asm", "the asm"},
179181
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
180-
{RPCResult::Type::STR, "hex", "the hex"},
182+
{RPCResult::Type::STR_HEX, "hex", "the hex"},
181183
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
182184
{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
183185
}},
@@ -321,21 +323,22 @@ static RPCHelpMan decoderawtransaction()
321323
RPCResult{
322324
RPCResult::Type::OBJ, "", "",
323325
{
326+
// When updating this documentation, update `getrawtransaction` in the same way.
324327
{RPCResult::Type::STR_HEX, "txid", "The transaction id"},
325328
{RPCResult::Type::STR_HEX, "hash", "The transaction hash (differs from txid for witness transactions)"},
326-
{RPCResult::Type::NUM, "size", "The transaction size"},
329+
{RPCResult::Type::NUM, "size", "The serialized transaction size"},
327330
{RPCResult::Type::NUM, "vsize", "The virtual transaction size (differs from size for witness transactions)"},
328-
{RPCResult::Type::NUM, "weight", "The transaction's weight (between vsize*4 - 3 and vsize*4)"},
331+
{RPCResult::Type::NUM, "weight", "The transaction's weight (between vsize*4-3 and vsize*4)"},
329332
{RPCResult::Type::NUM, "version", "The version"},
330333
{RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
331334
{RPCResult::Type::ARR, "vin", "",
332335
{
333336
{RPCResult::Type::OBJ, "", "",
334337
{
335-
{RPCResult::Type::STR_HEX, "coinbase", /*optional=*/true, ""},
336-
{RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id"},
337-
{RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number"},
338-
{RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script",
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)",
339342
{
340343
{RPCResult::Type::STR, "asm", "asm"},
341344
{RPCResult::Type::STR_HEX, "hex", "hex"},
@@ -351,7 +354,7 @@ static RPCHelpMan decoderawtransaction()
351354
{
352355
{RPCResult::Type::OBJ, "", "",
353356
{
354-
{RPCResult::Type::NUM, "value", "The value in " + CURRENCY_UNIT},
357+
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
355358
{RPCResult::Type::NUM, "n", "index"},
356359
{RPCResult::Type::OBJ, "scriptPubKey", "",
357360
{

0 commit comments

Comments
 (0)