Skip to content

Conversation

achow101
Copy link
Member

This PR makes a new RPC command called getaddressinfo which relies on the wallet. It contains all of validateaddress's address info stuff. Those parts in validateaddress have been marked as deprecated. The tests have been updated to use getaddressinfo except the disablewallet test which is the only test that actually uses validateaddress to validate an address.

@laanwj
Copy link
Member

laanwj commented Jun 14, 2017

Concept ACK. Makes a lot of sense to move the wallet-specific information to a separate RPC.

Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

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

Concept ACK.

@sipa
Copy link
Member

sipa commented Jun 16, 2017

Currently this duplicates a singificant amount of code. Would it be possible to abstract out the 'info' part of getaddressinfo, and then call that from validateaddress as well (temporarily, until removed)?

@achow101
Copy link
Member Author

@sipa Apparently, no, this is not possible. My attempt at doing so has resulted in a linker failure. Apparently there is some makefile problems with that. https://github.com/achow101/bitcoin/tree/getaddressinfo-broken is the branch with the duplication removed, but there is a linker error with IsMine calls. The full build error is here: https://gist.github.com/achow101/0f0e2d9e75d9d77132ab83a7605f2377

@achow101
Copy link
Member Author

On second thought, I think I fixed the problem.

@achow101 achow101 force-pushed the getaddressinfo branch 2 times, most recently from a64867b to 2d93b39 Compare June 20, 2017 18:43
@sipa
Copy link
Member

sipa commented Jun 20, 2017

I believe you can do:

 bitcoind_LDADD = \
   $(LIBBITCOIN_SERVER) \
+  $(LIBBITCOIN_WALLET) \
   $(LIBBITCOIN_COMMON) \
   $(LIBUNIVALUE) \
   $(LIBBITCOIN_UTIL) \
-  $(LIBBITCOIN_WALLET) \
   $(LIBBITCOIN_ZMQ) \

in Makefile.am.

Then the _ismine code can move from wallet to common (which I think belongs there, as signing code is already in common too).

@achow101
Copy link
Member Author

@sipa I did that in my latest commit, but it seems that travis doesn't like it.

@laanwj
Copy link
Member

laanwj commented Jun 24, 2017

Then the _ismine code can move from wallet to common (which I think belongs there, as signing code is already in common too).

From what I remember it was already moved in the other direction at some point for the same reason.
The circular dependency between _wallet and _server remains a problem.
We'll need to solve #7965 to get rid of it.
Unfortunately, this is part of that...

@jnewbery
Copy link
Contributor

needs rebase

@achow101
Copy link
Member Author

rebased

@achow101 achow101 force-pushed the getaddressinfo branch 2 times, most recently from a3932cc to 47fd5fc Compare August 17, 2017 01:19
@jnewbery
Copy link
Contributor

jnewbery commented Sep 1, 2017

Concept ACK. This PR is currently difficult to review because there are broken intermediate commits, commits which reverse previous commits, random style changes in unconnected commits, etc. Are you able to tidy this up to make it easier to review? If not, I'm happy to take this PR and tidy it up.

My high-level feedback is that we should hide the deprecated fields in validateaddress behind a command-line argument (similar to #11031). The ismine move to libbitcoin_common seems fine to me.

@achow101 achow101 force-pushed the getaddressinfo branch 3 times, most recently from f76d026 to ad412dd Compare September 5, 2017 17:39
@achow101
Copy link
Member Author

achow101 commented Sep 5, 2017

Rebased and tidied up

@jnewbery
Copy link
Contributor

jnewbery commented Sep 5, 2017

Travis is failing on invalid scripted diff check.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

A few nits inline. I think you could drop the third commit by making your scripted diff more focussed:

find ./test/functional -path '*py' -not -path ./test/functional/disablewallet.py -exec sed -i'' -e 's/validateaddress/getaddressinfo/g' {} \;

note that sed syntax differs between BSD and GNU. You'll need to use sed -i '' (space between i and empty string) on BSD.

(this also has the benefit of not breaking git bisect)

I still think it's a good idea to hide the deprecated functionality behind a command-line argument to make removing it in the next version easier.

src/rpc/misc.cpp Outdated
}
try {
ret.pushKVs(getaddressinfo(request));
} catch (UniValue e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this. Why do we swallow the RPC_METHOD_NOT_FOUND error?

Can you add a comment explaining this?

Copy link
Member Author

@achow101 achow101 Sep 5, 2017

Choose a reason for hiding this comment

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

That is swallowed in the event that -disablewallet is used; getaddressinfo will return RPC_METHOD_NOT_FOUND but validateaddress should still work and validate addresses.

I will add a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, I think it's preferable to test for wallet existence before calling getaddressinfo. The following should do it:

        if (!::vpwallets.empty()) {
            ret.pushKVs(getaddressinfo(request));
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;

if (request.fHelp || request.params.size() != 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: braces for if block

"1. \"address\" (string, required) The bitcoin address to get the information of.\n"
"\nResult:\n"
"{\n"
" \"address\" : \"address\", (string) The bitcoin address validated\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Help text seems to be missing result fields, including at least script, hex, addresses, sigsrequired.

Copy link
Member Author

Choose a reason for hiding this comment

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

Forgot to say that this was addressed.

src/rpc/util.cpp Outdated
return UniValue(UniValue::VOBJ);
}

UniValue operator()(const CKeyID &keyID) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, const CKeyID& keyID. { on new line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@achow101 achow101 force-pushed the getaddressinfo branch 2 times, most recently from 5f4e02f to baef775 Compare February 15, 2018 23:32
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Lightly tested ACK. Please consider the following comments.


UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); }

UniValue operator()(const CKeyID &keyID) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

& before space and { new line.

return obj;
}

UniValue operator()(const CScriptID &scriptID) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

& before space and { new line.

src/rpc/util.cpp Outdated
public:
explicit DescribeAddressVisitor() {}

UniValue operator()(const CNoDestination &dest) const
Copy link
Contributor

Choose a reason for hiding this comment

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

& before space.

Copy link
Member

Choose a reason for hiding this comment

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

travis linter is complaining about trailing whitespace.... I don't know protocol if it matters but just reporting where the complaint is coming from


explicit DescribeWalletAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {}

UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); }
Copy link
Contributor

Choose a reason for hiding this comment

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

& before space.

ret.pushKV("iswatchonly", bool(mine & ISMINE_WATCH_ONLY));
UniValue detail = DescribeWalletAddress(pwallet, dest);
ret.pushKVs(detail);
if (pwallet->mapAddressBook.count(dest)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use find to avoid 2nd lookup below (unless you don't want to touch moved code).

CRIPEMD160 hasher;
uint160 hash;
hasher.Write(id.begin(), 32).Finalize(hash.begin());
if (pwallet && pwallet->GetCScript(CScriptID(hash), subscript)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In this context pwallet is valid so:

if (pwallet->GetCScript(CScriptID(hash), subscript)) {

ret.pushKV("hdmasterkeyid", meta->hdMasterKeyID.GetHex());
}
}
if (!::vpwallets.empty() && IsDeprecatedRPCEnabled("validateaddress")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why !::vpwallets.empty()? There is alwasy one wallet right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, you can run with -disablewallet which will disable wallets and thus vpwallets will be empty.

src/rpc/util.cpp Outdated
return UniValue(UniValue::VOBJ);
}

UniValue operator()(const CKeyID &keyID) const
Copy link
Contributor

Choose a reason for hiding this comment

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

& before space.

src/rpc/util.cpp Outdated
return obj;
}

UniValue operator()(const CScriptID &scriptID) const
Copy link
Contributor

Choose a reason for hiding this comment

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

& before space.

{
UniValue obj(UniValue::VOBJ);
CPubKey pubkey;
if (pwallet && pwallet->GetPubKey(CKeyID(id), pubkey)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In this context pwallet is valid so:

if (pwallet->GetPubKey(CKeyID(id), pubkey)) {

@jnewbery
Copy link
Contributor

@promag - personally, I'd generally discourage nits after a PR has been open for many months and been rebased/re-reviewed many times already. Adding additional churn and workload to the contributor and reviewers at this point seems borderline sadistic 🙂

(just my opinion though)

jnewbery and others added 3 commits February 16, 2018 12:09
Moves the parts of validateaddress which require the wallet into getaddressinfo
which is part of the wallet RPCs. Mark those parts of validateaddress which
require the wallet as deprecated.

Validateaddress will  call getaddressinfo
for the data that both share for right now.

Moves IsMine functions to libbitcoin_common and then links libbitcoin_wallet
before libbitcoin_common in order to prevent linker errors since IsMine is no
longer used in libbitcoin_server.
Change all instances of validateaddress to getaddressinfo since it seems that
no test actually uses validateaddress for actually validating addresses.

-BEGIN VERIFY SCRIPT-
find ./test/functional -path '*py' -not -path ./test/functional/wallet_disable.py -not -path ./test/functional/rpc_deprecated.py -not -path ./test/functional/wallet_address_types.py -exec sed -i'' -e 's/validateaddress/getaddressinfo/g' {} \;
-END VERIFY SCRIPT-
@achow101
Copy link
Member Author

Addressed some of @promag's nits. I don't really feel like fixing the other ones. It's also getting really tedious to do fix nits at this point, so I probably won't do so in the future for this PR.

@jnewbery
Copy link
Contributor

Tested ACK b22cce0. Travis failure looks unrelated.

Let's get this merged!

@sipa
Copy link
Member

sipa commented Feb 16, 2018

utACK b22cce0

I have a few minor improvements, but I'll submit them as a separate PR after merge, nothing worth holding this up for.

@promag
Copy link
Contributor

promag commented Feb 16, 2018

@jnewbery @achow101 sorry! didn't want to cause such pain :) I did report tested ACK.

@jonasschnelli
Copy link
Contributor

Tested ACK b22cce0

@jonasschnelli jonasschnelli merged commit b22cce0 into bitcoin:master Feb 17, 2018
jonasschnelli added a commit that referenced this pull request Feb 17, 2018
b22cce0 scripted-diff: validateaddress to getaddressinfo in tests (Andrew Chow)
b98bfc5 Create getaddressinfo RPC and deprecate parts of validateaddress (Andrew Chow)
1598f32 [rpc] Move DescribeAddressVisitor to rpc/util (John Newbery)
39633ec [rpc] split wallet and non-wallet parts of DescribeAddressVisitor (John Newbery)

Pull request description:

  This PR makes a new RPC command called `getaddressinfo` which relies on the wallet. It contains all of `validateaddress`'s address info stuff. Those parts in `validateaddress` have been marked as deprecated. The tests have been updated to use `getaddressinfo` except the `disablewallet` test which is the only test that actually uses `validateaddress` to validate an address.

Tree-SHA512: ce00ed0f2416200b8de1e0a75e8517c024be0b6153457d302c3879b3491cce28191e7c29aed08ec7d2eeeadc62918f5c43a7cb79cd2e4b6d9291bd83ec31c852
tynes pushed a commit to tynes/bcoin that referenced this pull request Mar 16, 2019
updates validateaddress to match the changes
in bitcoind bitcoin/bitcoin#10583.
removes the fields ismine and iswatchonly, those
are things that a wallet would know, not a node.
adds segwit related fields
tynes pushed a commit to tynes/bcoin that referenced this pull request Mar 26, 2019
updates validateaddress to match the changes
in bitcoind bitcoin/bitcoin#10583.
removes the fields ismine and iswatchonly, those
are things that a wallet would know, not a node.
adds segwit related fields, witness_version and
witness_program. test changes to the node rpc method
validateaddress with p2pkh, p2sh, p2wpkh and p2wsh addresses
tynes pushed a commit to tynes/hsd that referenced this pull request Apr 2, 2019
This PR updates the node rpc validateaddress to
better seperate the wallet and the node. The rpc
was returning ismine and iswatch only. These values
were moved to the wallet rpc method getaddressinfo.
This corresponds to a change in bitcoind and bcoin.

The updated validateaddress rpc returns the values:

- isvalid
- address
- ismine
- iswatchonly
- isscript
- isspendable
- witness_version
- witness_program

See PR in bcoin: bcoin-org/bcoin#731
See PR in bitcoind: bitcoin/bitcoin#10583
boymanjor pushed a commit to handshake-org/hsd that referenced this pull request Apr 9, 2019
This PR updates the node rpc validateaddress to
better seperate the wallet and the node. The rpc
was returning ismine and iswatch only. These values
were moved to the wallet rpc method getaddressinfo.
This corresponds to a change in bitcoind and bcoin.

The updated validateaddress rpc returns the values:

- isvalid
- address
- ismine
- iswatchonly
- isscript
- isspendable
- witness_version
- witness_program

See PR in bcoin: bcoin-org/bcoin#731
See PR in bitcoind: bitcoin/bitcoin#10583
tuxcanfly pushed a commit to tuxcanfly/bcoin that referenced this pull request Apr 19, 2019
updates validateaddress to match the changes
in bitcoind bitcoin/bitcoin#10583.
removes the fields ismine and iswatchonly, those
are things that a wallet would know, not a node.
adds segwit related fields, witness_version and
witness_program. test changes to the node rpc method
validateaddress with p2pkh, p2sh, p2wpkh and p2wsh addresses
xdustinface added a commit to dashpay/dash that referenced this pull request Dec 17, 2020
…taddressinfo (#3880)

* [rpc] split wallet and non-wallet parts of DescribeAddressVisitor

* [rpc] Move DescribeAddressVisitor to rpc/util

* Create getaddressinfo RPC and deprecate parts of validateaddress

Moves the parts of validateaddress which require the wallet into getaddressinfo
which is part of the wallet RPCs. Mark those parts of validateaddress which
require the wallet as deprecated.

Validateaddress will  call getaddressinfo
for the data that both share for right now.

Moves IsMine functions to libbitcoin_common and then links libbitcoin_wallet
before libbitcoin_common in order to prevent linker errors since IsMine is no
longer used in libbitcoin_server.

* scripted-diff: validateaddress to getaddressinfo in tests

Change all instances of validateaddress to getaddressinfo since it seems that
no test actually uses validateaddress for actually validating addresses.

-BEGIN VERIFY SCRIPT-
find ./test/functional -path '*py' -not -path ./test/functional/wallet_disable.py -not -path ./test/functional/rpc_deprecated.py -not -path ./test/functional/wallet_address_types.py -exec sed -i'' -e 's/validateaddress/getaddressinfo/g' {} \;
-END VERIFY SCRIPT-

* wallet: Add missing description of "hdchainid"

* Update src/wallet/rpcwallet.cpp

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>

Co-authored-by: John Newbery <john@johnnewbery.com>
Co-authored-by: Andrew Chow <achow101-github@achow101.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
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.