Skip to content

Conversation

fyquah
Copy link
Contributor

@fyquah fyquah commented Feb 20, 2021

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 20, 2021

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.

@0xB10C
Copy link
Contributor

0xB10C commented Feb 23, 2021

Concept ACK. Thanks for picking this up! Will have a closer look and test this soon.

@fyquah fyquah force-pushed the verbosity-level-3-getblock branch from 6eede79 to dc68479 Compare February 24, 2021 20:35
Copy link
Contributor

@0xB10C 0xB10C left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 53ea5bd

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

@fyquah fyquah force-pushed the verbosity-level-3-getblock branch 2 times, most recently from 7569d7c to d39eb54 Compare February 26, 2021 16:24
@luke-jr
Copy link
Member

luke-jr commented Feb 26, 2021

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.

@fyquah fyquah force-pushed the verbosity-level-3-getblock branch from d39eb54 to 5710e3f Compare February 27, 2021 14:20
@fyquah
Copy link
Contributor Author

fyquah commented Feb 27, 2021

Ideally, this should probably be 3 commits

Done

@fyquah fyquah force-pushed the verbosity-level-3-getblock branch 8 times, most recently from 37f2c4e to d512661 Compare March 1, 2021 15:11
@fyquah fyquah force-pushed the verbosity-level-3-getblock branch 2 times, most recently from c8ecb1d to 4aaebc1 Compare March 1, 2021 17:07
@fyquah fyquah force-pushed the verbosity-level-3-getblock branch from 3f70a60 to 72dbe98 Compare August 3, 2021 22:09
@fyquah
Copy link
Contributor Author

fyquah commented Aug 3, 2021

@kiminuo i think your comments should be addressed now. Can you mark this as reviewed once this looks good?

@kiminuo
Copy link
Contributor

kiminuo commented Aug 5, 2021

Currently ./bitcoin-cli -testnet getblock prints:

Console output
error code: -1
error message:
getblock "blockhash" ( verbosity )

If verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.
If verbosity is 1, returns an Object with information about block <hash>.
If verbosity is 2, returns an Object with information about block <hash> and information about each transaction.
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).

Arguments:
1. blockhash    (string, required) The block hash
2. verbosity    (numeric, optional, default=1) 0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data

Result (for verbosity = 0):
"hex"    (string) A string that is serialized, hex-encoded data for block 'hash'

Result (for verbosity = 1):
{                                 (json object)
  "hash" : "hex",                 (string) the block hash (same as provided)
  "confirmations" : n,            (numeric) The number of confirmations, or -1 if the block is not on the main chain
  "size" : n,                     (numeric) The block size
  "strippedsize" : n,             (numeric) The block size excluding witness data
  "weight" : n,                   (numeric) The block weight as defined in BIP 141
  "height" : n,                   (numeric) The block height or index
  "version" : n,                  (numeric) The block version
  "versionHex" : "hex",           (string) The block version formatted in hexadecimal
  "merkleroot" : "hex",           (string) The merkle root
  "tx" : [                        (json array) The transaction ids
    "hex",                        (string) The transaction id
    ...
  ],
  "time" : xxx,                   (numeric) The block time expressed in UNIX epoch time
  "mediantime" : xxx,             (numeric) The median block time expressed in UNIX epoch time
  "nonce" : n,                    (numeric) The nonce
  "bits" : "hex",                 (string) The bits
  "difficulty" : n,               (numeric) The difficulty
  "chainwork" : "hex",            (string) Expected number of hashes required to produce the chain up to this block (in hex)
  "nTx" : n,                      (numeric) The number of transactions in the block
  "previousblockhash" : "hex",    (string, optional) The hash of the previous block (if available)
  "nextblockhash" : "hex"         (string, optional) The hash of the next block (if available)
}

Result (for verbosity = 2):
{                   (json object)
  ...,              Same output as verbosity = 1
  "tx" : [          (json array)
    {               (json object)
      ...,          The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 "tx" result
      "fee" : n     (numeric) The transaction fee in BTC, omitted if block undo data is not available
    },
    ...
  ]
}

Examples:
> bitcoin-cli getblock "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"
> 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.

@kiminuo
Copy link
Contributor

kiminuo commented Aug 5, 2021

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

./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 0
Console output
0400c020fbf5f342465b89fc746df587a07339e662a944aff4c286ca0b000000000000008387d05d584be6d61398c894427255227592c9e7c3c093759bafa4487e271532819c0b6100ec421969ccd91002010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5a03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000ffffffff04b92e9500000000001976a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac0000000000000000266a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df0000000000000000266a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c100000000000000002b6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f757301200000000000000000000000000000000000000000000000000000000000000000f1087e960100000000010386fe743a8db99cd6db255f8505d9e20e67e03edbd411874816382415a053b1120100000000ffffffffa0785a72492fc87903eb4e07893fc769ef561db7020ba9b43e9c484619c637e10000000000ffffffff7dcd54a6c50865c34290454183ffa1a7f31aae3557045007a9075b022a4759020100000000ffffffff02408e2c000000000017a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87eac5000000000000160014f2aeff3fd69c70bcff9c0709cc3ed1521868538002483045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e1012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e00248304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001210396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d4570247304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d634012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e000000000

Verbose level 1

./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 1
Console output
{
  "hash": "000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5",
  "confirmations": 10,
  "height": 2063334,
  "version": 549453828,
  "versionHex": "20c00004",
  "merkleroot": "3215277e48a4af9b7593c0c3e7c992752255724294c89813d6e64b585dd08783",
  "time": 1628150913,
  "mediantime": 1628149483,
  "nonce": 282709097,
  "bits": "1942ec00",
  "difficulty": 64177845.58487042,
  "chainwork": "000000000000000000000000000000000000000000000558fbc2a80220ea0e44",
  "nTx": 2,
  "previousblockhash": "000000000000000bca86c2f4af44a962e63973a087f56d74fc895b4642f3f5fb",
  "nextblockhash": "000000000000000119b44a12b31fb2e1d2baa9ad5bb7419428f62cc77a4685f5",
  "strippedsize": 598,
  "size": 959,
  "weight": 2753,
  "tx": [
    "f10ed21d238ce32aaa00384af709381e2ecf1e3914604b4f0fbd817b3477017c",
    "6fcf360bade1cae884cb0d36dfb92455b7cfdc037cfbab75f86dfbfe28f08b3e"
  ]
}

Verbose level 2

./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 2
Console output
{
  "hash": "000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5",
  "confirmations": 10,
  "height": 2063334,
  "version": 549453828,
  "versionHex": "20c00004",
  "merkleroot": "3215277e48a4af9b7593c0c3e7c992752255724294c89813d6e64b585dd08783",
  "time": 1628150913,
  "mediantime": 1628149483,
  "nonce": 282709097,
  "bits": "1942ec00",
  "difficulty": 64177845.58487042,
  "chainwork": "000000000000000000000000000000000000000000000558fbc2a80220ea0e44",
  "nTx": 2,
  "previousblockhash": "000000000000000bca86c2f4af44a962e63973a087f56d74fc895b4642f3f5fb",
  "nextblockhash": "000000000000000119b44a12b31fb2e1d2baa9ad5bb7419428f62cc77a4685f5",
  "strippedsize": 598,
  "size": 959,
  "weight": 2753,
  "tx": [
    {
      "txid": "f10ed21d238ce32aaa00384af709381e2ecf1e3914604b4f0fbd817b3477017c",
      "hash": "9a614c99fc94459d6a5901b4091576365def3a23e002d77e6d79fd153d533bf4",
      "version": 1,
      "size": 357,
      "vsize": 330,
      "weight": 1320,
      "locktime": 2524842225,
      "vin": [
        {
          "coinbase": "03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000",
          "txinwitness": [
            "0000000000000000000000000000000000000000000000000000000000000000"
          ],
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 0.09776825,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_DUP OP_HASH160 190f8ddccb511a66f0cfc9a33204d9287e65fdf7 OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "76a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac",
            "address": "mhoTpa5QLRPFKsH4DdWSp1mru5BkEEWvYR",
            "type": "pubkeyhash"
          }
        },
        {
          "value": 0.00000000,
          "n": 1,
          "scriptPubKey": {
            "asm": "OP_RETURN b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
            "hex": "6a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
            "type": "nulldata"
          }
        },
        {
          "value": 0.00000000,
          "n": 2,
          "scriptPubKey": {
            "asm": "OP_RETURN aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
            "hex": "6a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
            "type": "nulldata"
          }
        },
        {
          "value": 0.00000000,
          "n": 3,
          "scriptPubKey": {
            "asm": "OP_RETURN 52534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
            "hex": "6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
            "type": "nulldata"
          }
        }
      ],
      "hex": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5a03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000ffffffff04b92e9500000000001976a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac0000000000000000266a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df0000000000000000266a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c100000000000000002b6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f757301200000000000000000000000000000000000000000000000000000000000000000f1087e96"
    },
    {
      "txid": "6fcf360bade1cae884cb0d36dfb92455b7cfdc037cfbab75f86dfbfe28f08b3e",
      "hash": "891566037ba9d65bdc6bce5135d27d18607e7903979d8fa014d1f7118d618691",
      "version": 1,
      "size": 521,
      "vsize": 278,
      "weight": 1109,
      "locktime": 0,
      "vin": [
        {
          "txid": "12b153a015243816488711d4db3ee0670ee2d905855f25dbd69cb98d3a74fe86",
          "vout": 1,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "3045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e101",
            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
          ],
          "sequence": 4294967295
        },
        {
          "txid": "e137c61946489c3eb4a90b02b71d56ef69c73f89074eeb0379c82f49725a78a0",
          "vout": 0,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001",
            "0396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d457"
          ],
          "sequence": 4294967295
        },
        {
          "txid": "0259472a025b07a90750045735ae1af3a7a1ff8341459042c36508c5a654cd7d",
          "vout": 1,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d63401",
            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
          ],
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 0.02920000,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_HASH160 d1c71b4df72064844eec341c86dc68cf81b9c2ec OP_EQUAL",
            "hex": "a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87",
            "address": "2NCNRjYqKz6j377wA328zjTqRGWBR59ygz1",
            "type": "scripthash"
          }
        },
        {
          "value": 0.00050666,
          "n": 1,
          "scriptPubKey": {
            "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
            "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
            "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
            "type": "witness_v0_keyhash"
          }
        }
      ],
      "fee": 0.00011200,
      "hex": "0100000000010386fe743a8db99cd6db255f8505d9e20e67e03edbd411874816382415a053b1120100000000ffffffffa0785a72492fc87903eb4e07893fc769ef561db7020ba9b43e9c484619c637e10000000000ffffffff7dcd54a6c50865c34290454183ffa1a7f31aae3557045007a9075b022a4759020100000000ffffffff02408e2c000000000017a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87eac5000000000000160014f2aeff3fd69c70bcff9c0709cc3ed1521868538002483045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e1012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e00248304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001210396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d4570247304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d634012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e000000000"
    }
  ]
}

Verbose level 3

./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 3
Console output
{
  "hash": "000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5",
  "confirmations": 10,
  "height": 2063334,
  "version": 549453828,
  "versionHex": "20c00004",
  "merkleroot": "3215277e48a4af9b7593c0c3e7c992752255724294c89813d6e64b585dd08783",
  "time": 1628150913,
  "mediantime": 1628149483,
  "nonce": 282709097,
  "bits": "1942ec00",
  "difficulty": 64177845.58487042,
  "chainwork": "000000000000000000000000000000000000000000000558fbc2a80220ea0e44",
  "nTx": 2,
  "previousblockhash": "000000000000000bca86c2f4af44a962e63973a087f56d74fc895b4642f3f5fb",
  "nextblockhash": "000000000000000119b44a12b31fb2e1d2baa9ad5bb7419428f62cc77a4685f5",
  "strippedsize": 598,
  "size": 959,
  "weight": 2753,
  "tx": [
    {
      "txid": "f10ed21d238ce32aaa00384af709381e2ecf1e3914604b4f0fbd817b3477017c",
      "hash": "9a614c99fc94459d6a5901b4091576365def3a23e002d77e6d79fd153d533bf4",
      "version": 1,
      "size": 357,
      "vsize": 330,
      "weight": 1320,
      "locktime": 2524842225,
      "vin": [
        {
          "coinbase": "03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000",
          "txinwitness": [
            "0000000000000000000000000000000000000000000000000000000000000000"
          ],
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 0.09776825,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_DUP OP_HASH160 190f8ddccb511a66f0cfc9a33204d9287e65fdf7 OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "76a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac",
            "address": "mhoTpa5QLRPFKsH4DdWSp1mru5BkEEWvYR",
            "type": "pubkeyhash"
          }
        },
        {
          "value": 0.00000000,
          "n": 1,
          "scriptPubKey": {
            "asm": "OP_RETURN b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
            "hex": "6a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
            "type": "nulldata"
          }
        },
        {
          "value": 0.00000000,
          "n": 2,
          "scriptPubKey": {
            "asm": "OP_RETURN aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
            "hex": "6a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
            "type": "nulldata"
          }
        },
        {
          "value": 0.00000000,
          "n": 3,
          "scriptPubKey": {
            "asm": "OP_RETURN 52534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
            "hex": "6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
            "type": "nulldata"
          }
        }
      ],
      "hex": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5a03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000ffffffff04b92e9500000000001976a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac0000000000000000266a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df0000000000000000266a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c100000000000000002b6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f757301200000000000000000000000000000000000000000000000000000000000000000f1087e96"
    },
    {
      "txid": "6fcf360bade1cae884cb0d36dfb92455b7cfdc037cfbab75f86dfbfe28f08b3e",
      "hash": "891566037ba9d65bdc6bce5135d27d18607e7903979d8fa014d1f7118d618691",
      "version": 1,
      "size": 521,
      "vsize": 278,
      "weight": 1109,
      "locktime": 0,
      "vin": [
        {
          "txid": "12b153a015243816488711d4db3ee0670ee2d905855f25dbd69cb98d3a74fe86",
          "vout": 1,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "3045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e101",
            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
          ],
          "prevout": {
            "generated": false,
            "height": 2063323,
            "value": 0.00544519,
            "scriptPubKey": {
              "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
              "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
              "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
              "type": "witness_v0_keyhash",
              "addresses": [
                "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn"
              ],
              "reqSigs": 1
            }
          },
          "sequence": 4294967295
        },
        {
          "txid": "e137c61946489c3eb4a90b02b71d56ef69c73f89074eeb0379c82f49725a78a0",
          "vout": 0,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001",
            "0396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d457"
          ],
          "prevout": {
            "generated": false,
            "height": 2034020,
            "value": 0.01184228,
            "scriptPubKey": {
              "asm": "0 4aefc0691c23cddd7ac75d9ba3714e37c802088a",
              "hex": "00144aefc0691c23cddd7ac75d9ba3714e37c802088a",
              "address": "tb1qfthuq6guy0xa67k8tkd6xu2wxlyqyzy2ctc4fz",
              "type": "witness_v0_keyhash",
              "addresses": [
                "tb1qfthuq6guy0xa67k8tkd6xu2wxlyqyzy2ctc4fz"
              ],
              "reqSigs": 1
            }
          },
          "sequence": 4294967295
        },
        {
          "txid": "0259472a025b07a90750045735ae1af3a7a1ff8341459042c36508c5a654cd7d",
          "vout": 1,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d63401",
            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
          ],
          "prevout": {
            "generated": false,
            "height": 2007043,
            "value": 0.01253119,
            "scriptPubKey": {
              "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
              "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
              "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
              "type": "witness_v0_keyhash",
              "addresses": [
                "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn"
              ],
              "reqSigs": 1
            }
          },
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 0.02920000,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_HASH160 d1c71b4df72064844eec341c86dc68cf81b9c2ec OP_EQUAL",
            "hex": "a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87",
            "address": "2NCNRjYqKz6j377wA328zjTqRGWBR59ygz1",
            "type": "scripthash"
          }
        },
        {
          "value": 0.00050666,
          "n": 1,
          "scriptPubKey": {
            "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
            "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
            "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
            "type": "witness_v0_keyhash"
          }
        }
      ],
      "fee": 0.00011200,
      "hex": "0100000000010386fe743a8db99cd6db255f8505d9e20e67e03edbd411874816382415a053b1120100000000ffffffffa0785a72492fc87903eb4e07893fc769ef561db7020ba9b43e9c484619c637e10000000000ffffffff7dcd54a6c50865c34290454183ffa1a7f31aae3557045007a9075b022a4759020100000000ffffffff02408e2c000000000017a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87eac5000000000000160014f2aeff3fd69c70bcff9c0709cc3ed1521868538002483045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e1012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e00248304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001210396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d4570247304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d634012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e000000000"
    }
  ]
}

REST

curl -H "content-type:text/plain;" http://127.0.0.1:18332/rest/block/000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5.json
Console output
{
  "hash": "000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5",
  "confirmations": 11,
  "height": 2063334,
  "version": 549453828,
  "versionHex": "20c00004",
  "merkleroot": "3215277e48a4af9b7593c0c3e7c992752255724294c89813d6e64b585dd08783",
  "time": 1628150913,
  "mediantime": 1628149483,
  "nonce": 282709097,
  "bits": "1942ec00",
  "difficulty": 64177845.58487042,
  "chainwork": "000000000000000000000000000000000000000000000558fbc2a80220ea0e44",
  "nTx": 2,
  "previousblockhash": "000000000000000bca86c2f4af44a962e63973a087f56d74fc895b4642f3f5fb",
  "nextblockhash": "000000000000000119b44a12b31fb2e1d2baa9ad5bb7419428f62cc77a4685f5",
  "strippedsize": 598,
  "size": 959,
  "weight": 2753,
  "tx": [
    {
      "txid": "f10ed21d238ce32aaa00384af709381e2ecf1e3914604b4f0fbd817b3477017c",
      "hash": "9a614c99fc94459d6a5901b4091576365def3a23e002d77e6d79fd153d533bf4",
      "version": 1,
      "size": 357,
      "vsize": 330,
      "weight": 1320,
      "locktime": 2524842225,
      "vin": [
        {
          "coinbase": "03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000",
          "txinwitness": [
            "0000000000000000000000000000000000000000000000000000000000000000"
          ],
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 0.09776825,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_DUP OP_HASH160 190f8ddccb511a66f0cfc9a33204d9287e65fdf7 OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "76a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac",
            "address": "mhoTpa5QLRPFKsH4DdWSp1mru5BkEEWvYR",
            "type": "pubkeyhash"
          }
        },
        {
          "value": 0,
          "n": 1,
          "scriptPubKey": {
            "asm": "OP_RETURN b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
            "hex": "6a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df",
            "type": "nulldata"
          }
        },
        {
          "value": 0,
          "n": 2,
          "scriptPubKey": {
            "asm": "OP_RETURN aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
            "hex": "6a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c1",
            "type": "nulldata"
          }
        },
        {
          "value": 0,
          "n": 3,
          "scriptPubKey": {
            "asm": "OP_RETURN 52534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
            "hex": "6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f7573",
            "type": "nulldata"
          }
        }
      ],
      "hex": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5a03e67b1f04819c0b612f64656275672e636f6d2ffabe6d6d5647e44d08c48adec0ee855a3e78909f300bc4a4f9b79b01167ad2d107747c3501000000000000002c6c0d02af403792e06d14248417542f120093c2020000000000ffffffff04b92e9500000000001976a914190f8ddccb511a66f0cfc9a33204d9287e65fdf788ac0000000000000000266a24b9e11b6d0e9243317b288d087de11b8e6ef80f7c2103f4de492da071b36caa92112c85df0000000000000000266a24aa21a9ed863dde47b2d6f490300e63cb1db36a41a47052956ac4eb40e17a9d8e15d694c100000000000000002b6a2952534b424c4f434b3af72ef02a50ecbfc6f9e6e464c57881bc23da25fbf5254088f7e68366001f757301200000000000000000000000000000000000000000000000000000000000000000f1087e96"
    },
    {
      "txid": "6fcf360bade1cae884cb0d36dfb92455b7cfdc037cfbab75f86dfbfe28f08b3e",
      "hash": "891566037ba9d65bdc6bce5135d27d18607e7903979d8fa014d1f7118d618691",
      "version": 1,
      "size": 521,
      "vsize": 278,
      "weight": 1109,
      "locktime": 0,
      "vin": [
        {
          "txid": "12b153a015243816488711d4db3ee0670ee2d905855f25dbd69cb98d3a74fe86",
          "vout": 1,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "3045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e101",
            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
          ],
          "prevout": {
            "generated": false,
            "height": 2063323,
            "value": 0.00544519,
            "scriptPubKey": {
              "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
              "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
              "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
              "type": "witness_v0_keyhash",
              "addresses": [
                "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn"
              ],
              "reqSigs": 1
            }
          },
          "sequence": 4294967295
        },
        {
          "txid": "e137c61946489c3eb4a90b02b71d56ef69c73f89074eeb0379c82f49725a78a0",
          "vout": 0,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001",
            "0396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d457"
          ],
          "prevout": {
            "generated": false,
            "height": 2034020,
            "value": 0.01184228,
            "scriptPubKey": {
              "asm": "0 4aefc0691c23cddd7ac75d9ba3714e37c802088a",
              "hex": "00144aefc0691c23cddd7ac75d9ba3714e37c802088a",
              "address": "tb1qfthuq6guy0xa67k8tkd6xu2wxlyqyzy2ctc4fz",
              "type": "witness_v0_keyhash",
              "addresses": [
                "tb1qfthuq6guy0xa67k8tkd6xu2wxlyqyzy2ctc4fz"
              ],
              "reqSigs": 1
            }
          },
          "sequence": 4294967295
        },
        {
          "txid": "0259472a025b07a90750045735ae1af3a7a1ff8341459042c36508c5a654cd7d",
          "vout": 1,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d63401",
            "02b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e0"
          ],
          "prevout": {
            "generated": false,
            "height": 2007043,
            "value": 0.01253119,
            "scriptPubKey": {
              "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
              "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
              "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
              "type": "witness_v0_keyhash",
              "addresses": [
                "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn"
              ],
              "reqSigs": 1
            }
          },
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 0.0292,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_HASH160 d1c71b4df72064844eec341c86dc68cf81b9c2ec OP_EQUAL",
            "hex": "a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87",
            "address": "2NCNRjYqKz6j377wA328zjTqRGWBR59ygz1",
            "type": "scripthash"
          }
        },
        {
          "value": 0.00050666,
          "n": 1,
          "scriptPubKey": {
            "asm": "0 f2aeff3fd69c70bcff9c0709cc3ed15218685380",
            "hex": "0014f2aeff3fd69c70bcff9c0709cc3ed15218685380",
            "address": "tb1q72h0707kn3cteluuquyuc0k32gvxs5uqawmvpn",
            "type": "witness_v0_keyhash"
          }
        }
      ],
      "fee": 0.000112,
      "hex": "0100000000010386fe743a8db99cd6db255f8505d9e20e67e03edbd411874816382415a053b1120100000000ffffffffa0785a72492fc87903eb4e07893fc769ef561db7020ba9b43e9c484619c637e10000000000ffffffff7dcd54a6c50865c34290454183ffa1a7f31aae3557045007a9075b022a4759020100000000ffffffff02408e2c000000000017a914d1c71b4df72064844eec341c86dc68cf81b9c2ec87eac5000000000000160014f2aeff3fd69c70bcff9c0709cc3ed1521868538002483045022100e45dd0be123e8edc98780e8fb1746cd5449d18399818052b66e8ae5fed26b0c502205e971594f3198009a436416c88f4aeea96beb07c713b71a60ffc043996da36e1012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e00248304502210083212c58e557e4b9b31bc9788bc3d08af280ea4b0376c00f54231f4fc6afd80e0220140601b13356014c924bca99ff0eba14ee200af496f9c9716bdd087023cbf1b001210396b46245502c3011f8e1b8b19aa9e8a40fff3153e225f619f57297914d93d4570247304402201d1bae75003e8986346c6df5aabe4ff820651cdc3c30038e3c2937c0393a70e30220528ac716e5e480b830e4b742c451b85cf4afbf53b20b982adf1b83423c79d634012102b90ee04fcba937c82b5a45b7f0fff4fbf6f1f4de2d152a16db94d31b40f352e000000000"
    }
  ]
}

Copy link
Contributor

@kiminuo kiminuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -1017,7 +1025,16 @@ static RPCHelpMan getblock()
return strHex;
}

return blockToJSON(block, tip, pblockindex, verbosity >= 2);
TxVerbosity block_to_json_verbosity;
Copy link
Contributor

@kiminuo kiminuo Aug 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The name block_to_json_verbosity seems long and it does not add any more meaning than just tx_verbosity, imho.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank u

@@ -20,6 +20,12 @@ class uint256;
class UniValue;
class CTxUndo;

enum class TxVerbosity {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some enum classes have these nice doxygen comments:

enum class BlockValidationResult {
Maybe it is worth adding here too.

@@ -312,6 +312,16 @@ def run_test(self):
if 'coinbase' not in tx['vin'][0]}
assert_equal(non_coinbase_txs, set(txs))

# Verify that the non-coinbase tx has "prevout" field set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
# Verify that the non-coinbase tx has "prevout" field set
# Verify that the non-coinbase tx has "prevout" key set

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

Comment on lines +320 to +321
prevout = vin["prevout"]
assert_equal(prevout["generated"], False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
prevout = vin["prevout"]
assert_equal(prevout["generated"], False)
assert_equal(vin["prevout"]["generated"], False)

def assert_vin_contains_prevout(verbosity):
block = node.getblock(blockhash, verbosity)
tx = block["tx"][1]
total_vin = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be more like:

Suggested change
total_vin = 0
total_vin = Decimal("0.00000000")


for (size_t i = 0; i < block.vtx.size(); ++i) {
const CTransactionRef& tx = block.vtx.at(i);
// coinbase transaction (i == 0) doesn't have undo data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
// coinbase transaction (i == 0) doesn't have undo data
// coinbase transaction (i.e. i == 0) doesn't have undo data


case TxVerbosity::SHOW_DETAILS_AND_PREVOUT:
UniValue o_script_pub_key(UniValue::VOBJ);
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* includeHex */ true, /* include_addresses */ true);
Copy link
Contributor

@kiminuo kiminuo Aug 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* includeHex */ true, /* include_addresses */ true);
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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is adding new output, I think it should probably just be a constant false here, actually.

@kiminuo
Copy link
Contributor

kiminuo commented Aug 8, 2021

@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:

./bitcoin-cli -testnet getblock

reports for me:

Console output
error code: -1
error message:
getblock "blockhash" ( verbosity )

If verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.
If verbosity is 1, returns an Object with information about block <hash>.
If verbosity is 2, returns an Object with information about block <hash> and information about each transaction.
If verbosity is 3, returns an Object with information about block <hash> and information about each transaction, including prevout information for inputs (only for unpruned blocks in the current best chain).

Arguments:
1. blockhash    (string, required) The block hash
2. verbosity    (numeric, optional, default=1) 0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data

Result (for verbosity = 0):
"hex"    (string) A string that is serialized, hex-encoded data for block 'hash'

Result (for verbosity = 1):
{                                 (json object)
  "hash" : "hex",                 (string) the block hash (same as provided)
  "confirmations" : n,            (numeric) The number of confirmations, or -1 if the block is not on the main chain
  "size" : n,                     (numeric) The block size
  "strippedsize" : n,             (numeric) The block size excluding witness data
  "weight" : n,                   (numeric) The block weight as defined in BIP 141
  "height" : n,                   (numeric) The block height or index
  "version" : n,                  (numeric) The block version
  "versionHex" : "hex",           (string) The block version formatted in hexadecimal
  "merkleroot" : "hex",           (string) The merkle root
  "tx" : [                        (json array) The transaction ids
    "hex",                        (string) The transaction id
    ...
  ],
  "time" : xxx,                   (numeric) The block time expressed in UNIX epoch time
  "mediantime" : xxx,             (numeric) The median block time expressed in UNIX epoch time
  "nonce" : n,                    (numeric) The nonce
  "bits" : "hex",                 (string) The bits
  "difficulty" : n,               (numeric) The difficulty
  "chainwork" : "hex",            (string) Expected number of hashes required to produce the chain up to this block (in hex)
  "nTx" : n,                      (numeric) The number of transactions in the block
  "previousblockhash" : "hex",    (string, optional) The hash of the previous block (if available)
  "nextblockhash" : "hex"         (string, optional) The hash of the next block (if available)
}

Result (for verbosity = 2):
{                   (json object)
  ...,              Same output as verbosity = 1
  "tx" : [          (json array)
    {               (json object)
      ...,          The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 "tx" result
      "fee" : n     (numeric) The transaction fee in BTC, omitted if block undo data is not available
    },
    ...
  ]
}

Result (for verbosity = 3):
{                                        (json object)
  ...,                                   Same output as verbosity = 2
  "tx" : [                               (json array)
    {                                    (json object)
      "vin" : [                          (json array)
        {                                (json object)
          ...,                           The same output as verbosity = 2
          "prevout" : {                  (json object)
            "generated" : true|false,    (boolean) Coinbase or not
            "height" : n,                (numeric) The height of the prevout
            "value" : n,                 (numeric) The value in BTC
            "scriptPubKey" : {           (json object)
              "asm" : "str",             (string) The asm
              "hex" : "str",             (string) The hex
              "reqSigs" : n,             (numeric, optional) (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures
              "type" : "str",            (string) The type, eg 'pubkeyhash'
              "address" : "str",         (string, optional) bitcoin address (only if a well-defined address exists)
              "addresses" : [            (json array, optional) (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses
                "str",                   (string) bitcoin address
                ...
              ]
            }
          }
        },
        ...
      ]
    },
    ...
  ]
}

Examples:
> bitcoin-cli getblock "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"
> 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.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK 72dbe98

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 (#21245 (comment)), more detailled "prevout" checking w.r.t. to coinbase/non-coinbase txs (#21245 (comment)), RPC help improvement (#21245 (comment))) 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?

@fyquah
Copy link
Contributor Author

fyquah commented Aug 20, 2021

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 )

@fanquake
Copy link
Member

Is there anything that is blocking merge at this point?

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

@luke-jr
Copy link
Member

luke-jr commented Aug 25, 2021

I would re-ACK except for #21245 (comment)

@kiminuo
Copy link
Contributor

kiminuo commented Aug 25, 2021

@fyquah I think #21245 (comment) 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).

@kiminuo
Copy link
Contributor

kiminuo commented Sep 6, 2021

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

(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.)

@fanquake
Copy link
Member

fanquake commented Sep 8, 2021

Closing this for now that #22918 is open.

@fanquake fanquake closed this Sep 8, 2021
laanwj added a commit to bitcoin-core/gui that referenced this pull request Oct 19, 2021
…PC call (#21245 modified)

5c34507 core_write: Rename calculate_fee to have_undo for clarity (fyquah)
8edf620 release-notes: Add release note about getblock verbosity level 3. (fyquah)
459104b rest: Add test for prevout fields in getblock (fyquah)
4330af6 rpc: Add test for level 3 verbosity getblock rpc call. (fyquah)
51dbc16 rpc: Add level 3 verbosity to getblock RPC call. (fyquah)
3cc9534 rpc: Replace boolean argument for tx details with enum class. (fyquah)

Pull request description:

  Author of #21245 expressed [time issues](bitcoin/bitcoin#21245 (comment)) 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 ](bitcoin/bitcoin#21245 (comment)) 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

  * kiminuo/bitcoin@b0bf4f2 - I can include even this commit to this PR if deemed useful or I can leave it for a follow-up PR. See bitcoin/bitcoin#21245 (comment) 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:
    ACK 5c34507
  meshcollider:
    utACK 5c34507
  theStack:
    ACK 5c34507 👘
  promag:
    Concept ACK 5c34507

Tree-SHA512: bbff120d8fd76e617b723b102b0c606e0d8eb27f21c631d5f4cdab0892137c4bc7c65b1df144993405f942c91be47a26e80480102af55bff22621c19f518aea3
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 19, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants