-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[RPC] Split part of validateaddress into getaddressinfo #10583
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
Conversation
Concept ACK. Makes a lot of sense to move the wallet-specific information to a separate RPC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK.
Currently this duplicates a singificant amount of code. Would it be possible to abstract out the 'info' part of |
@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 |
On second thought, I think I fixed the problem. |
a64867b
to
2d93b39
Compare
I believe you can do: bitcoind_LDADD = \
$(LIBBITCOIN_SERVER) \
+ $(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_COMMON) \
$(LIBUNIVALUE) \
$(LIBBITCOIN_UTIL) \
- $(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_ZMQ) \ in Then the _ismine code can move from wallet to common (which I think belongs there, as signing code is already in common too). |
@sipa I did that in my latest commit, but it seems that travis doesn't like it. |
From what I remember it was already moved in the other direction at some point for the same reason. |
needs rebase |
40a069f
to
300808b
Compare
rebased |
a3932cc
to
47fd5fc
Compare
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 |
f76d026
to
ad412dd
Compare
Rebased and tidied up |
Travis is failing on invalid scripted diff check. |
ad412dd
to
7c3e7ac
Compare
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/wallet/rpcwallet.cpp
Outdated
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) | ||
return NullUniValue; | ||
|
||
if (request.fHelp || request.params.size() != 1) |
There was a problem hiding this comment.
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
src/wallet/rpcwallet.cpp
Outdated
"1. \"address\" (string, required) The bitcoin address to get the information of.\n" | ||
"\nResult:\n" | ||
"{\n" | ||
" \"address\" : \"address\", (string) The bitcoin address validated\n" |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
5f4e02f
to
baef775
Compare
There was a problem hiding this 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.
src/wallet/rpcwallet.cpp
Outdated
|
||
UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); } | ||
|
||
UniValue operator()(const CKeyID &keyID) const { |
There was a problem hiding this comment.
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/wallet/rpcwallet.cpp
Outdated
return obj; | ||
} | ||
|
||
UniValue operator()(const CScriptID &scriptID) const { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&
before space.
There was a problem hiding this comment.
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
src/wallet/rpcwallet.cpp
Outdated
|
||
explicit DescribeWalletAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {} | ||
|
||
UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); } |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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")) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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)) {
@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) |
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-
baef775
to
b22cce0
Compare
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. |
Tested ACK b22cce0. Travis failure looks unrelated. Let's get this merged! |
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. |
Tested ACK b22cce0 |
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
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
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
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
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
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
…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>
This PR makes a new RPC command called
getaddressinfo
which relies on the wallet. It contains all ofvalidateaddress
's address info stuff. Those parts invalidateaddress
have been marked as deprecated. The tests have been updated to usegetaddressinfo
except thedisablewallet
test which is the only test that actually usesvalidateaddress
to validate an address.