RPC: getblock returns coinbase scriptsig #10385

pull pinheadmz wants to merge 1 commits into bitcoin:master from pinheadmz:cbtext changing 1 files +2 −0
  1. pinheadmz commented at 11:22 PM on May 10, 2017: member

    Miners are putting lots of exciting information in coinbase scriptSig's these days... Currently to get that string via RPC two calls are required: first getblock to get the list of all transactions in the block, and then getrawtransaction with the coinbase transaction hash. Of course this only works if your node is running with txindex=1, which is a lot of overhead if all you're interested in is coinbase strings. This PR makes it easy:

    $ bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f | grep coinbase
      "coinbase": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73",
    $ echo 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73 | xxd -r -p
    ??EThe Times 03/Jan/2009 Chancellor on brink of second bailout for banks
    
  2. init getblock returns coinbase scriptsig 69a0e0a2e2
  3. fanquake added the label RPC/REST/ZMQ on May 11, 2017
  4. sdaftuar commented at 12:33 PM on May 11, 2017: member

    I believe this would be implemented by #8704?

  5. pinheadmz commented at 4:29 PM on May 11, 2017: member

    Oh huh! You know I saw the extra "verbose" lines in the code and thought to myself "huh I didn't know that was a new feature" but didn't think that it actually solves my problem!

  6. laanwj commented at 5:40 PM on May 17, 2017: member

    but didn't think that it actually solves my problem!

    What are you missing? After #8704:

    $ src/bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f 2
    ...
          "vin": [
            {
              "coinbase": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73",
    ...
    
  7. pinheadmz commented at 5:43 PM on May 17, 2017: member

    @laanwj I DIDN'T think, this is a facepalm. I saw the code from #8704, said "huh" out loud and went forward with this PR anyway, feel free to close.

  8. laanwj commented at 5:51 PM on May 17, 2017: member

    It might still make sense to include the coinbase info at a lower verbosity level, as the verbosity=2 output can be huge, I don't know.

  9. pinheadmz commented at 6:07 PM on May 17, 2017: member

    Right, well the motivation is that miners are mining with clients that use the coinbase scriptSig as an "extra version" field. My application is just trying to sort out what's going on out there, so I don't need the RPC call to return 1MB of json. I just want to see the version bits and the "extra version".

  10. jnewbery commented at 6:06 PM on May 23, 2017: member

    There are a couple of ways to get the full coinbase transaction:

    • getblock() with the verbosity level set to 2
    • (once #10275 is merged) getblock() with verbosity level set to 1, and then getrawtransaction() with the txid and blockhash specified.

    I don't think adding a new option to return only the coinbase transaction from getblock() is necessary, but I'm not completely opposed. Just please don't add another 'verbosity level' but instead make this an explicit option.

  11. pinheadmz commented at 6:38 PM on May 23, 2017: member

    @jnewbery Isn't the problem with getrawtransaction() is that it requires txindex=1? You're right about getblock with verbose=2, though -- I didn't realize that was in the code already when I started my PR. However, since miners are putting messages in the coinbase scriptSig, it is useful at least to my own application to include that string (not even the whole transaction, just the scriptSig) as part of the top-level return values along with version and size when describing a block.

  12. sipa commented at 6:39 PM on May 23, 2017: member

    I don't think this use case warrants an extra RPC/mode. You can just use verbose=2 and look at the coinbase tx of the output.

  13. jnewbery commented at 6:40 PM on May 23, 2017: member

    Isn't the problem with getrawtransaction() is that it requires txindex=1

    Please see #10275

  14. pinheadmz commented at 6:44 PM on May 23, 2017: member

    Cool I will close

  15. pinheadmz closed this on May 23, 2017

  16. MarcoFalke locked this on Sep 8, 2021

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: 2026-04-13 15:15 UTC

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