Skip to content

Conversation

NicolasDorier
Copy link
Contributor

@NicolasDorier NicolasDorier commented Mar 14, 2017

Supersede #9503 created by @JeremyRubin , I will maintain it.

@NicolasDorier NicolasDorier force-pushed the listreceivedbyaddress-filtered branch from 45c69fa to 8c373d5 Compare March 14, 2017 16:52
@NicolasDorier
Copy link
Contributor Author

  1. Rebased and fixed conflicts
  2. Addressed @kallewoof nits
  3. Add the new parameter to client.cpp

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

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

utACK 8c373d5feedb428d234278d484e5d2a932010fae

@NicolasDorier
Copy link
Contributor Author

NicolasDorier commented Mar 16, 2017

@luke-jr @jnewbery @JeremyRubin nit addressed, can you re-ACK?

#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)
Copy link
Contributor

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).

Copy link
Contributor Author

@NicolasDorier NicolasDorier Mar 17, 2017

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

Copy link
Contributor

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.

{"address":empty_addr},
{"address":empty_addr, "account":"", "amount":0, "confirmations":0, "txids":[]})

#Test Address filtering
Copy link
Contributor

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 on addr. Assert only one transaction is returned.
  • call listreceivedbyaddress() filtering on other_addr. Assert only one transaction is returned.
  • call listreceivedbyaddress() with no filtering. Assert both transactions are returned.

"\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"
Copy link
Contributor

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.

@jnewbery
Copy link
Contributor

Looks good. A couple of nits and a suggestion on improving the test case.

@JeremyRubin
Copy link
Contributor

utAck

@NicolasDorier NicolasDorier force-pushed the listreceivedbyaddress-filtered branch from 8c373d5 to 2f435f4 Compare March 17, 2017 03:09
@NicolasDorier
Copy link
Contributor Author

@jnewbery I improved the tests, and fixed the alignement. I can't use named parameter in the test though.

@NicolasDorier NicolasDorier force-pushed the listreceivedbyaddress-filtered branch from 2f435f4 to 7d9a0f1 Compare March 17, 2017 14:47
@NicolasDorier
Copy link
Contributor Author

added named parameters to one call to listreceivedbyaddress in the tests for better readability.

@jnewbery
Copy link
Contributor

jnewbery commented Mar 17, 2017

line 73 minConf needs to be minconf.

with that change, tested ACK. Good stuff @NicolasDorier !

@NicolasDorier NicolasDorier force-pushed the listreceivedbyaddress-filtered branch from 7d9a0f1 to eef18e8 Compare March 18, 2017 14:04
@NicolasDorier
Copy link
Contributor Author

NicolasDorier commented Mar 18, 2017

@jnewbery thanks done, @JeremyRubin did the hard work :)

@NicolasDorier NicolasDorier force-pushed the listreceivedbyaddress-filtered branch from eef18e8 to c262be5 Compare March 21, 2017 01:58
@EthanHeilman
Copy link
Contributor

utACK - the code looks good and this is very useful functionality.

@NicolasDorier
Copy link
Contributor Author

@TheBlueMatt I fixed nits and added tests, can you re-ACK ?

@nopara73
Copy link

ACK - works fine.
This could be (not sure if should be) combined with fixing this issue for correct GUI experience: #9192

@NicolasDorier
Copy link
Contributor Author

NicolasDorier commented Jun 14, 2017

Closing. I am using a workaround now, I am caching the whole listtransaction, at every block. This call would have been super useful though.

@jnewbery
Copy link
Contributor

😞 I'm happy to reACK if you decide to reopen this!

@NicolasDorier NicolasDorier reopened this Jun 15, 2017
@NicolasDorier
Copy link
Contributor Author

NicolasDorier commented Jun 15, 2017

@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 GetTransactions(address) which should send back the inputs AND outputs transactions of this address. listreceivedbyaddress would only show input transactions.

The way I ended up implemeting my need is by caching listtransaction then for each transaction in it, caching gettransaction in a internal database. I now have good performance, and I am not sure this RPC method would suit my case now.


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] -> [Offer] -> [Fulfill]

Escrow is confirmed.
The user knows one of the ScriptPubKey inside Offer, but not the transaction ID.
His goal is to fetch Fulfill on the blockchain. (When the ScriptPubKey of Offer get spent, then important preimages are revealed)

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.
At the root, this is the same reason as to why #10007 could not make it..

@NicolasDorier NicolasDorier reopened this Mar 6, 2018
@NicolasDorier
Copy link
Contributor Author

ok rebasing

@NicolasDorier NicolasDorier force-pushed the listreceivedbyaddress-filtered branch 5 times, most recently from 22ebb2a to b3f2540 Compare March 6, 2018 23:09
@NicolasDorier
Copy link
Contributor Author

Rebased, fixed the nits of @luke-jr and @promag .

I renamed only_address to address_filter so that if later we decide it is also possible to pass an array of address instead of a single address, we don't need to rename anything. It is more generic.

@NicolasDorier NicolasDorier force-pushed the listreceivedbyaddress-filtered branch from b3f2540 to 522c119 Compare March 6, 2018 23:12
Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

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

utACK

@@ -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;
Copy link
Contributor

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).

@@ -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" } },
Copy link
Contributor

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.

@NicolasDorier NicolasDorier force-pushed the listreceivedbyaddress-filtered branch 2 times, most recently from 9f63a88 to 4211124 Compare March 7, 2018 13:29
@NicolasDorier NicolasDorier force-pushed the listreceivedbyaddress-filtered branch from 4211124 to f087613 Compare March 7, 2018 13:31
@NicolasDorier
Copy link
Contributor Author

Addressed @kallewoof nits

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

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

utACK f087613

@laanwj laanwj merged commit f087613 into bitcoin:master Mar 7, 2018
@laanwj
Copy link
Member

laanwj commented Mar 7, 2018

utACK f087613

laanwj added a commit that referenced this pull request Mar 7, 2018
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
Copy link
Member

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,]}
Copy link
Member

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.

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 17, 2020
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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 17, 2020
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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 17, 2020
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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 27, 2020
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 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.