Skip to content

Commit ea107ac

Browse files
laanwjknst
authored andcommitted
Merge bitcoin/bitcoin#23320: rpc: Add RPC help for getblock verbosity level 3
059f88b6a97b7a3ae1f033885e40ac01f91e6d60 Add RPC help for getblock verbosity level 3 (Kiminuo) 1bdd5f63229ebf28c24a8656f486ed8a6c8b3787 Address review comments from #22918 (Kiminuo) Pull request description: This is a follow-up PR to #22918 which addresses review comments (first commit). The second commit adds missing RPC help for verbosity level 3. ACKs for top commit: pg156: ACK bitcoin/bitcoin@059f88b laanwj: re-ACK 059f88b6a97b7a3ae1f033885e40ac01f91e6d60 Tree-SHA512: f27d53ac34b93a304ef5668701ed2b5c986a926bc8ad0df4de89695fc9e1df26acb008611451319ea897658acd9c56c6a0555d60359960c9cd28238ebefa2d50
1 parent 6df2fae commit ea107ac

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

doc/release-notes-22918.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Updated RPCs
22

3-
- The `getblock` RPC command now supports verbose level 3 containing transaction inputs
3+
- The `getblock` RPC command now supports verbosity level 3 containing transaction inputs
44
`prevout` information. The existing `/rest/block/` REST endpoint is modified to contain
55
this information too. Every `vin` field will contain an additional `prevout` subfield
66
describing the spent output. `prevout` contains the following keys:

src/core_write.cpp

+11-16
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,17 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
226226
const CTxOut& prev_txout = prev_coin.out;
227227

228228
amt_total_in += prev_txout.nValue;
229-
switch (verbosity) {
230-
case TxVerbosity::SHOW_TXID:
231-
case TxVerbosity::SHOW_DETAILS:
232-
break;
233-
234-
case TxVerbosity::SHOW_DETAILS_AND_PREVOUT:
235-
UniValue o_script_pub_key(UniValue::VOBJ);
236-
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* includeHex */ true, /*include_address=*/true);
237-
238-
UniValue p(UniValue::VOBJ);
239-
p.pushKV("generated", bool(prev_coin.fCoinBase));
240-
p.pushKV("height", uint64_t(prev_coin.nHeight));
241-
p.pushKV("value", ValueFromAmount(prev_txout.nValue));
242-
p.pushKV("scriptPubKey", o_script_pub_key);
243-
in.pushKV("prevout", p);
244-
break;
229+
230+
if (verbosity == TxVerbosity::SHOW_DETAILS_AND_PREVOUT) {
231+
UniValue o_script_pub_key(UniValue::VOBJ);
232+
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /*include_hex=*/ true, /*include_address=*/true);
233+
234+
UniValue p(UniValue::VOBJ);
235+
p.pushKV("generated", bool(prev_coin.fCoinBase));
236+
p.pushKV("height", uint64_t(prev_coin.nHeight));
237+
p.pushKV("value", ValueFromAmount(prev_txout.nValue));
238+
p.pushKV("scriptPubKey", o_script_pub_key);
239+
in.pushKV("prevout", p);
245240
}
246241
}
247242
in.pushKV("sequence", (int64_t)txin.nSequence);

src/rpc/blockchain.cpp

+33-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn
183183
objTx.pushKV("instantlock_internal", fLocked);
184184
txs.push_back(objTx);
185185
}
186+
break;
186187
}
187188

188189
result.pushKV("tx", txs);
@@ -881,7 +882,7 @@ static RPCHelpMan getblock()
881882
"If verbosity is 3, returns an Object with information about block <hash> and information about each transaction, including prevout information for inputs (only for unpruned blocks in the current best chain).\n",
882883
{
883884
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
884-
{"verbosity|verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data"},
885+
{"verbosity|verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a JSON object, 2 for JSON object with transaction data, and 3 for JSON object with transaction data including prevout information for inputs"},
885886
},
886887
{
887888
RPCResult{"for verbosity = 0",
@@ -929,6 +930,37 @@ static RPCHelpMan getblock()
929930
}},
930931
}},
931932
}},
933+
RPCResult{"for verbosity = 3",
934+
RPCResult::Type::OBJ, "", "",
935+
{
936+
{RPCResult::Type::ELISION, "", "Same output as verbosity = 2"},
937+
{RPCResult::Type::ARR, "tx", "",
938+
{
939+
{RPCResult::Type::OBJ, "", "",
940+
{
941+
{RPCResult::Type::ARR, "vin", "",
942+
{
943+
{RPCResult::Type::OBJ, "", "",
944+
{
945+
{RPCResult::Type::ELISION, "", "The same output as verbosity = 2"},
946+
{RPCResult::Type::OBJ, "prevout", "(Only if undo information is available)",
947+
{
948+
{RPCResult::Type::BOOL, "generated", "Coinbase or not"},
949+
{RPCResult::Type::NUM, "height", "The height of the prevout"},
950+
{RPCResult::Type::NUM, "value", "The value in " + CURRENCY_UNIT},
951+
{RPCResult::Type::OBJ, "scriptPubKey", "",
952+
{
953+
{RPCResult::Type::STR, "asm", "The asm"},
954+
{RPCResult::Type::STR, "hex", "The hex"},
955+
{RPCResult::Type::STR, "address", /*optional=*/ true, "The Dash address (only if a well-defined address exists)"},
956+
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
957+
}},
958+
}},
959+
}},
960+
}},
961+
}},
962+
}},
963+
}},
932964
},
933965
RPCExamples{
934966
HelpExampleCli("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"")

0 commit comments

Comments
 (0)