Skip to content

Commit 66be456

Browse files
committed
Merge bitcoin/bitcoin#23320: rpc: Add RPC help for getblock verbosity level 3
059f88b Add RPC help for getblock verbosity level 3 (Kiminuo) 1bdd5f6 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 059f88b Tree-SHA512: f27d53ac34b93a304ef5668701ed2b5c986a926bc8ad0df4de89695fc9e1df26acb008611451319ea897658acd9c56c6a0555d60359960c9cd28238ebefa2d50
2 parents 2211fe7 + 059f88b commit 66be456

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

doc/release-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Updated RPCs
9797
`gettransaction verbose=true` and REST endpoints `/rest/tx`, `/rest/getutxos`,
9898
`/rest/block` no longer return the `addresses` and `reqSigs` fields, which
9999
were previously deprecated in 22.0. (#22650)
100-
- The `getblock` RPC command now supports verbose level 3 containing transaction inputs
100+
- The `getblock` RPC command now supports verbosity level 3 containing transaction inputs'
101101
`prevout` information. The existing `/rest/block/` REST endpoint is modified to contain
102102
this information too. Every `vin` field will contain an additional `prevout` subfield
103103
describing the spent output. `prevout` contains the following keys:

src/core_write.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,17 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
208208
const CTxOut& prev_txout = prev_coin.out;
209209

210210
amt_total_in += prev_txout.nValue;
211-
switch (verbosity) {
212-
case TxVerbosity::SHOW_TXID:
213-
case TxVerbosity::SHOW_DETAILS:
214-
break;
215211

216-
case TxVerbosity::SHOW_DETAILS_AND_PREVOUT:
217-
UniValue o_script_pub_key(UniValue::VOBJ);
218-
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* includeHex */ true);
212+
if (verbosity == TxVerbosity::SHOW_DETAILS_AND_PREVOUT) {
213+
UniValue o_script_pub_key(UniValue::VOBJ);
214+
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /*include_hex=*/ true);
219215

220-
UniValue p(UniValue::VOBJ);
221-
p.pushKV("generated", bool(prev_coin.fCoinBase));
222-
p.pushKV("height", uint64_t(prev_coin.nHeight));
223-
p.pushKV("value", ValueFromAmount(prev_txout.nValue));
224-
p.pushKV("scriptPubKey", o_script_pub_key);
225-
in.pushKV("prevout", p);
226-
break;
216+
UniValue p(UniValue::VOBJ);
217+
p.pushKV("generated", bool(prev_coin.fCoinBase));
218+
p.pushKV("height", uint64_t(prev_coin.nHeight));
219+
p.pushKV("value", ValueFromAmount(prev_txout.nValue));
220+
p.pushKV("scriptPubKey", o_script_pub_key);
221+
in.pushKV("prevout", p);
227222
}
228223
}
229224
in.pushKV("sequence", (int64_t)txin.nSequence);

src/rpc/blockchain.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIn
185185
TxToUniv(*tx, uint256(), objTx, true, RPCSerializationFlags(), txundo, verbosity);
186186
txs.push_back(objTx);
187187
}
188+
break;
188189
}
189190

190191
result.pushKV("tx", txs);
@@ -967,7 +968,7 @@ static RPCHelpMan getblock()
967968
"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",
968969
{
969970
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
970-
{"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"},
971+
{"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"},
971972
},
972973
{
973974
RPCResult{"for verbosity = 0",
@@ -1009,6 +1010,37 @@ static RPCHelpMan getblock()
10091010
}},
10101011
}},
10111012
}},
1013+
RPCResult{"for verbosity = 3",
1014+
RPCResult::Type::OBJ, "", "",
1015+
{
1016+
{RPCResult::Type::ELISION, "", "Same output as verbosity = 2"},
1017+
{RPCResult::Type::ARR, "tx", "",
1018+
{
1019+
{RPCResult::Type::OBJ, "", "",
1020+
{
1021+
{RPCResult::Type::ARR, "vin", "",
1022+
{
1023+
{RPCResult::Type::OBJ, "", "",
1024+
{
1025+
{RPCResult::Type::ELISION, "", "The same output as verbosity = 2"},
1026+
{RPCResult::Type::OBJ, "prevout", "(Only if undo information is available)",
1027+
{
1028+
{RPCResult::Type::BOOL, "generated", "Coinbase or not"},
1029+
{RPCResult::Type::NUM, "height", "The height of the prevout"},
1030+
{RPCResult::Type::NUM, "value", "The value in " + CURRENCY_UNIT},
1031+
{RPCResult::Type::OBJ, "scriptPubKey", "",
1032+
{
1033+
{RPCResult::Type::STR, "asm", "The asm"},
1034+
{RPCResult::Type::STR, "hex", "The hex"},
1035+
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
1036+
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
1037+
}},
1038+
}},
1039+
}},
1040+
}},
1041+
}},
1042+
}},
1043+
}},
10121044
},
10131045
RPCExamples{
10141046
HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")

0 commit comments

Comments
 (0)