rpc: Add level 3 verbosity to getblock RPC call. #21245

pull fyquah wants to merge 6 commits into bitcoin:master from fyquah:verbosity-level-3-getblock changing 9 files +149 −48
  1. fyquah commented at 12:17 pm on February 20, 2021: contributor

    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

  2. DrahtBot added the label RPC/REST/ZMQ on Feb 20, 2021
  3. DrahtBot commented at 2:23 pm on February 20, 2021: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #22689 (rpc: deprecate top-level fee fields in getmempool RPCs by josibake)
    • #22650 (Remove -deprecatedrpc=addresses flag and corresponding code/logic by mjdietzx)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. fyquah force-pushed on Feb 20, 2021
  5. 0xB10C commented at 9:21 pm on February 23, 2021: member
    Concept ACK. Thanks for picking this up! Will have a closer look and test this soon.
  6. in src/core_write.cpp:246 in 6eede79af1 outdated
    222@@ -223,6 +223,17 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
    223             const CTxOut& prev_txout = txundo->vprevout[i].out;
    224             amt_total_in += prev_txout.nValue;
    225         }
    226+        if (display_prev_out && (nullptr != txundo)) {
    227+            const CTxOut& prev_txout = txundo->vprevout[i].out;
    228+            UniValue p(UniValue::VOBJ);
    229+            UniValue o_script_pub_key(UniValue::VOBJ);
    230+
    


    luke-jr commented at 3:15 am on February 24, 2021:
    Where did “height” and “generated” go?

    fyquah commented at 8:37 pm on February 24, 2021:
    Added it back

    kiminuo commented at 7:38 am on July 16, 2021:
    (Please mark as resolved 🙏 )
  7. in src/rpc/blockchain.cpp:184 in 6eede79af1 outdated
    182             // coinbase transaction (i == 0) doesn't have undo data
    183             const CTxUndo* txundo = (have_undo && i) ? &blockUndo.vtxundo.at(i - 1) : nullptr;
    184+            const bool display_prev_out = (verbosity == BlockToJsonVerbosity::TX_DETAILS_AND_PREV_OUT);
    185             UniValue objTx(UniValue::VOBJ);
    186-            TxToUniv(*tx, uint256(), objTx, true, RPCSerializationFlags(), txundo);
    187+            std::cout << display_prev_out  << std::endl;
    


    luke-jr commented at 3:18 am on February 24, 2021:
    no thx

    fyquah commented at 8:36 pm on February 24, 2021:
    Removed, sorry :)

    kiminuo commented at 7:38 am on July 16, 2021:
    (Please mark as resolved 🙏 )
  8. in src/core_io.h:49 in 6eede79af1 outdated
    45@@ -46,6 +46,6 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
    46 std::string SighashToStr(unsigned char sighash_type);
    47 void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
    48 void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
    49-void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
    50+void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr, const bool display_prev_out = false);
    


    luke-jr commented at 3:20 am on February 24, 2021:
    Can we just use BlockToJsonVerbosity here? (Maybe rename it)

    fyquah commented at 8:36 pm on February 24, 2021:
    I renamed it to TxVerbosity, and moved it to src/core_io.h. Feels cleaner than passing bools.

    kiminuo commented at 7:42 am on July 16, 2021:
    (Please mark as resolved 🙏 )

    kiminuo commented at 7:46 am on July 16, 2021:
    (Please mark as resolved 🙏 )
  9. luke-jr changes_requested
  10. fyquah force-pushed on Feb 24, 2021
  11. in src/core_write.cpp:240 in dc684798a0 outdated
    235+                UniValue p(UniValue::VOBJ);
    236+                UniValue o_script_pub_key(UniValue::VOBJ);
    237+
    238+                p.pushKV("value", ValueFromAmount(prev_txout.nValue));
    239+                p.pushKV("height", static_cast<uint64_t>(prev_coin.nHeight));
    240+                p.pushKV("generated", !static_cast<bool>(prev_coin.fCoinBase));
    


    luke-jr commented at 10:16 pm on February 24, 2021:
    0                p.pushKV("height", uint64_t(prev_coin.nHeight));
    1                p.pushKV("generated", bool(prev_coin.fCoinBase));
    

    luke-jr commented at 10:17 pm on February 24, 2021:
    Why did you invert this? That is wrong?

    fyquah commented at 10:20 pm on February 24, 2021:

    i was confused as to what “generated” means. I will change this.

    Why don’t we just call that field “coinbase” though .. ?


    luke-jr commented at 10:42 pm on February 24, 2021:
    The coinbase is the input to the generation transaction (height + 95 bytes arbitrary). The outputs (which are being spent in the input here) are simply generated coins.

    fyquah commented at 10:53 pm on February 24, 2021:
    ah i see. this is fixed now, and i modified the tests to reflect this too.

    kiminuo commented at 7:46 am on July 16, 2021:
    (Please mark as resolved 🙏 )
  12. luke-jr changes_requested
  13. fyquah force-pushed on Feb 24, 2021
  14. in src/core_io.h:27 in 53ea5bd39b outdated
    19@@ -20,6 +20,12 @@ class uint256;
    20 class UniValue;
    21 class CTxUndo;
    22 
    23+enum class TxVerbosity {
    24+    DONT_SHOW_TX_DETAILS,
    25+    TX_DETAILS,
    26+    TX_DETAILS_AND_PREV_OUT
    27+};
    


    0xB10C commented at 2:37 pm on February 26, 2021:

    nit: I find something like this cleaner

    0enum class TxVerbosity {
    1    SHOW_TXID
    2    SHOW_DETAILS,
    3    SHOW_DETAILS_AND_PREV_OUT
    4};
    

    fyquah commented at 4:31 pm on February 26, 2021:

    done, adopted change.

    Question with code review like this, is it preferred to make a separate commit, or squash everything to a single commit ?


    0xB10C commented at 8:56 pm on February 26, 2021:
    For small code review like the above ‘Suggested change’ through the GitHub web interface it’s best to just fix it up locally, squash and then force push IMO. No reason to have it a separate commit (and I personally don’t care about the co-author thing that GitHub does).
  15. 0xB10C approved
  16. 0xB10C commented at 2:58 pm on February 26, 2021: member

    ACK 53ea5bd39bfb1da614c264656536edf954419373

    Code reviewed and tested both the RPC and REST interface on testnet with a few blocks.

  17. fyquah force-pushed on Feb 26, 2021
  18. fyquah force-pushed on Feb 26, 2021
  19. luke-jr commented at 5:08 pm on February 26, 2021: member
    Ideally, this should probably be 3 commits: one changing the bool to the class enum (with 2 values), one adding the new feature, and another adding tests.
  20. fyquah force-pushed on Feb 27, 2021
  21. fyquah commented at 2:20 pm on February 27, 2021: contributor

    Ideally, this should probably be 3 commits

    Done

  22. in src/rpc/blockchain.cpp:167 in cee04d6ef9 outdated
    164     result.pushKV("weight", (int)::GetBlockWeight(block));
    165     UniValue txs(UniValue::VARR);
    166-    if (txDetails) {
    167+
    168+    switch (verbosity) {
    169+      case TxVerbosity::SHOW_TXID:
    


    luke-jr commented at 3:23 pm on February 27, 2021:
    indentation is wrong

    kiminuo commented at 7:39 am on July 16, 2021:
    (Seems done; please mark as resolved 🙏 )
  23. in src/core_io.h:56 in 5710e3f900 outdated
    52@@ -46,6 +53,6 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
    53 std::string SighashToStr(unsigned char sighash_type);
    54 void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
    55 void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
    56-void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
    57+void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_TXID);
    


    luke-jr commented at 3:34 pm on February 27, 2021:
    Nit: This should be added in the later commit

    luke-jr commented at 3:40 pm on February 27, 2021:
    SHOW_DETAILS makes more sense as a default (SHOW_TXID isn’t even supported by this function!)

    kiminuo commented at 7:48 am on July 16, 2021:
    (Please mark as resolved 🙏 )
  24. in src/rpc/blockchain.h:44 in 5710e3f900 outdated
    40@@ -40,7 +41,7 @@ double GetDifficulty(const CBlockIndex* blockindex);
    41 void RPCNotifyBlockChange(const CBlockIndex*);
    42 
    43 /** Block description to JSON */
    44-UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails = false) LOCKS_EXCLUDED(cs_main);
    45+UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, const TxVerbosity verbosity = TxVerbosity::SHOW_TXID) LOCKS_EXCLUDED(cs_main);
    


    luke-jr commented at 3:35 pm on February 27, 2021:
    const doesn’t do anything here, and is missing in the definition.

    kiminuo commented at 7:47 am on July 16, 2021:
    (const was removed; please mark as resolved 🙏 )
  25. in src/rpc/blockchain.cpp:977 in 5710e3f900 outdated
    970@@ -964,7 +971,17 @@ static RPCHelpMan getblock()
    971         return strHex;
    972     }
    973 
    974-    return blockToJSON(block, tip, pblockindex, verbosity >= 2);
    975+    TxVerbosity block_to_json_verbosity;
    976+
    977+    if (verbosity <= 1) {
    978+      block_to_json_verbosity = TxVerbosity::SHOW_TXID;
    


    luke-jr commented at 3:42 pm on February 27, 2021:
    indentation is wrong

    kiminuo commented at 7:49 am on July 16, 2021:
    (Looks correct to me now; please mark as resolved 🙏 )
  26. in src/rpc/blockchain.cpp:975 in 5710e3f900 outdated
    970@@ -964,7 +971,17 @@ static RPCHelpMan getblock()
    971         return strHex;
    972     }
    973 
    974-    return blockToJSON(block, tip, pblockindex, verbosity >= 2);
    975+    TxVerbosity block_to_json_verbosity;
    976+
    


    luke-jr commented at 3:42 pm on February 27, 2021:
    nit: I’d drop the blank link
  27. in src/core_write.cpp:233 in 5710e3f900 outdated
    229+                case TxVerbosity::SHOW_DETAILS:
    230+                    break;
    231+
    232+                case TxVerbosity::SHOW_DETAILS_AND_PREV_OUT:
    233+                    const Coin&   prev_coin  = txundo->vprevout[i];
    234+                    const CTxOut& prev_txout = prev_coin.out;
    


    luke-jr commented at 3:53 pm on February 27, 2021:
    We already have prev_txout above. Move prev_coin up there?

    fyquah commented at 6:23 pm on February 27, 2021:
    Done

    luke-jr commented at 8:10 pm on March 1, 2021:
    This is still here…

    kiminuo commented at 7:56 am on July 16, 2021:
    Is this still relevant?
  28. in src/rest.cpp:298 in 5710e3f900 outdated
    294@@ -295,12 +295,12 @@ static bool rest_block(HTTPRequest* req,
    295 
    296 static bool rest_block_extended(const util::Ref& context, HTTPRequest* req, const std::string& strURIPart)
    297 {
    298-    return rest_block(req, strURIPart, true);
    299+    return rest_block(req, strURIPart, TxVerbosity::SHOW_DETAILS_AND_PREV_OUT);
    


    luke-jr commented at 3:59 pm on February 27, 2021:
    This could use a test

    fyquah commented at 6:22 pm on February 27, 2021:
    I added a test in 37f2c4e9e09d586e1c7d38332dc7fe7864245b97

    kiminuo commented at 7:56 pm on May 11, 2021:

    Should a note be added to the PR description to make sure it’s clear that you modify an existing REST endpoint behavior (even though you just add more information)?

    I’m not sure whether this is something that is supposed to be mentioned in release notes too.


    fyquah commented at 3:58 pm on July 16, 2021:
    good point. I added a commit with changes to the release notes, please have a look!
  29. luke-jr changes_requested
  30. fyquah force-pushed on Feb 27, 2021
  31. fyquah force-pushed on Feb 27, 2021
  32. fyquah force-pushed on Feb 27, 2021
  33. fyquah force-pushed on Feb 27, 2021
  34. fyquah force-pushed on Feb 27, 2021
  35. fyquah force-pushed on Feb 27, 2021
  36. fyquah force-pushed on Feb 27, 2021
  37. fyquah force-pushed on Mar 1, 2021
  38. fyquah force-pushed on Mar 1, 2021
  39. fyquah force-pushed on Mar 1, 2021
  40. DrahtBot added the label Needs rebase on Mar 1, 2021
  41. in src/core_io.h:55 in 4aaebc155d outdated
    51@@ -46,6 +52,6 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
    52 std::string SighashToStr(unsigned char sighash_type);
    53 void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
    54 void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
    55-void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
    56+void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS);
    


    luke-jr commented at 7:12 pm on March 1, 2021:
    This is one commit too early (causing a build failure in that commit)

    fyquah commented at 8:07 pm on March 1, 2021:
    Fixed. I moved the change in src/core_write.cpp from the previous commit to this one.
  42. fyquah force-pushed on Mar 1, 2021
  43. fyquah force-pushed on Mar 1, 2021
  44. luke-jr changes_requested
  45. luke-jr commented at 8:16 pm on March 1, 2021: member

    Needs update for getblock docs

    0"If verbosity is 3, returns an Object with information about block <hash> and information about each transaction, including prevout information for inputs (only for blocks in the current best chain).\n",
    
  46. fyquah force-pushed on Mar 1, 2021
  47. fyquah force-pushed on Mar 1, 2021
  48. fyquah commented at 8:40 pm on March 1, 2021: contributor

    Needs update for getblock docs

    0"If verbosity is 3, returns an Object with information about block <hash> and information about each transaction, including prevout information for inputs (only for blocks in the current best chain).\n",
    

    Done, I added to the commit that implements this feature

  49. luke-jr approved
  50. luke-jr commented at 8:46 pm on March 1, 2021: member
    utACK bce09fe7429d8a007a3a96cd0cea28d5535f35cf
  51. luke-jr commented at 8:48 pm on March 1, 2021: member
    (Could still be cleaner with the duplicate line removed #21245 (review))
  52. fyquah force-pushed on Mar 1, 2021
  53. fyquah commented at 8:53 pm on March 1, 2021: contributor

    (Could still be cleaner with the duplicate line removed #21245 (comment))

    should be fixed this time ..

  54. DrahtBot removed the label Needs rebase on Mar 1, 2021
  55. luke-jr approved
  56. luke-jr commented at 11:56 pm on March 1, 2021: member
    utACK 7fc316e2c9f83cdab1b3b6cbd780c8d498f0bbb9
  57. fanquake referenced this in commit 72e6979b31 on Mar 2, 2021
  58. 0xB10C commented at 5:15 pm on March 3, 2021: member

    ACK 7fc316e2c9f83cdab1b3b6cbd780c8d498f0bbb9.

    • tested that both the RPC and REST interface have a new prevout field in the vin’s
    • tested that the contents of the getblock RPC and /rest/block/<hash>.json are the same by piping them into jq and diffing the results
    • tested that a random vin can be found on chain as a previous output and the height, value, address, type and scriptPubkey.hex fields are correct with, for example, this bash helper:
    0# make sure to play around with different block hashes and transaction indices (here 50) 
    1vin0=$(curl localhost:8332/rest/block/0000000000000000000c07a5ac516dc2a766da3bd1f85ec92090ba497188fd1b.json | jq .tx[50].vin[0])
    2vin0txid=$(echo $vin0 | jq .txid -r)
    3vin0nout=$(echo $vin0 | jq .vout)
    4vin0height=$(echo $vin0 | jq .prevout.height)
    5vin0blockhash=$(bitcoin-cli getblockhash $vin0height)
    6
    7echo $vin0 | jq
    8echo ""
    9bitcoin-cli getrawtransaction $vin0txid true $vin0blockhash | jq .vout[$vin0nout]
    

    BlockToJsonVerbose and BlockToJsonVerboseWrite (JSON serialization from #21170) benchmarks:

    master @ cabe63759ce890a7d39d72f7b8046195b0edb421

    ns/op op/s err% ins/op cyc/op IPC bra/op miss% total benchmark
    71,551,280.00 13.98 0.1% 561,473,856.00 136,734,366.00 4.106 105,739,596.00 0.4% 0.79 BlockToJsonVerbose
    24,850,266.00 40.24 0.4% 231,100,742.00 49,070,928.00 4.710 43,476,242.00 0.3% 0.29 BlockToJsonVerboseWrite

    this PR @ 7fc316e2c9f83cdab1b3b6cbd780c8d498f0bbb9

    ns/op op/s err% ins/op cyc/op IPC bra/op miss% total benchmark
    72,740,207.00 13.75 0.5% 561,708,569.00 138,848,957.00 4.045 105,777,166.00 0.4% 0.80 BlockToJsonVerbose
    24,838,117.00 40.26 0.6% 231,115,449.00 49,100,061.00 4.707 43,478,330.00 0.3% 0.29 BlockToJsonVerboseWrite
  59. DrahtBot added the label Needs rebase on Mar 29, 2021
  60. in src/core_io.h:26 in 7fc316e2c9 outdated
    19@@ -20,6 +20,12 @@ class uint256;
    20 class UniValue;
    21 class CTxUndo;
    22 
    23+enum class TxVerbosity {
    24+    SHOW_TXID,
    25+    SHOW_DETAILS,
    26+    SHOW_DETAILS_AND_PREV_OUT
    


    kiminuo commented at 7:28 pm on May 11, 2021:
    Nit: It seems that people mostly write prevout as one word. Would it make sense to you to use SHOW_DETAILS_AND_PREVOUT?

    kiminuo commented at 7:36 am on July 16, 2021:
    (Done; Please mark as resolved 🙏 )
  61. in src/core_write.cpp:253 in 7fc316e2c9 outdated
    238+                    p.pushKV("height", uint64_t(prev_coin.nHeight));
    239+                    p.pushKV("generated", bool(prev_coin.fCoinBase));
    240+                    ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, true);
    241+                    p.pushKV("scriptPubKey", o_script_pub_key);
    242+                    in.pushKV("prevout", p);
    243+                    break;
    


    kiminuo commented at 7:37 pm on May 11, 2021:

    Nit: What about this way:

    0                    UniValue o_script_pub_key(UniValue::VOBJ);
    1                    ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* fIncludeHex */ true);
    2
    3                    UniValue p(UniValue::VOBJ);
    4                    p.pushKV("generated", bool(prev_coin.fCoinBase));
    5                    p.pushKV("height", uint64_t(prev_coin.nHeight));
    6                    p.pushKV("value", ValueFromAmount(prev_txout.nValue));
    7                    p.pushKV("scriptPubKey", o_script_pub_key);
    8                    in.pushKV("prevout", p);
    9                    break;
    

    I find this order of JSON properties more natural as I think it’s more in line with how JSON properties are ordered in other places. I may be wrong here. Functionally it’s the same. Anyway, it’s just a suggestion. Feel free to ignore it.

  62. in src/rpc/blockchain.cpp:940 in 7fc316e2c9 outdated
    885@@ -879,7 +886,8 @@ static RPCHelpMan getblock()
    886     return RPCHelpMan{"getblock",
    887                 "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
    888                 "If verbosity is 1, returns an Object with information about block <hash>.\n"
    889-                "If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n",
    890+                "If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n"
    


    kiminuo commented at 7:41 pm on May 11, 2021:

    I’m not sure if there is a reason for the trailing space:

    0                "If verbosity is 2, returns an Object with information about block <hash> and information about each transaction.\n"
    

    Is there?


    fyquah commented at 11:41 pm on July 15, 2021:
    I removed the trailing space.

    kiminuo commented at 7:35 am on July 16, 2021:
    (Please mark as resolved 🙏 )
  63. in src/rpc/blockchain.cpp:1031 in 7fc316e2c9 outdated
    971@@ -964,7 +972,16 @@ static RPCHelpMan getblock()
    972         return strHex;
    973     }
    974 
    975-    return blockToJSON(block, tip, pblockindex, verbosity >= 2);
    976+    TxVerbosity block_to_json_verbosity;
    977+    if (verbosity <= 1) {
    978+        block_to_json_verbosity = TxVerbosity::SHOW_TXID;
    979+    } else if (verbosity <= 2) {
    


    kiminuo commented at 7:42 pm on May 11, 2021:
    I would personally go with == instead of <= here.

    fyquah commented at 11:40 pm on July 15, 2021:
    Done

    kiminuo commented at 7:31 am on July 16, 2021:

    Please mark this as resolved. 🙏

    (For some reason I can’t do it and it’s harder for me to track what is done, what is not done and what was rejected as a suggestion.)

  64. in src/rpc/blockchain.cpp:1029 in 7fc316e2c9 outdated
    971@@ -964,7 +972,16 @@ static RPCHelpMan getblock()
    972         return strHex;
    973     }
    974 
    975-    return blockToJSON(block, tip, pblockindex, verbosity >= 2);
    976+    TxVerbosity block_to_json_verbosity;
    977+    if (verbosity <= 1) {
    


    kiminuo commented at 7:44 pm on May 11, 2021:

    I would suggest:

    0    if (verbosity == 1) {
    

    as it’s easier to understand here.


    kiminuo commented at 7:32 am on July 16, 2021:
    (Please mark as resolved 🙏 )
  65. in src/rpc/blockchain.h:42 in 7fc316e2c9 outdated
    40@@ -40,7 +41,7 @@ double GetDifficulty(const CBlockIndex* blockindex);
    41 void RPCNotifyBlockChange(const CBlockIndex*);
    42 
    43 /** Block description to JSON */
    44-UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails = false) LOCKS_EXCLUDED(cs_main);
    45+UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, TxVerbosity verbosity = TxVerbosity::SHOW_TXID) LOCKS_EXCLUDED(cs_main);
    


    kiminuo commented at 7:49 pm on May 11, 2021:
    It seems to me that the TxVerbosity::SHOW_TXID default value is not actually needed. Would it make sense to not having a default value here?

    fyquah commented at 11:49 pm on July 15, 2021:
    make sense, i removed it.

    kiminuo commented at 7:33 am on July 16, 2021:
    (Please mark as resolved 🙏 )
  66. in src/core_write.cpp:238 in 7fc316e2c9 outdated
    219@@ -220,8 +220,27 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
    220             in.pushKV("txinwitness", txinwitness);
    221         }
    222         if (calculate_fee) {
    223-            const CTxOut& prev_txout = txundo->vprevout[i].out;
    224+            const Coin&   prev_coin  = txundo->vprevout[i];
    225+            const CTxOut& prev_txout = prev_coin.out;
    226+
    227             amt_total_in += prev_txout.nValue;
    228+            switch (verbosity) {
    


    kiminuo commented at 8:01 pm on May 11, 2021:
    Personally, I would use simple if here as it is shorter. Or is there any specific reason to use switch?

    fyquah commented at 11:30 pm on July 15, 2021:
    personally think it’s clearer to comprehend, compared to something like verbosity == TxVerbosity::SHOW_TXID || verbosity == TxVerbosity::SHOW_DETAILS)

    kiminuo commented at 7:21 am on July 16, 2021:

    But here it would be if (verbosity == TxVerbosity::SHOW_DETAILS_AND_PREVOUT) { /* compute something */ }. Seems very straightforward and Bitcoin Core does not use switches instead of simple if statements by default.

    Obviously, this is rather a nit. So I don’t want to waste your time with this. Feel free to resolve this suggestion if you are happy with the code as it is.

  67. in src/core_write.cpp:234 in 7fc316e2c9 outdated
    219@@ -220,8 +220,27 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
    220             in.pushKV("txinwitness", txinwitness);
    221         }
    222         if (calculate_fee) {
    223-            const CTxOut& prev_txout = txundo->vprevout[i].out;
    224+            const Coin&   prev_coin  = txundo->vprevout[i];
    


    kiminuo commented at 8:46 pm on May 11, 2021:

    This is suggested by clang formatter:

    0            const Coin& prev_coin = txundo->vprevout[i];
    

    kiminuo commented at 7:34 am on July 16, 2021:
    (Please mark as resolved 🙏 )
  68. kiminuo commented at 8:48 pm on May 11, 2021: contributor
    Some nitpicking from my side :)
  69. PulpCattel referenced this in commit 0d2f6b1d16 on May 12, 2021
  70. in test/functional/rpc_blockchain.py:400 in 7fc316e2c9 outdated
    394@@ -395,17 +395,55 @@ def _test_getblock(self):
    395         miniwallet.send_self_transfer(fee_rate=fee_per_kb, from_node=node)
    396         blockhash = node.generate(1)[0]
    397 
    398+        def check_fee_not_in_block(verbosity):
    


    kiminuo commented at 7:55 am on May 16, 2021:
    Maybe the function can be called assert_fee_not_in_block.
  71. in test/functional/rpc_blockchain.py:435 in 7fc316e2c9 outdated
    430+                    assert "prevout" not in vin
    431+
    432         self.log.info("Test that getblock with verbosity 1 doesn't include fee")
    433-        block = node.getblock(blockhash, 1)
    434-        assert 'fee' not in block['tx'][1]
    435+        check_fee_not_in_block(1)
    


    kiminuo commented at 8:55 am on May 16, 2021:
    It would be great to introduce a constant for this value (similar to this ones https://github.com/bitcoin/bitcoin/pull/21245/files#diff-0b117a50ea1a4d205e8b5268d01f06b100c6d75ccc743628774b1f656077a0c3R23). I think that they could be re-used and code would be self-describing.

    fyquah commented at 3:29 pm on July 16, 2021:
    i disagree – i think what we are asserting here is that level 1 verbosity does not have fee in block, level 2 & 3 does etc.. a constant for the value would probably make the test intention less clear.
  72. in test/functional/rpc_blockchain.py:410 in 7fc316e2c9 outdated
    403+            block = node.getblock(blockhash, verbosity)
    404+            tx = block['tx'][1]
    405+            assert 'fee' in tx
    406+            assert_equal(tx['fee'], tx['vsize'] * fee_per_byte)
    407+
    408+        def check_vin_contains_prevout(verbosity):
    


    kiminuo commented at 8:58 am on May 16, 2021:

    The parameter is always 3 so it seems unnecessary.

    The function does more than checking that prevouts are present. Maybe {verify|assert}_level3_block?


    fyquah commented at 3:33 pm on July 16, 2021:
    I renamed the prefix to assert. The pattern i was going for was: assert_<some-expected-behaviour>(verbosity_level), which is consistent with the other assertion helpers in this test. I think i’d prefer leaving it as such.

    kiminuo commented at 8:40 pm on July 16, 2021:
    ok
  73. luke-jr referenced this in commit e2cff844b7 on Jun 27, 2021
  74. luke-jr referenced this in commit 09bf0af392 on Jun 27, 2021
  75. luke-jr referenced this in commit 3f91819d94 on Jun 27, 2021
  76. theStack commented at 8:49 pm on July 14, 2021: member
    Concept ACK Happy to review after rebase
  77. kiminuo commented at 9:14 pm on July 15, 2021: contributor

    I have rebased the PR here: #22463. In my testing each individual commit can be compiled and make check passed for me. If you like the work, please just use it. (No guaratees!)

    I plan to address review comments from this PR in #22463 in coming days, unless somebody beats me to it :)

    Hopefully this effort will help move the needle.

  78. fyquah force-pushed on Jul 15, 2021
  79. fyquah commented at 11:27 pm on July 15, 2021: contributor
    sorry for the delay getting back to this. I just rebased – it ought to be passing tests, i’ll take a look at some of the reviews..
  80. fyquah force-pushed on Jul 15, 2021
  81. fyquah force-pushed on Jul 15, 2021
  82. fyquah force-pushed on Jul 15, 2021
  83. fyquah commented at 11:52 pm on July 15, 2021: contributor
    @kiminuo all your comments should been addressed now.
  84. DrahtBot removed the label Needs rebase on Jul 16, 2021
  85. kiminuo commented at 7:23 am on July 16, 2021: contributor

    @kiminuo all your comments should been addressed now.

    Thank you! There are still open review comments from my side. I’m not sure if you have seen them or not. Mostly nits though.

    Edit: For example these ones:

  86. in src/core_write.cpp:250 in dac9c0cf96 outdated
    246+                    UniValue o_script_pub_key(UniValue::VOBJ);
    247+
    248+                    p.pushKV("value", ValueFromAmount(prev_txout.nValue));
    249+                    p.pushKV("height", uint64_t(prev_coin.nHeight));
    250+                    p.pushKV("generated", bool(prev_coin.fCoinBase));
    251+                    ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, true, true);
    


    kiminuo commented at 7:44 am on July 16, 2021:

    The convention seems to be:

    0                    ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* fIncludeHex */ true, /* include_addresses */ true);
    
  87. fyquah force-pushed on Jul 16, 2021
  88. fyquah force-pushed on Jul 16, 2021
  89. fyquah force-pushed on Jul 16, 2021
  90. fyquah commented at 3:59 pm on July 16, 2021: contributor
    @kiminuo i think they should all be addressed now ..
  91. kiminuo commented at 7:35 pm on July 16, 2021: contributor

    @fyquah Thanks!

    Is this Luke’s comment addressed: #21245 (review) ? I’m not sure. 🤷‍♂️

  92. in doc/release-notes.md:112 in 356c74c6e0 outdated
    108@@ -109,6 +109,15 @@ Updated RPCs
    109   of `decodescript` these fields are top-level attributes, and included again as attributes
    110   of the `scriptPubKey` object. (#20286)
    111 
    112+- The `getblock` rpc now supports a level 3 verbosity containing a transaction inputs'
    


    kiminuo commented at 7:40 pm on July 16, 2021:

    Maybe:

    0- The `getblock` RPC command now supports verbose level 3 containing transaction inputs'
    

    (naming based on https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.15.0.md)

  93. fyquah force-pushed on Jul 16, 2021
  94. fyquah commented at 8:02 pm on July 16, 2021: contributor

    Is this Luke’s comment addressed: #21245 (comment) ? I’m not sure. 🤷‍♂️

    I don’t think so. It has already been moved into the if(calculate_fee) block.

  95. fyquah commented at 8:05 pm on July 16, 2021: contributor
    @kiminuo I think all but 2 remaining comments above are addressed.
  96. fyquah commented at 9:42 pm on July 16, 2021: contributor

    Maintainers: I believe all the reviews are addressed. Is there anything else blocking merge?

    Once again, sorry for the delay getting back to this.

  97. in test/functional/interface_rest.py:321 in 144547291d outdated
    312@@ -313,6 +313,13 @@ def run_test(self):
    313                             if 'coinbase' not in tx['vin'][0]}
    314         assert_equal(non_coinbase_txs, set(txs))
    315 
    316+        # Verify that the non-coinbase tx has "prevout" field set
    317+        for tx_obj in json_obj["tx"]:
    318+            for vin in tx_obj["vin"]:
    319+                if "coinbase" not in vin:
    320+                    prevout = vin["prevout"]
    321+                    assert_equal(prevout["generated"], False)
    


    theStack commented at 10:35 am on July 19, 2021:
    nit: should probably also check here that for coinbase txs, “prevout” is not set. Could also add a check assert "prevout" in vin before accessing, to avoid a KeyError thrown if this ever would fail in the future
  98. theStack approved
  99. theStack commented at 11:02 am on July 19, 2021: member

    ACK cecbfed94e90df32f59ee661b83cb28f30c68587

    Reviewed the code, built locally and ran the tests, issued a few getblock RPC commands on mainnet with verbose levels 1/2/3, LGTM. The tests could still be a bit more detailled, e.g. the sub-fields “height” and “scriptPubKey” are currently not covered (see also my comment beow), but this is non-blocking in my opinion.

  100. in src/core_write.cpp:234 in cecbfed94e outdated
    230@@ -231,8 +231,27 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_add
    231             in.pushKV("txinwitness", txinwitness);
    232         }
    233         if (calculate_fee) {
    234-            const CTxOut& prev_txout = txundo->vprevout[i].out;
    235+            const Coin& prev_coin = txundo->vprevout[i];
    


    kiminuo commented at 11:39 am on July 19, 2021:
    L233: calculate_fee may be called have_undo now as this code block now is not only about calculating fees.
  101. in src/rpc/blockchain.cpp:226 in cecbfed94e outdated
    237+            const bool have_undo = !IsBlockPruned(blockindex) && UndoReadFromDisk(blockUndo, blockindex);
    238+
    239+            for (size_t i = 0; i < block.vtx.size(); ++i) {
    240+                const CTransactionRef& tx = block.vtx.at(i);
    241+                // coinbase transaction (i == 0) doesn't have undo data
    242+                const CTxUndo* txundo = (have_undo && i) ? &blockUndo.vtxundo.at(i - 1) : nullptr;
    


    kiminuo commented at 12:01 pm on July 19, 2021:

    Nit:

    0                const CTxUndo* txundo = (have_undo && i > 0) ? &blockUndo.vtxundo.at(i - 1) : nullptr;
    
  102. kiminuo commented at 12:01 pm on July 19, 2021: contributor
    utACK
  103. in src/rpc/blockchain.cpp:941 in cecbfed94e outdated
    936@@ -930,7 +937,8 @@ static RPCHelpMan getblock()
    937     return RPCHelpMan{"getblock",
    938                 "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
    939                 "If verbosity is 1, returns an Object with information about block <hash>.\n"
    940-                "If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n",
    941+                "If verbosity is 2, returns an Object with information about block <hash> and information about each transaction.\n"
    942+                "If verbosity is 3, returns an Object with information about block <hash> and information about each transaction, including prevout information for inputs (only for blocks in the current best chain).\n",
    


    kiminuo commented at 12:06 pm on July 19, 2021:
    FMI: “only for blocks in the current best chain” - Is this precisely worded with regard to how pruning works?

    fyquah commented at 10:10 pm on August 3, 2021:
    iiuc, txundo will not be looked up for pruned blocks. I reworded this from “only for blocks” to “only for unpruned blocks”.
  104. DrahtBot added the label Needs rebase on Jul 21, 2021
  105. rpc: Replace boolean argument for tx details with enum class.
    Co-authored-by: Luke Dashjr <luke_github1@dashjr.org>
    Co-authored-by: 0xB10C <19157360+0xB10C@users.noreply.github.com>
    b788bbd837
  106. fyquah force-pushed on Aug 3, 2021
  107. fyquah force-pushed on Aug 3, 2021
  108. fyquah force-pushed on Aug 3, 2021
  109. rpc: Add level 3 verbosity to getblock RPC call.
    Display the prevout in transaction inputs when calling getblock level 3
    verbosity.
    
    Co-authored-by: Luke Dashjr <luke_github1@dashjr.org>
    Co-authored-by: 0xB10C <19157360+0xB10C@users.noreply.github.com>
    b702a1fb2e
  110. rpc: Add test for level 3 verbosity getblock rpc call. 65571bda12
  111. rest: Add test for prevout fields in getblock 8b215ebf4a
  112. release-notes: Add release note about getblock verbosity level 3. c1be00d295
  113. core_write: Rename calculate_fee to have_undo for clarity 72dbe98164
  114. fyquah force-pushed on Aug 3, 2021
  115. fyquah commented at 10:11 pm on August 3, 2021: contributor
    @kiminuo i think your comments should be addressed now. Can you mark this as reviewed once this looks good?
  116. DrahtBot removed the label Needs rebase on Aug 3, 2021
  117. kiminuo commented at 9:30 am on August 5, 2021: contributor

    Currently ./bitcoin-cli -testnet getblock prints:

     0error code: -1
     1error message:
     2getblock "blockhash" ( verbosity )
     3
     4If verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.
     5If verbosity is 1, returns an Object with information about block <hash>.
     6If verbosity is 2, returns an Object with information about block <hash> and information about each transaction.
     7If verbosity is 3, returns an Object with information about block <hash> and information about each transaction, including prevout information for inputs (only for blocks in the current best chain).
     8
     9Arguments:
    101. blockhash    (string, required) The block hash
    112. verbosity    (numeric, optional, default=1) 0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data
    12
    13Result (for verbosity = 0):
    14"hex"    (string) A string that is serialized, hex-encoded data for block 'hash'
    15
    16Result (for verbosity = 1):
    17{                                 (json object)
    18  "hash" : "hex",                 (string) the block hash (same as provided)
    19  "confirmations" : n,            (numeric) The number of confirmations, or -1 if the block is not on the main chain
    20  "size" : n,                     (numeric) The block size
    21  "strippedsize" : n,             (numeric) The block size excluding witness data
    22  "weight" : n,                   (numeric) The block weight as defined in BIP 141
    23  "height" : n,                   (numeric) The block height or index
    24  "version" : n,                  (numeric) The block version
    25  "versionHex" : "hex",           (string) The block version formatted in hexadecimal
    26  "merkleroot" : "hex",           (string) The merkle root
    27  "tx" : [                        (json array) The transaction ids
    28    "hex",                        (string) The transaction id
    29    ...
    30  ],
    31  "time" : xxx,                   (numeric) The block time expressed in UNIX epoch time
    32  "mediantime" : xxx,             (numeric) The median block time expressed in UNIX epoch time
    33  "nonce" : n,                    (numeric) The nonce
    34  "bits" : "hex",                 (string) The bits
    35  "difficulty" : n,               (numeric) The difficulty
    36  "chainwork" : "hex",            (string) Expected number of hashes required to produce the chain up to this block (in hex)
    37  "nTx" : n,                      (numeric) The number of transactions in the block
    38  "previousblockhash" : "hex",    (string, optional) The hash of the previous block (if available)
    39  "nextblockhash" : "hex"         (string, optional) The hash of the next block (if available)
    40}
    41
    42Result (for verbosity = 2):
    43{                   (json object)
    44  ...,              Same output as verbosity = 1
    45  "tx" : [          (json array)
    46    {               (json object)
    47      ...,          The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 "tx" result
    48      "fee" : n     (numeric) The transaction fee in BTC, omitted if block undo data is not available
    49    },
    50    ...
    51  ]
    52}
    53
    54Examples:
    55> bitcoin-cli getblock "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"
    56> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getblock", "params": ["00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
    

    It would be great to:

    • Add “Result (for verbosity = 3):” in the output.
    • Modify “2. verbosity (numeric, optional, default=1) 0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data” to include your new level 3.

    Edit: I’ll try to carve out some more time tomorrow to test it more.

  118. kiminuo commented at 9:35 am on August 5, 2021: contributor

    The following examples may be worth adding to your original post:

    Examples of the getblock output with various verbose levels. Note that 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 contains only 2 transactions.

    bitcoin-cli

    Verbose level 0

    0./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 0
    
    00400c020fbf5f342465b89fc746df587a07339e662a944aff4c286ca0b000000000000008387d05d584be6d61398c894427255227592c9e7c3c093759bafa4487e271532819c0b6100ec421969ccd91002010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5a03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000ffffffff04b92e9500000000001976a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac0000000000000000266a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df0000000000000000266a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c100000000000000002b6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f757301200000000000000000000000000000000000000000000000000000000000000000f1087e960100000000010386fe743a8db99cd6db255f8505d9e20e67e03edbd411874816382415a053b1120100000000ffffffffa0785a72492fc87903eb4e07893fc769ef561db7020ba9b43e9c484619c637e10000000000ffffffff7dcd54a6c50865c34290454183ffa1a7f31aae3557045007a9075b022a4759020100000000ffffffff02408e2c000000000017a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87eac5000000000000160014f2aeff3fd69c70bcff9c0709cc3ed1521868538002483045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e1012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e00248304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001210396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d4570247304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d634012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e000000000
    

    Verbose level 1

    0./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 1
    
     0{
     1  "hash": "000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5",
     2  "confirmations": 10,
     3  "height": 2063334,
     4  "version": 549453828,
     5  "versionHex": "20c00004",
     6  "merkleroot": "3215277e48a4af9b7593c0c3e7c992752255724294c89813d6e64b585dd08783",
     7  "time": 1628150913,
     8  "mediantime": 1628149483,
     9  "nonce": 282709097,
    10  "bits": "1942ec00",
    11  "difficulty": 64177845.58487042,
    12  "chainwork": "000000000000000000000000000000000000000000000558fbc2a80220ea0e44",
    13  "nTx": 2,
    14  "previousblockhash": "000000000000000bca86c2f4af44a962e63973a087f56d74fc895b4642f3f5fb",
    15  "nextblockhash": "000000000000000119b44a12b31fb2e1d2baa9ad5bb7419428f62cc77a4685f5",
    16  "strippedsize": 598,
    17  "size": 959,
    18  "weight": 2753,
    19  "tx": [
    20    "f10ed21d238ce32aaa00384af709381e2ecf1e3914604b4f0fbd817b3477017c",
    21    "6fcf360bade1cae884cb0d36dfb92455b7cfdc037cfbab75f86dfbfe28f08b3e"
    22  ]
    23}
    

    Verbose level 2

    0./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 2
    
      0{
      1  "hash": "000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5",
      2  "confirmations": 10,
      3  "height": 2063334,
      4  "version": 549453828,
      5  "versionHex": "20c00004",
      6  "merkleroot": "3215277e48a4af9b7593c0c3e7c992752255724294c89813d6e64b585dd08783",
      7  "time": 1628150913,
      8  "mediantime": 1628149483,
      9  "nonce": 282709097,
     10  "bits": "1942ec00",
     11  "difficulty": 64177845.58487042,
     12  "chainwork": "000000000000000000000000000000000000000000000558fbc2a80220ea0e44",
     13  "nTx": 2,
     14  "previousblockhash": "000000000000000bca86c2f4af44a962e63973a087f56d74fc895b4642f3f5fb",
     15  "nextblockhash": "000000000000000119b44a12b31fb2e1d2baa9ad5bb7419428f62cc77a4685f5",
     16  "strippedsize": 598,
     17  "size": 959,
     18  "weight": 2753,
     19  "tx": [
     20    {
     21      "txid": "f10ed21d238ce32aaa00384af709381e2ecf1e3914604b4f0fbd817b3477017c",
     22      "hash": "9a614c99fc94459d6a5901b4091576365def3a23e002d77e6d79fd153d533bf4",
     23      "version": 1,
     24      "size": 357,
     25      "vsize": 330,
     26      "weight": 1320,
     27      "locktime": 2524842225,
     28      "vin": [
     29        {
     30          "coinbase": "03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000",
     31          "txinwitness": [
     32            "0000000000000000000000000000000000000000000000000000000000000000"
     33          ],
     34          "sequence": 4294967295
     35        }
     36      ],
     37      "vout": [
     38        {
     39          "value": 0.09776825,
     40          "n": 0,
     41          "scriptPubKey": {
     42            "asm": "OP_DUP OP_HASH160 190f8ddccb511a66f0cfc9a33204d9287e65fdf7 OP_EQUALVERIFY OP_CHECKSIG",
     43            "hex": "76a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac",
     44            "address": "mhoTpa5QLRPFKsH4DdWSp1mru5BkEEWvYR",
     45            "type": "pubkeyhash"
     46          }
     47        },
     48        {
     49          "value": 0.00000000,
     50          "n": 1,
     51          "scriptPubKey": {
     52            "asm": "OP_RETURN b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
     53            "hex": "6a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
     54            "type": "nulldata"
     55          }
     56        },
     57        {
     58          "value": 0.00000000,
     59          "n": 2,
     60          "scriptPubKey": {
     61            "asm": "OP_RETURN aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
     62            "hex": "6a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
     63            "type": "nulldata"
     64          }
     65        },
     66        {
     67          "value": 0.00000000,
     68          "n": 3,
     69          "scriptPubKey": {
     70            "asm": "OP_RETURN 52534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
     71            "hex": "6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
     72            "type": "nulldata"
     73          }
     74        }
     75      ],
     76      "hex": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5a03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000ffffffff04b92e9500000000001976a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac0000000000000000266a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df0000000000000000266a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c100000000000000002b6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f757301200000000000000000000000000000000000000000000000000000000000000000f1087e96"
     77    },
     78    {
     79      "txid": "6fcf360bade1cae884cb0d36dfb92455b7cfdc037cfbab75f86dfbfe28f08b3e",
     80      "hash": "891566037ba9d65bdc6bce5135d27d18607e7903979d8fa014d1f7118d618691",
     81      "version": 1,
     82      "size": 521,
     83      "vsize": 278,
     84      "weight": 1109,
     85      "locktime": 0,
     86      "vin": [
     87        {
     88          "txid": "12b153a015243816488711d4db3ee0670ee2d905855f25dbd69cb98d3a74fe86",
     89          "vout": 1,
     90          "scriptSig": {
     91            "asm": "",
     92            "hex": ""
     93          },
     94          "txinwitness": [
     95            "3045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e101",
     96            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
     97          ],
     98          "sequence": 4294967295
     99        },
    100        {
    101          "txid": "e137c61946489c3eb4a90b02b71d56ef69c73f89074eeb0379c82f49725a78a0",
    102          "vout": 0,
    103          "scriptSig": {
    104            "asm": "",
    105            "hex": ""
    106          },
    107          "txinwitness": [
    108            "304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001",
    109            "0396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d457"
    110          ],
    111          "sequence": 4294967295
    112        },
    113        {
    114          "txid": "0259472a025b07a90750045735ae1af3a7a1ff8341459042c36508c5a654cd7d",
    115          "vout": 1,
    116          "scriptSig": {
    117            "asm": "",
    118            "hex": ""
    119          },
    120          "txinwitness": [
    121            "304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d63401",
    122            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
    123          ],
    124          "sequence": 4294967295
    125        }
    126      ],
    127      "vout": [
    128        {
    129          "value": 0.02920000,
    130          "n": 0,
    131          "scriptPubKey": {
    132            "asm": "OP_HASH160 d1c71b4df72064844eec341c86dc68cf81b9c2ec OP_EQUAL",
    133            "hex": "a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87",
    134            "address": "2NCNRjYqKz6j377wA328zjTqRGWBR59ygz1",
    135            "type": "scripthash"
    136          }
    137        },
    138        {
    139          "value": 0.00050666,
    140          "n": 1,
    141          "scriptPubKey": {
    142            "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    143            "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    144            "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
    145            "type": "witness_v0_keyhash"
    146          }
    147        }
    148      ],
    149      "fee": 0.00011200,
    150      "hex": "0100000000010386fe743a8db99cd6db255f8505d9e20e67e03edbd411874816382415a053b1120100000000ffffffffa0785a72492fc87903eb4e07893fc769ef561db7020ba9b43e9c484619c637e10000000000ffffffff7dcd54a6c50865c34290454183ffa1a7f31aae3557045007a9075b022a4759020100000000ffffffff02408e2c000000000017a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87eac5000000000000160014f2aeff3fd69c70bcff9c0709cc3ed1521868538002483045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e1012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e00248304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001210396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d4570247304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d634012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e000000000"
    151    }
    152  ]
    153}
    

    Verbose level 3

    0./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 3
    
      0{
      1  "hash": "000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5",
      2  "confirmations": 10,
      3  "height": 2063334,
      4  "version": 549453828,
      5  "versionHex": "20c00004",
      6  "merkleroot": "3215277e48a4af9b7593c0c3e7c992752255724294c89813d6e64b585dd08783",
      7  "time": 1628150913,
      8  "mediantime": 1628149483,
      9  "nonce": 282709097,
     10  "bits": "1942ec00",
     11  "difficulty": 64177845.58487042,
     12  "chainwork": "000000000000000000000000000000000000000000000558fbc2a80220ea0e44",
     13  "nTx": 2,
     14  "previousblockhash": "000000000000000bca86c2f4af44a962e63973a087f56d74fc895b4642f3f5fb",
     15  "nextblockhash": "000000000000000119b44a12b31fb2e1d2baa9ad5bb7419428f62cc77a4685f5",
     16  "strippedsize": 598,
     17  "size": 959,
     18  "weight": 2753,
     19  "tx": [
     20    {
     21      "txid": "f10ed21d238ce32aaa00384af709381e2ecf1e3914604b4f0fbd817b3477017c",
     22      "hash": "9a614c99fc94459d6a5901b4091576365def3a23e002d77e6d79fd153d533bf4",
     23      "version": 1,
     24      "size": 357,
     25      "vsize": 330,
     26      "weight": 1320,
     27      "locktime": 2524842225,
     28      "vin": [
     29        {
     30          "coinbase": "03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000",
     31          "txinwitness": [
     32            "0000000000000000000000000000000000000000000000000000000000000000"
     33          ],
     34          "sequence": 4294967295
     35        }
     36      ],
     37      "vout": [
     38        {
     39          "value": 0.09776825,
     40          "n": 0,
     41          "scriptPubKey": {
     42            "asm": "OP_DUP OP_HASH160 190f8ddccb511a66f0cfc9a33204d9287e65fdf7 OP_EQUALVERIFY OP_CHECKSIG",
     43            "hex": "76a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac",
     44            "address": "mhoTpa5QLRPFKsH4DdWSp1mru5BkEEWvYR",
     45            "type": "pubkeyhash"
     46          }
     47        },
     48        {
     49          "value": 0.00000000,
     50          "n": 1,
     51          "scriptPubKey": {
     52            "asm": "OP_RETURN b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
     53            "hex": "6a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
     54            "type": "nulldata"
     55          }
     56        },
     57        {
     58          "value": 0.00000000,
     59          "n": 2,
     60          "scriptPubKey": {
     61            "asm": "OP_RETURN aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
     62            "hex": "6a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
     63            "type": "nulldata"
     64          }
     65        },
     66        {
     67          "value": 0.00000000,
     68          "n": 3,
     69          "scriptPubKey": {
     70            "asm": "OP_RETURN 52534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
     71            "hex": "6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
     72            "type": "nulldata"
     73          }
     74        }
     75      ],
     76      "hex": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5a03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000ffffffff04b92e9500000000001976a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac0000000000000000266a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df0000000000000000266a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c100000000000000002b6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f757301200000000000000000000000000000000000000000000000000000000000000000f1087e96"
     77    },
     78    {
     79      "txid": "6fcf360bade1cae884cb0d36dfb92455b7cfdc037cfbab75f86dfbfe28f08b3e",
     80      "hash": "891566037ba9d65bdc6bce5135d27d18607e7903979d8fa014d1f7118d618691",
     81      "version": 1,
     82      "size": 521,
     83      "vsize": 278,
     84      "weight": 1109,
     85      "locktime": 0,
     86      "vin": [
     87        {
     88          "txid": "12b153a015243816488711d4db3ee0670ee2d905855f25dbd69cb98d3a74fe86",
     89          "vout": 1,
     90          "scriptSig": {
     91            "asm": "",
     92            "hex": ""
     93          },
     94          "txinwitness": [
     95            "3045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e101",
     96            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
     97          ],
     98          "prevout": {
     99            "generated": false,
    100            "height": 2063323,
    101            "value": 0.00544519,
    102            "scriptPubKey": {
    103              "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    104              "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    105              "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
    106              "type": "witness_v0_keyhash",
    107              "addresses": [
    108                "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn"
    109              ],
    110              "reqSigs": 1
    111            }
    112          },
    113          "sequence": 4294967295
    114        },
    115        {
    116          "txid": "e137c61946489c3eb4a90b02b71d56ef69c73f89074eeb0379c82f49725a78a0",
    117          "vout": 0,
    118          "scriptSig": {
    119            "asm": "",
    120            "hex": ""
    121          },
    122          "txinwitness": [
    123            "304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001",
    124            "0396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d457"
    125          ],
    126          "prevout": {
    127            "generated": false,
    128            "height": 2034020,
    129            "value": 0.01184228,
    130            "scriptPubKey": {
    131              "asm": "0 4aefc0691c23cddd7ac75d9ba3714e37c802088a",
    132              "hex": "00144aefc0691c23cddd7ac75d9ba3714e37c802088a",
    133              "address": "tb1qfthuq6guy0xa67k8tkd6xu2wxlyqyzy2ctc4fz",
    134              "type": "witness_v0_keyhash",
    135              "addresses": [
    136                "tb1qfthuq6guy0xa67k8tkd6xu2wxlyqyzy2ctc4fz"
    137              ],
    138              "reqSigs": 1
    139            }
    140          },
    141          "sequence": 4294967295
    142        },
    143        {
    144          "txid": "0259472a025b07a90750045735ae1af3a7a1ff8341459042c36508c5a654cd7d",
    145          "vout": 1,
    146          "scriptSig": {
    147            "asm": "",
    148            "hex": ""
    149          },
    150          "txinwitness": [
    151            "304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d63401",
    152            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
    153          ],
    154          "prevout": {
    155            "generated": false,
    156            "height": 2007043,
    157            "value": 0.01253119,
    158            "scriptPubKey": {
    159              "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    160              "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    161              "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
    162              "type": "witness_v0_keyhash",
    163              "addresses": [
    164                "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn"
    165              ],
    166              "reqSigs": 1
    167            }
    168          },
    169          "sequence": 4294967295
    170        }
    171      ],
    172      "vout": [
    173        {
    174          "value": 0.02920000,
    175          "n": 0,
    176          "scriptPubKey": {
    177            "asm": "OP_HASH160 d1c71b4df72064844eec341c86dc68cf81b9c2ec OP_EQUAL",
    178            "hex": "a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87",
    179            "address": "2NCNRjYqKz6j377wA328zjTqRGWBR59ygz1",
    180            "type": "scripthash"
    181          }
    182        },
    183        {
    184          "value": 0.00050666,
    185          "n": 1,
    186          "scriptPubKey": {
    187            "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    188            "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    189            "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
    190            "type": "witness_v0_keyhash"
    191          }
    192        }
    193      ],
    194      "fee": 0.00011200,
    195      "hex": "0100000000010386fe743a8db99cd6db255f8505d9e20e67e03edbd411874816382415a053b1120100000000ffffffffa0785a72492fc87903eb4e07893fc769ef561db7020ba9b43e9c484619c637e10000000000ffffffff7dcd54a6c50865c34290454183ffa1a7f31aae3557045007a9075b022a4759020100000000ffffffff02408e2c000000000017a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87eac5000000000000160014f2aeff3fd69c70bcff9c0709cc3ed1521868538002483045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e1012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e00248304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001210396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d4570247304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d634012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e000000000"
    196    }
    197  ]
    198}
    

    REST

    0curl -H "content-type:text/plain;" http://127.0.0.1:18332/rest/block/000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5.json
    
      0{
      1  "hash": "000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5",
      2  "confirmations": 11,
      3  "height": 2063334,
      4  "version": 549453828,
      5  "versionHex": "20c00004",
      6  "merkleroot": "3215277e48a4af9b7593c0c3e7c992752255724294c89813d6e64b585dd08783",
      7  "time": 1628150913,
      8  "mediantime": 1628149483,
      9  "nonce": 282709097,
     10  "bits": "1942ec00",
     11  "difficulty": 64177845.58487042,
     12  "chainwork": "000000000000000000000000000000000000000000000558fbc2a80220ea0e44",
     13  "nTx": 2,
     14  "previousblockhash": "000000000000000bca86c2f4af44a962e63973a087f56d74fc895b4642f3f5fb",
     15  "nextblockhash": "000000000000000119b44a12b31fb2e1d2baa9ad5bb7419428f62cc77a4685f5",
     16  "strippedsize": 598,
     17  "size": 959,
     18  "weight": 2753,
     19  "tx": [
     20    {
     21      "txid": "f10ed21d238ce32aaa00384af709381e2ecf1e3914604b4f0fbd817b3477017c",
     22      "hash": "9a614c99fc94459d6a5901b4091576365def3a23e002d77e6d79fd153d533bf4",
     23      "version": 1,
     24      "size": 357,
     25      "vsize": 330,
     26      "weight": 1320,
     27      "locktime": 2524842225,
     28      "vin": [
     29        {
     30          "coinbase": "03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000",
     31          "txinwitness": [
     32            "0000000000000000000000000000000000000000000000000000000000000000"
     33          ],
     34          "sequence": 4294967295
     35        }
     36      ],
     37      "vout": [
     38        {
     39          "value": 0.09776825,
     40          "n": 0,
     41          "scriptPubKey": {
     42            "asm": "OP_DUP OP_HASH160 190f8ddccb511a66f0cfc9a33204d9287e65fdf7 OP_EQUALVERIFY OP_CHECKSIG",
     43            "hex": "76a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac",
     44            "address": "mhoTpa5QLRPFKsH4DdWSp1mru5BkEEWvYR",
     45            "type": "pubkeyhash"
     46          }
     47        },
     48        {
     49          "value": 0,
     50          "n": 1,
     51          "scriptPubKey": {
     52            "asm": "OP_RETURN b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
     53            "hex": "6a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
     54            "type": "nulldata"
     55          }
     56        },
     57        {
     58          "value": 0,
     59          "n": 2,
     60          "scriptPubKey": {
     61            "asm": "OP_RETURN aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
     62            "hex": "6a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
     63            "type": "nulldata"
     64          }
     65        },
     66        {
     67          "value": 0,
     68          "n": 3,
     69          "scriptPubKey": {
     70            "asm": "OP_RETURN 52534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
     71            "hex": "6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
     72            "type": "nulldata"
     73          }
     74        }
     75      ],
     76      "hex": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5a03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000ffffffff04b92e9500000000001976a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac0000000000000000266a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df0000000000000000266a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c100000000000000002b6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f757301200000000000000000000000000000000000000000000000000000000000000000f1087e96"
     77    },
     78    {
     79      "txid": "6fcf360bade1cae884cb0d36dfb92455b7cfdc037cfbab75f86dfbfe28f08b3e",
     80      "hash": "891566037ba9d65bdc6bce5135d27d18607e7903979d8fa014d1f7118d618691",
     81      "version": 1,
     82      "size": 521,
     83      "vsize": 278,
     84      "weight": 1109,
     85      "locktime": 0,
     86      "vin": [
     87        {
     88          "txid": "12b153a015243816488711d4db3ee0670ee2d905855f25dbd69cb98d3a74fe86",
     89          "vout": 1,
     90          "scriptSig": {
     91            "asm": "",
     92            "hex": ""
     93          },
     94          "txinwitness": [
     95            "3045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e101",
     96            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
     97          ],
     98          "prevout": {
     99            "generated": false,
    100            "height": 2063323,
    101            "value": 0.00544519,
    102            "scriptPubKey": {
    103              "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    104              "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    105              "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
    106              "type": "witness_v0_keyhash",
    107              "addresses": [
    108                "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn"
    109              ],
    110              "reqSigs": 1
    111            }
    112          },
    113          "sequence": 4294967295
    114        },
    115        {
    116          "txid": "e137c61946489c3eb4a90b02b71d56ef69c73f89074eeb0379c82f49725a78a0",
    117          "vout": 0,
    118          "scriptSig": {
    119            "asm": "",
    120            "hex": ""
    121          },
    122          "txinwitness": [
    123            "304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001",
    124            "0396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d457"
    125          ],
    126          "prevout": {
    127            "generated": false,
    128            "height": 2034020,
    129            "value": 0.01184228,
    130            "scriptPubKey": {
    131              "asm": "0 4aefc0691c23cddd7ac75d9ba3714e37c802088a",
    132              "hex": "00144aefc0691c23cddd7ac75d9ba3714e37c802088a",
    133              "address": "tb1qfthuq6guy0xa67k8tkd6xu2wxlyqyzy2ctc4fz",
    134              "type": "witness_v0_keyhash",
    135              "addresses": [
    136                "tb1qfthuq6guy0xa67k8tkd6xu2wxlyqyzy2ctc4fz"
    137              ],
    138              "reqSigs": 1
    139            }
    140          },
    141          "sequence": 4294967295
    142        },
    143        {
    144          "txid": "0259472a025b07a90750045735ae1af3a7a1ff8341459042c36508c5a654cd7d",
    145          "vout": 1,
    146          "scriptSig": {
    147            "asm": "",
    148            "hex": ""
    149          },
    150          "txinwitness": [
    151            "304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d63401",
    152            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
    153          ],
    154          "prevout": {
    155            "generated": false,
    156            "height": 2007043,
    157            "value": 0.01253119,
    158            "scriptPubKey": {
    159              "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    160              "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    161              "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
    162              "type": "witness_v0_keyhash",
    163              "addresses": [
    164                "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn"
    165              ],
    166              "reqSigs": 1
    167            }
    168          },
    169          "sequence": 4294967295
    170        }
    171      ],
    172      "vout": [
    173        {
    174          "value": 0.0292,
    175          "n": 0,
    176          "scriptPubKey": {
    177            "asm": "OP_HASH160 d1c71b4df72064844eec341c86dc68cf81b9c2ec OP_EQUAL",
    178            "hex": "a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87",
    179            "address": "2NCNRjYqKz6j377wA328zjTqRGWBR59ygz1",
    180            "type": "scripthash"
    181          }
    182        },
    183        {
    184          "value": 0.00050666,
    185          "n": 1,
    186          "scriptPubKey": {
    187            "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    188            "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
    189            "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
    190            "type": "witness_v0_keyhash"
    191          }
    192        }
    193      ],
    194      "fee": 0.000112,
    195      "hex": "0100000000010386fe743a8db99cd6db255f8505d9e20e67e03edbd411874816382415a053b1120100000000ffffffffa0785a72492fc87903eb4e07893fc769ef561db7020ba9b43e9c484619c637e10000000000ffffffff7dcd54a6c50865c34290454183ffa1a7f31aae3557045007a9075b022a4759020100000000ffffffff02408e2c000000000017a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87eac5000000000000160014f2aeff3fd69c70bcff9c0709cc3ed1521868538002483045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e1012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e00248304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001210396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d4570247304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d634012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e000000000"
    196    }
    197  ]
    198}
    
  119. in src/rpc/blockchain.cpp:1028 in 72dbe98164
    1024@@ -1017,7 +1025,16 @@ static RPCHelpMan getblock()
    1025         return strHex;
    1026     }
    1027 
    1028-    return blockToJSON(block, tip, pblockindex, verbosity >= 2);
    1029+    TxVerbosity block_to_json_verbosity;
    


    kiminuo commented at 6:50 am on August 6, 2021:
    nit: The name block_to_json_verbosity seems long and it does not add any more meaning than just tx_verbosity, imho.

    jaysonmald35 commented at 8:33 pm on September 6, 2021:
    Thank u
  120. in src/core_io.h:23 in 72dbe98164
    19@@ -20,6 +20,12 @@ class uint256;
    20 class UniValue;
    21 class CTxUndo;
    22 
    23+enum class TxVerbosity {
    


    kiminuo commented at 6:55 am on August 6, 2021:
    Some enum classes have these nice doxygen comments: https://github.com/bitcoin/bitcoin/blob/d67330d11245b11fbdd5e2dd5343ee451186931e/src/consensus/validation.h#L63 Maybe it is worth adding here too.
  121. in test/functional/interface_rest.py:315 in 72dbe98164
    311@@ -312,6 +312,16 @@ def run_test(self):
    312                             if 'coinbase' not in tx['vin'][0]}
    313         assert_equal(non_coinbase_txs, set(txs))
    314 
    315+        # Verify that the non-coinbase tx has "prevout" field set
    


    kiminuo commented at 7:10 am on August 6, 2021:

    nit:

    0        # Verify that the non-coinbase tx has "prevout" key set
    

    A Python dictionary is a set of key-value pairs.

  122. in test/functional/interface_rest.py:321 in 72dbe98164
    316+        for tx_obj in json_obj["tx"]:
    317+            for vin in tx_obj["vin"]:
    318+                if "coinbase" not in vin:
    319+                    assert "prevout" in vin
    320+                    prevout = vin["prevout"]
    321+                    assert_equal(prevout["generated"], False)
    


    kiminuo commented at 7:14 am on August 6, 2021:

    Given that prevout variable is used just once, it may be shorter and actually easier to read:

    0                    assert_equal(vin["prevout"]["generated"], False)
    
  123. in test/functional/rpc_blockchain.py:428 in 72dbe98164
    434+            assert_equal(tx['fee'], tx['vsize'] * fee_per_byte)
    435+
    436+        def assert_vin_contains_prevout(verbosity):
    437+            block = node.getblock(blockhash, verbosity)
    438+            tx = block["tx"][1]
    439+            total_vin = 0
    


    kiminuo commented at 7:37 am on August 6, 2021:

    I believe this should be more like:

    0            total_vin = Decimal("0.00000000")
    
  124. in src/rpc/blockchain.cpp:225 in 72dbe98164
    236+            CBlockUndo blockUndo;
    237+            const bool have_undo = !IsBlockPruned(blockindex) && UndoReadFromDisk(blockUndo, blockindex);
    238+
    239+            for (size_t i = 0; i < block.vtx.size(); ++i) {
    240+                const CTransactionRef& tx = block.vtx.at(i);
    241+                // coinbase transaction (i == 0) doesn't have undo data
    


    kiminuo commented at 7:42 am on August 6, 2021:

    nit:

    0                // coinbase transaction (i.e. i == 0) doesn't have undo data
    
  125. in src/core_write.cpp:245 in 72dbe98164
    242+                case TxVerbosity::SHOW_DETAILS:
    243+                    break;
    244+
    245+                case TxVerbosity::SHOW_DETAILS_AND_PREVOUT:
    246+                    UniValue o_script_pub_key(UniValue::VOBJ);
    247+                    ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* includeHex */ true, /* include_addresses */ true);
    


    kiminuo commented at 7:48 am on August 6, 2021:

    Question: There is include_addresses parameter which is not used here. true is passed instead. Is that correct or should it look like:

    0                    ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* includeHex */ true, include_addresses);
    

    It looks to me that include_addresses = true is deprecated actually.

    Edit: This PR will be most likely affected by #22650.


    luke-jr commented at 4:29 pm on August 25, 2021:
    Since this is adding new output, I think it should probably just be a constant false here, actually.
  126. kiminuo commented at 7:52 am on August 6, 2021: contributor

    Did some more review, tested it and the PR is shaping up very nicely.

    It would be great if other reviewers could have a look too (@jonatack, @theStack possibly?) as I believe this has already received significant amount of work.

  127. kiminuo commented at 8:53 pm on August 8, 2021: contributor

    @fyquah I have attempted to address my comments above and add RPC help here: https://github.com/kiminuo/bitcoin/tree/feature/2021-08-08-verbosity-level-3-getblock-iteration-3:

    0./bitcoin-cli -testnet getblock
    

    reports for me:

     0error code: -1
     1error message:
     2getblock "blockhash" ( verbosity )
     3
     4If verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.
     5If verbosity is 1, returns an Object with information about block <hash>.
     6If verbosity is 2, returns an Object with information about block <hash> and information about each transaction.
     7If 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).
     8
     9Arguments:
    101. blockhash    (string, required) The block hash
    112. verbosity    (numeric, optional, default=1) 0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data
    12
    13Result (for verbosity = 0):
    14"hex"    (string) A string that is serialized, hex-encoded data for block 'hash'
    15
    16Result (for verbosity = 1):
    17{                                 (json object)
    18  "hash" : "hex",                 (string) the block hash (same as provided)
    19  "confirmations" : n,            (numeric) The number of confirmations, or -1 if the block is not on the main chain
    20  "size" : n,                     (numeric) The block size
    21  "strippedsize" : n,             (numeric) The block size excluding witness data
    22  "weight" : n,                   (numeric) The block weight as defined in BIP 141
    23  "height" : n,                   (numeric) The block height or index
    24  "version" : n,                  (numeric) The block version
    25  "versionHex" : "hex",           (string) The block version formatted in hexadecimal
    26  "merkleroot" : "hex",           (string) The merkle root
    27  "tx" : [                        (json array) The transaction ids
    28    "hex",                        (string) The transaction id
    29    ...
    30  ],
    31  "time" : xxx,                   (numeric) The block time expressed in UNIX epoch time
    32  "mediantime" : xxx,             (numeric) The median block time expressed in UNIX epoch time
    33  "nonce" : n,                    (numeric) The nonce
    34  "bits" : "hex",                 (string) The bits
    35  "difficulty" : n,               (numeric) The difficulty
    36  "chainwork" : "hex",            (string) Expected number of hashes required to produce the chain up to this block (in hex)
    37  "nTx" : n,                      (numeric) The number of transactions in the block
    38  "previousblockhash" : "hex",    (string, optional) The hash of the previous block (if available)
    39  "nextblockhash" : "hex"         (string, optional) The hash of the next block (if available)
    40}
    41
    42Result (for verbosity = 2):
    43{                   (json object)
    44  ...,              Same output as verbosity = 1
    45  "tx" : [          (json array)
    46    {               (json object)
    47      ...,          The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 "tx" result
    48      "fee" : n     (numeric) The transaction fee in BTC, omitted if block undo data is not available
    49    },
    50    ...
    51  ]
    52}
    53
    54Result (for verbosity = 3):
    55{                                        (json object)
    56  ...,                                   Same output as verbosity = 2
    57  "tx" : [                               (json array)
    58    {                                    (json object)
    59      "vin" : [                          (json array)
    60        {                                (json object)
    61          ...,                           The same output as verbosity = 2
    62          "prevout" : {                  (json object)
    63            "generated" : true|false,    (boolean) Coinbase or not
    64            "height" : n,                (numeric) The height of the prevout
    65            "value" : n,                 (numeric) The value in BTC
    66            "scriptPubKey" : {           (json object)
    67              "asm" : "str",             (string) The asm
    68              "hex" : "str",             (string) The hex
    69              "reqSigs" : n,             (numeric, optional) (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures
    70              "type" : "str",            (string) The type, eg 'pubkeyhash'
    71              "address" : "str",         (string, optional) bitcoin address (only if a well-defined address exists)
    72              "addresses" : [            (json array, optional) (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses
    73                "str",                   (string) bitcoin address
    74                ...
    75              ]
    76            }
    77          }
    78        },
    79        ...
    80      ]
    81    },
    82    ...
    83  ]
    84}
    85
    86Examples:
    87> bitcoin-cli getblock "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"
    88> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getblock", "params": ["00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
    

    If you find any of the modifications useful, please include it in your PR.

  128. theStack commented at 0:07 am on August 9, 2021: member

    re-ACK 72dbe9816482d46c63168109c8745d3ec615b031

    Verified via git range-diff cecbfed9...72dbe981 that since my last ACK all requested changes since then (e.g. rename calculate_fee to have_undo (https://github.com/bitcoin/bitcoin/pull/21245#discussion_r672221707), more detailled “prevout” checking w.r.t. to coinbase/non-coinbase txs (https://github.com/bitcoin/bitcoin/pull/21245#discussion_r672184180), RPC help improvement (https://github.com/bitcoin/bitcoin/pull/21245#discussion_r672238121)) were tackled. Also compiled locally and successfully ran the involved functional tests.

    Did some more review, tested it and the PR is shaping up very nicely.

    Agree! :) @kiminuo made some very good points for further improvements, especially considering the missing result desription for the newly introduced level in the RPC help. Since none of them are really blockers IMHO and the PR author does seem to be quite busy, maybe they can be done in a follow-up PR, to move things forward?

  129. fyquah commented at 0:06 am on August 20, 2021: contributor

    Hi, sorry, I haven’t been able to spend much time on this :(

    I like the suggestion to have @kiminuo ’s follow-up PR addressing the non-blocking issues. Is there anything that is blocking merge at this point?

    (Tagging an arbitrary maintainer: @fanquake )

  130. fanquake commented at 1:34 am on August 25, 2021: member

    Is there anything that is blocking merge at this point?

    This has only been ACK’d by a single reviewer.

  131. luke-jr commented at 3:20 am on August 25, 2021: member
    I would re-ACK except for #21245 (review)
  132. kiminuo commented at 7:59 am on August 25, 2021: contributor

    @fyquah I think #21245 (review) is important so I would ACK once this is fixed.

    Also, the work is actually done here #21245 (comment) I believe (the last commit is extra and is for a follow-up PR).

  133. kiminuo commented at 8:20 pm on September 6, 2021: contributor

    @fyquah Could you find a moment to address #21245 (review)?

    (PS: I’m willing to take over your PR to work on it if you are too busy. Anyway, it seems to me one little change is needed here, nothing time consuming.)

  134. fanquake commented at 11:17 am on September 8, 2021: member
    Closing this for now that #22918 is open.
  135. fanquake closed this on Sep 8, 2021

  136. laanwj referenced this in commit 986003aff9 on Oct 19, 2021
  137. sidhujag referenced this in commit 20541b82b7 on Oct 19, 2021
  138. DrahtBot locked this on Sep 17, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-19 03:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me