mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-23 17:02:21 +02:00
Merge bitcoin/bitcoin#22918: rpc: Add level 3 verbosity to getblock RPC call (#21245 modified)
5c34507ecb
core_write: Rename calculate_fee to have_undo for clarity (fyquah)8edf6204a8
release-notes: Add release note about getblock verbosity level 3. (fyquah)459104b2aa
rest: Add test for prevout fields in getblock (fyquah)4330af6f72
rpc: Add test for level 3 verbosity getblock rpc call. (fyquah)51dbc167e9
rpc: Add level 3 verbosity to getblock RPC call. (fyquah)3cc95345ca
rpc: Replace boolean argument for tx details with enum class. (fyquah) Pull request description: Author of #21245 expressed [time issues](https://github.com/bitcoin/bitcoin/pull/21245#issuecomment-902332088) in the original PR. Given that #21245 has received a lot of review*, I have decided to open this new pull request with [modifications required to get ACK from luke-jr ](https://github.com/bitcoin/bitcoin/pull/21245#issuecomment-905150806) and a few nits of mine. ### Original PR description > Display the prevout in transaction inputs when calling getblock level 3 verbosity. This PR affects the existing `/rest/block` API by adding a `prevout` fields to tx inputs. This is mentioned in the change to the release notes. > > I added some functional tests that > > * checks that the RPC call still works when TxUndo can't be found > > * Doesn't display the "value" or "scriptPubKey" of the previous output when at a lower verbosity level > > > This "completes" the issue #18771 ### Possible improvements *b0bf4f255f
- I can include even this commit to this PR if deemed useful or I can leave it for a follow-up PR. See https://github.com/bitcoin/bitcoin/pull/21245#issuecomment-894853784 for more context. ### Examples Examples of the `getblock` output with various verbose levels. Note that `000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5` contains only 2 transactions. #### Verbose level 0 ```bash ./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 0 ``` ##### Verbose level 1 ```bash ./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 1 ``` ##### Verbose level 2 ```bash ./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 2 ``` ##### Verbose level 3 ```bash ./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 3 ``` #### REST ```bash curl -H "content-type:text/plain;" http://127.0.0.1:18332/rest/block/000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5.json ``` <sub>* ... and my everyday obsessive checking of my email inbox whether the PR moves forward.</sub> Edit laanwj: Removed at symbol from message, and large example output to prevent it from all ending up in the commit message. ACKs for top commit: 0xB10C: ACK5c34507ecb
meshcollider: utACK5c34507ecb
theStack: ACK5c34507ecb
👘 promag: Concept ACK5c34507ecb
Tree-SHA512: bbff120d8fd76e617b723b102b0c606e0d8eb27f21c631d5f4cdab0892137c4bc7c65b1df144993405f942c91be47a26e80480102af55bff22621c19f518aea3
This commit is contained in:
@@ -262,7 +262,7 @@ static bool rest_headers(const std::any& context,
|
||||
static bool rest_block(const std::any& context,
|
||||
HTTPRequest* req,
|
||||
const std::string& strURIPart,
|
||||
bool showTxDetails)
|
||||
TxVerbosity tx_verbosity)
|
||||
{
|
||||
if (!CheckWarmup(req))
|
||||
return false;
|
||||
@@ -314,7 +314,7 @@ static bool rest_block(const std::any& context,
|
||||
}
|
||||
|
||||
case RetFormat::JSON: {
|
||||
UniValue objBlock = blockToJSON(block, tip, pblockindex, showTxDetails);
|
||||
UniValue objBlock = blockToJSON(block, tip, pblockindex, tx_verbosity);
|
||||
std::string strJSON = objBlock.write() + "\n";
|
||||
req->WriteHeader("Content-Type", "application/json");
|
||||
req->WriteReply(HTTP_OK, strJSON);
|
||||
@@ -329,12 +329,12 @@ static bool rest_block(const std::any& context,
|
||||
|
||||
static bool rest_block_extended(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
|
||||
{
|
||||
return rest_block(context, req, strURIPart, true);
|
||||
return rest_block(context, req, strURIPart, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
|
||||
}
|
||||
|
||||
static bool rest_block_notxdetails(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
|
||||
{
|
||||
return rest_block(context, req, strURIPart, false);
|
||||
return rest_block(context, req, strURIPart, TxVerbosity::SHOW_TXID);
|
||||
}
|
||||
|
||||
// A bit of a hack - dependency on a function defined in rpc/blockchain.cpp
|
||||
|
Reference in New Issue
Block a user