-
Notifications
You must be signed in to change notification settings - Fork 37.8k
rpc, wallet: Add listaddresses RPC #23019
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
7af0244
to
fdc4031
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
src/wallet/rpcwallet.cpp
Outdated
{RPCResult::Type::STR, "hdkeypath", "The BIP 32 HD path of the address"}, | ||
{RPCResult::Type::STR, "descriptor", "The address descriptor"}, | ||
{RPCResult::Type::BOOL, "internal", "The address is internal (change) or external (receive)"}, | ||
{RPCResult::Type::NUM, "amount", "Available amount at address"}, |
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.
Addresses don't hold funds. They only receive, never send.
Instead, it should just tally the total received ever.
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.
The code to count the total received is already available in the function. It can be done.
But address explorers in most software wallets, such as Electrum and Specter Desktop, only show the funds available to be spent at each address. I think the idea is to see how the UTXO values are distributed across the addresses (if there is any significant gap, for example).
Approach NACK I started reviewing, but I have some fundamental issues with the approach taken. I like the general idea, but this specific implementation has issues. First of all, why does this even need to take parameters? I don't see why a "starting index" or "ending index" need to be provided. We shouldn't need to derive addresses on the fly because they should already be in the wallet in some way. This really should use the address book, the keypool, and key metadata rather than re-deriving. Index just doesn't really make sense for what this RPC purports to do. This also ends up making assumptions about what addresses are receiving and change, depending on how they are derived. But that is not reliable, especially for wallets prior to the HD chain split. In fact, using this with such a wallet will result in an assertion failure, and that is just not acceptable. The correct thing is to use the wallet's built in change determining function(s) so that those that are listed as change actually correspond with the things that the wallet will see as change. Likewise, why is this limited to just the default address type? A wallet will typically have addresses of address types that are not the default. These should be output as well. Furthermore, this RPC appears to only work on HD wallets, which severely limits is usability. Many people do use non-HD wallets still, and I would expect something that just lists out the wallet's addresses is not limited to just HD wallets. |
b8f1be9
to
7260734
Compare
@achow101 thanks for detailed review. My original implementation used the keypool (for legacy wallets), m_wallet_descriptor (for descriptor wallets) and key metadata. But the problem is the following case: if the user wants to know some address whose index is greater than the keypool total (such as 2395th), an error would be generated. Deriving addresses solved this issue. The listaddresses RPC would work regardless of keypool size. Since the problem was in the approach, not in concept, I changed the code of this PR to the original version, that uses the keypool, m_wallet_descriptor and key metadata. if ((size_t) end_index >= setKeyPool->size()) {
auto s_end_index = strprintf("%u", end_index);
auto s_set_keypool_size = strprintf("%u", setKeyPool->size() - 1);
auto error_message = "Error: end_index (" + s_end_index + ") is greater than last keypool item (" + s_set_keypool_size + ").";
error = _(error_message.c_str());
return false;
} I didn't understand the reason to remove I also added address type as parameter. |
I don't think that is a situation we should support. It would mean that users could get addresses that are not currently being watched by the wallet. I think that there would be the expectation that the wallet is watching such an address and so any funds sent to them would appear in the wallet. But that would not be the case.
I think that it is completely reasonable to return such a large result. There could be options for verbosity, e.g. a non-verbose output is just the addresses, then verbose is with all of the additional information that this PR currently includes. We have many RPCs that will output a ton of data from the wallet, e.g. |
34ff480
to
420a878
Compare
f450f3f
to
39d734e
Compare
I removed the indexes and changed the code to use address book, the keypool, and key metadata. . Legacy wallet: The addresses from . Descriptor wallet: All the addresses are in the correct BIP32 derivation order, as it is possible to iterate over the Updated test information in PR description. |
73d9357
to
9ab3a4b
Compare
9ab3a4b
to
b0e508b
Compare
getaddressinfo() and listddresses() have fields in common. AddDestinationInfo() was created to reuse the same code for both. In this commit, getaddressinfo() is changed to call this function.
b0e508b
to
fcade9b
Compare
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
Closing for now. Let us know when you are working on this again and if it should be reopened. |
This PR adds an address explorer RPC to Bitcoin Core, similar to "Address" tab of Electrum or Specter Desktop.
This allows the user to know any arbitrary range of external and internal addresses and can be used with legacy or descriptor wallet.
This same functionality can be used to build an "Address" tab in the GUI later.
For better visualization in manual tests, the reviewer can start the node with the keypool reduced to 2. (default is 1000) and create a new wallet.