-
Notifications
You must be signed in to change notification settings - Fork 37.8k
listreceivedbyaddress Filter Address #9991
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
listreceivedbyaddress Filter Address #9991
Conversation
45c69fa
to
8c373d5
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.
utACK 8c373d5feedb428d234278d484e5d2a932010fae
@luke-jr @jnewbery @JeremyRubin nit addressed, can you re-ACK? |
qa/rpc-tests/receivedby.py
Outdated
#Test Address filtering | ||
#Only on addr | ||
expected = {"address":addr, "account":"", "amount":Decimal("0.1"), "confirmations":10, "txids":[txid,]} | ||
res = self.nodes[1].listreceivedbyaddress(0, True, True, addr) |
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: Consider using named arguments here, instead of positional arguments (since the meaning of the arguments is not clear without having to go back to the definition of listreceivedbyaddress).
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.
Listreceivedbyaddress is not known at compile time, and thus has no definition in python. This is interpreted at runtime. So I can't really use named argument. Would inline comment be good ?
EDIT: No mid line comments in python
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.
You can use named arguments in the RPC calls. See #9983 for example.
qa/rpc-tests/receivedby.py
Outdated
{"address":empty_addr}, | ||
{"address":empty_addr, "account":"", "amount":0, "confirmations":0, "txids":[]}) | ||
|
||
#Test Address filtering |
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'd prefer this test if other_addr
(currently declared on line 78) received some funds before you did your tests on listreceivedbyaddress()
with a filter address. This isn't currently testing the case where the wallet contains multiple addresses with funds and you want to see the transactions received by one of those addresses. Ideally the test case would be:
- define addr and send funds to it (already done for you in lines 42-43)
- define other_addr and send funds to it
- call
listreceivedbyaddress()
filtering onaddr
. Assert only one transaction is returned. - call
listreceivedbyaddress()
filtering onother_addr
. Assert only one transaction is returned. - call
listreceivedbyaddress()
with no filtering. Assert both transactions are returned.
src/wallet/rpcwallet.cpp
Outdated
"\nList balances by receiving address.\n" | ||
"\nArguments:\n" | ||
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" | ||
"2. include_empty (bool, optional, default=false) Whether to include addresses that haven't received any payments.\n" | ||
"3. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress').\n" | ||
|
||
"4. only_address (string, optional) If present, only return information on this address. Otherwise, return all information.\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.
minor nit: align parentheses with line above.
Looks good. A couple of nits and a suggestion on improving the test case. |
utAck |
8c373d5
to
2f435f4
Compare
@jnewbery I improved the tests, and fixed the alignement. I can't use named parameter in the test though. |
2f435f4
to
7d9a0f1
Compare
added named parameters to one call to listreceivedbyaddress in the tests for better readability. |
line 73 with that change, tested ACK. Good stuff @NicolasDorier ! |
7d9a0f1
to
eef18e8
Compare
@jnewbery thanks done, @JeremyRubin did the hard work :) |
eef18e8
to
c262be5
Compare
utACK - the code looks good and this is very useful functionality. |
@TheBlueMatt I fixed nits and added tests, can you re-ACK ? |
ACK - works fine. |
Closing. I am using a workaround now, I am caching the whole |
😞 I'm happy to reACK if you decide to reopen this! |
@jnewbery, if you have interest, I am reopening, I guess it does not hurt to keep it opens, it is not high maintenance PR. I was thinking to allow multiple addresses to be passed in the filter, instead of only one. For NTumbleBit, I changed the design, I have a method called The way I ended up implemeting my need is by caching EDIT: Documenting why I need also all transaction spent from this address: (not only transactions received) In TumbleBit, there is a chain of transaction.
Escrow is confirmed. So the way I am doing it now is adding Offer's ScriptPubKey as WatchOnly. Then fetching all the transactions from the wallet, caching them in internal database, and going through all those transactions to see if there is one input which is spent by the ScriptPubKey of Offer. If yes, then we have [Fulfill]. Watching all transactions related to one address is very useful, not only the received transaction of the address. In Core, however it is not possible, because knowing if a transaction is "from an address" is considered bad practice. |
ok rebasing |
22ebb2a
to
b3f2540
Compare
b3f2540
to
522c119
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.
utACK
src/wallet/rpcwallet.cpp
Outdated
@@ -1403,6 +1403,16 @@ UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bool fByA | |||
if(params[2].get_bool()) | |||
filter = filter | ISMINE_WATCH_ONLY; | |||
|
|||
bool fFilterAddress = false; |
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 convention has changed a bit recently. Now, we don't put the type as prefix, and we try to use snake case. I would rename this has_filter_address
and the below to filter_address
. You can leave existing vars as is, if you don't want the diff to grow for no reason though (like fByAccounts
below).
src/wallet/rpcwallet.cpp
Outdated
@@ -3837,7 +3866,7 @@ static const CRPCCommand commands[] = | |||
{ "wallet", "listaddressgroupings", &listaddressgroupings, {} }, | |||
{ "wallet", "listlockunspent", &listlockunspent, {} }, | |||
{ "wallet", "listreceivedbyaccount", &listreceivedbyaccount, {"minconf","include_empty","include_watchonly"} }, | |||
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, {"minconf","include_empty","include_watchonly"} }, | |||
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter" } }, |
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 space after "
(end of line) -- compare to other lines.
9f63a88
to
4211124
Compare
4211124
to
f087613
Compare
Addressed @kallewoof nits |
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.
utACK f087613
utACK f087613 |
f087613 Add tests of listreceivedbyaddress address filtering (Jeremy Rubin) 8ee0812 Add address filtering to listreceivedbyaddress (Jeremy Rubin) Pull request description: Supersede #9503 created by @JeremyRubin , I will maintain it. Tree-SHA512: 2accaed493b7e1c2eb5cb5270180f100f8c718b6585b9574f294191c318dc622a79e42ac185300f291f82d3b2a6f1c00850b6b17e4ff2dbab94d71df695acbfe
{"address": empty_addr}, | ||
{"address": empty_addr, "account": "", "amount": 0, "confirmations": 0, "txids": []}) | ||
|
||
#Test Address filtering |
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.
Space after #
is expected now it seems.
|
||
#Test Address filtering | ||
#Only on addr | ||
expected = {"address":addr, "account":"", "amount":Decimal("0.1"), "confirmations":10, "txids":[txid,]} |
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.
Space after :
is expected now it seems.
f087613 Add tests of listreceivedbyaddress address filtering (Jeremy Rubin) 8ee0812 Add address filtering to listreceivedbyaddress (Jeremy Rubin) Pull request description: Supersede bitcoin#9503 created by @JeremyRubin , I will maintain it. Tree-SHA512: 2accaed493b7e1c2eb5cb5270180f100f8c718b6585b9574f294191c318dc622a79e42ac185300f291f82d3b2a6f1c00850b6b17e4ff2dbab94d71df695acbfe
f087613 Add tests of listreceivedbyaddress address filtering (Jeremy Rubin) 8ee0812 Add address filtering to listreceivedbyaddress (Jeremy Rubin) Pull request description: Supersede bitcoin#9503 created by @JeremyRubin , I will maintain it. Tree-SHA512: 2accaed493b7e1c2eb5cb5270180f100f8c718b6585b9574f294191c318dc622a79e42ac185300f291f82d3b2a6f1c00850b6b17e4ff2dbab94d71df695acbfe
f087613 Add tests of listreceivedbyaddress address filtering (Jeremy Rubin) 8ee0812 Add address filtering to listreceivedbyaddress (Jeremy Rubin) Pull request description: Supersede bitcoin#9503 created by @JeremyRubin , I will maintain it. Tree-SHA512: 2accaed493b7e1c2eb5cb5270180f100f8c718b6585b9574f294191c318dc622a79e42ac185300f291f82d3b2a6f1c00850b6b17e4ff2dbab94d71df695acbfe
f087613 Add tests of listreceivedbyaddress address filtering (Jeremy Rubin) 8ee0812 Add address filtering to listreceivedbyaddress (Jeremy Rubin) Pull request description: Supersede bitcoin#9503 created by @JeremyRubin , I will maintain it. Tree-SHA512: 2accaed493b7e1c2eb5cb5270180f100f8c718b6585b9574f294191c318dc622a79e42ac185300f291f82d3b2a6f1c00850b6b17e4ff2dbab94d71df695acbfe
Supersede #9503 created by @JeremyRubin , I will maintain it.