Add scriptPubKey field to validateaddress RPC call #4964

pull petertodd wants to merge 1 commits into bitcoin:master from petertodd:validateaddress-return-scriptpubkey changing 1 files +5 −0
  1. petertodd commented at 9:26 AM on September 23, 2014: contributor

    Handy to have quickly available, and a good pedagogical tool.

  2. Add scriptPubKey field to validateaddress RPC call 426a74ed3c
  3. BitcoinPullTester commented at 9:41 AM on September 23, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4964_426a74ed3c3c98b791a8445dd276e89fc5d6175e/ for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  4. laanwj added the label RPC on Sep 23, 2014
  5. laanwj commented at 9:28 AM on September 24, 2014: member

    Agree that this could be handy, but I don't think we should be adding more 'library-like' functionality to RPC (ie, stuff that doesn't actually require a running node), we're trying to move in the opposite direction.

  6. gmaxwell commented at 12:26 AM on October 9, 2014: contributor

    Really this isn't that much of a library call, I think. It consults the wallet. Current addresses are simple enough that a stateless library could do it, but something fancier might need the wallet. Having people unaware of scriptPubKey as a pubkey has certantly made it harder for people to understand the system.

  7. TheBlueMatt commented at 12:41 AM on October 9, 2014: member

    I'm not sure this isnt more something for bitcoin-tx.

  8. laanwj commented at 10:41 AM on October 9, 2014: member

    @gmaxwell validateaddress consults the wallet when it is built in; without wallet it's a pure library call. But I didn't mean to say that validateaddress is a library call, functionality to compute a scriptPubKey certainly is. @TheBlueMatt Agreed. Would be more something for an utility.

  9. laanwj commented at 10:46 AM on October 9, 2014: member

    Anyhow, if @gmaxwell thinks this is a good idea, I don't feel strongly about it either way, it's three lines of codes in a non-critical path. utACK.

  10. laanwj commented at 8:45 AM on October 10, 2014: member

    I've verified that this matches against python-bitcoinllib for both P2SH and legacy addresses, for example:

    >>> from bitcoin.wallet import CBitcoinAddress
    >>> binascii.b2a_hex(CBitcoinAddress('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy').to_scriptPubKey())
    'a914b472a266d0bd89c13706a4132ccfb16f7c3b9fcb87'
    
    $ src/bitcoin-cli -datadir=/store/tmp/testbtc validateaddress 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy
    {
        "isvalid" : true,
        "address" : "3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy",
        "scriptPubKey" : "a914b472a266d0bd89c13706a4132ccfb16f7c3b9fcb87",
        "ismine" : false
    }
    

    One nit: validateaddress can return a "pubkey" entry as well when the address is a receiving address in the wallet which is also a hex string. Could scriptPubKey versus pubkey cause (dangerous) confusion?

  11. petertodd commented at 10:12 AM on October 10, 2014: contributor

    @laanwj I think that bit of confusion is actually a good pedagogical point, and more importantly I can't see any way any code written to use the API could make that mistake.

  12. laanwj commented at 10:38 AM on October 10, 2014: member

    Making a pedagogical point is good, but not if it would cost someone a lot of money. I don't think that's a risk as the underlying data is a different type/structure, but I wanted to mention it. Trying to use a scriptPubKey as pubkey would get an OpenSSL error about invalid encoding (and thus an invalid transaction), and the other way around would get an invalid script (which at least fails the isCanonical check but probably more...).

  13. jgarzik merged this on Dec 31, 2014
  14. jgarzik closed this on Dec 31, 2014

  15. jgarzik referenced this in commit 95ecc0a857 on Dec 31, 2014
  16. jgarzik commented at 12:24 PM on December 31, 2014: contributor

    ACK

  17. 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