Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcserver: add parity with bitcoind for validateaddress #1613

Merged
merged 1 commit into from
Aug 31, 2020

Conversation

onyb
Copy link
Collaborator

@onyb onyb commented Aug 9, 2020

What is this about?

Updated the rpcserver handler for validateaddress JSON-RPC command to have parity with the bitcoind 0.20.0 interface.

The new fields included are - isscript, iswitness, witness_version, and witness_program. The scriptPubKey field has been left out since it requires wallet access.

This update has no impact on the rpcclient.ValidateAddress method, which uses the btcjson.ValidateAddressWalletResult type for modelling the response from bitcoind.

How to test?

Unfortunately, we lack a proper framework to write rpcserver tests, so here's you can test this PR:

Prepare

$ go build .
$ ./btcd --testnet --rpcuser=aaaa --rpcpass=bbbb

In another tab,

$ cd cmd/btcctl
$ go build .

P2PKH valid

$ ./btcctl --testnet --rpcuser=aaaa --rpcpass=bbbb validateaddress mkpZhYtJu2r87Js3pDiWJDmPte2NRZ8bJV
{
  "isvalid": true,
  "address": "mkpZhYtJu2r87Js3pDiWJDmPte2NRZ8bJV",
  "isscript": false,
  "iswitness": false
}

P2SH-P2WPKH valid

$ ./btcctl --testnet --rpcuser=aaaa --rpcpass=bbbb validateaddress 2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp
{
  "isvalid": true,
  "address": "2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp",
  "isscript": true,
  "iswitness": false
}

P2WPKH valid

$ ./btcctl --testnet --rpcuser=aaaa --rpcpass=bbbb validateaddress tb1qkwgskuzmmwwvqajnyr7yp9hgvh5y45kg8wvdmd
{
  "isvalid": true,
  "address": "tb1qkwgskuzmmwwvqajnyr7yp9hgvh5y45kg8wvdmd",
  "isscript": false,
  "iswitness": true,
  "witness_version": 0,
  "witness_program": "b3910b705bdb9cc0765320fc4096e865e84ad2c8"
}

Invalid address

$ ./btcctl --testnet --rpcuser=aaaa --rpcpass=bbbb validateaddress deadbeef
{
  "isvalid": false
}

Invalid network

$ ./btcctl --testnet --rpcuser=aaaa --rpcpass=bbbb validateaddress 1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX
{
  "isvalid": false
}

rpcserver.go Show resolved Hide resolved
Copy link
Collaborator

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

The code looks good to me, I tested as well and did not have any issues.

btcjson/chainsvrresults.go Show resolved Hide resolved
@onyb onyb force-pushed the validateaddress-chain branch 2 times, most recently from 9a2b594 to 77d239c Compare August 24, 2020 18:39
Updated the rpcserver handler for validateaddress JSON-RPC command to
have parity with the bitcoind 0.20.0 interface.

The new fields included are - isscript, iswitness, witness_version, and
witness_program. The scriptPubKey field has been left out since it
requires wallet access.

This update has no impact on the rpcclient.ValidateAddress method,
which uses the btcjson.ValidateAddressWalletResult type for modelling
the response from bitcoind.
Copy link
Collaborator

@jakesylvestre jakesylvestre left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Copy link
Member

@jcvernaleo jcvernaleo left a comment

Choose a reason for hiding this comment

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

OK

@jcvernaleo jcvernaleo merged commit 7145eef into btcsuite:master Aug 31, 2020
@onyb onyb deleted the validateaddress-chain branch September 26, 2020 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants