This change partially reverts #13075 and #14023.
Fixes #14382
Is this for backport to 0.17.1? While not necessary, I believe it would simplify upgrade from 0.17.1+ to 0.18.0, because 0.17.1 could be used without -deprecatedrpc as workaround.
I think it'd be reasonable to backport this, since it's a small change that restores a removed feature. But I think it won't cherry-pick cleanly because #14023 was merged since the 0.17 branch. @Saicere originally reported the issue so they might be able to say whether there's a benefit to backporting.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, 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.
@Saicere originally reported the issue so they might be able to say whether there's a benefit to backporting.
As far as I am concerned, it's not really a big deal whether or not it's backported to the 0.17 branch as long as it's in before accounts are removed entirely. If you were using accounts in your application, you are probably running 0.17 with -deprecatedrpc=accounts anyway while RPC-facing code is updated.
ACK 8fcb76508493cd09d4895e7f3ad11cc5b945056e
1374 | @@ -1375,8 +1375,9 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest) 1375 | * @param fLong Whether to include the JSON version of the transaction. 1376 | * @param ret The UniValue into which the result is stored. 1377 | * @param filter The "is mine" filter bool. 1378 | + * @param filter_label Optional label string to filter incoming transactions. 1379 | */ 1380 | -static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter) EXCLUSIVE_LOCKS_REQUIRED(cs_main) 1381 | +static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter, const std::string* filter_label) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
I think changing the signature is better because makes it easier to verify in the diff that there aren't other calls that should be passing along label values. It may also make it more likely that new RPC methods added in the future will support filtering by label.
In general, I think default arguments in c++ can make code difficult to read, and should be used sparingly. If I see nullptr /* filter label */ I can see that the code actually intended to pass null instead of just forgetting to override the default. I also like being able to count from the end when functions take a lot of arguments.
I agree that default arguments should be used sparingly.
:+1:
Concept ACK.
Concept ACK. For completeness, this functionality was hidden behind a deprecation switch in #12953 (based on #11497). The functionality was marked deprecated in #5575.
Apologies - it was my oversight that this functionality got dropped. I'm happy to backport this to V0.17 once this gets merged. I aim to review this week.
96 | @@ -97,9 +97,10 @@ def run_test(self): 97 | txid = self.nodes[1].sendtoaddress(multisig["address"], 0.1) 98 | self.nodes[1].generate(1) 99 | self.sync_all() 100 | - assert not [tx for tx in self.nodes[0].listtransactions(dummy="*", count=100, skip=0, include_watchonly=False) if "label" in tx and tx["label"] == "watchonly"] 101 | - txs = [tx for tx in self.nodes[0].listtransactions(dummy="*", count=100, skip=0, include_watchonly=True) if "label" in tx and tx['label'] == 'watchonly'] 102 | - assert_array_result(txs, {"category": "receive", "amount": Decimal("0.1")}, {"txid": txid}) 103 | + assert(len(self.nodes[0].listtransactions("watchonly", 100, 0, False)) == 0)
Fixed in 665d00fce4bc53a9ea9dc5a7d457d586af357bf3. The style changes just came from reverting to the previous code.
96 | @@ -97,9 +97,10 @@ def run_test(self): 97 | txid = self.nodes[1].sendtoaddress(multisig["address"], 0.1) 98 | self.nodes[1].generate(1) 99 | self.sync_all() 100 | - assert not [tx for tx in self.nodes[0].listtransactions(dummy="*", count=100, skip=0, include_watchonly=False) if "label" in tx and tx["label"] == "watchonly"] 101 | - txs = [tx for tx in self.nodes[0].listtransactions(dummy="*", count=100, skip=0, include_watchonly=True) if "label" in tx and tx['label'] == 'watchonly'] 102 | - assert_array_result(txs, {"category": "receive", "amount": Decimal("0.1")}, {"txid": txid}) 103 | + assert(len(self.nodes[0].listtransactions("watchonly", 100, 0, False)) == 0) 104 | + assert_array_result(self.nodes[0].listtransactions("watchonly", 100, 0, True),
As above, please retain the named args.
Fixed in 665d00fce4bc53a9ea9dc5a7d457d586af357bf3. The style changes just came from reverting to the previous code.
Tested ACK 8fcb76508493cd09d4895e7f3ad11cc5b945056e with a couple of nits. @MarcoFalke - I'll go ahead and open a PR for backporting. A couple of questions:
We assume the reader goes through the release notes for each release, so it should be sufficient to only mention on the 0.17. branch.
1464 | @@ -1461,9 +1465,11 @@ UniValue listtransactions(const JSONRPCRequest& request)
1465 | if (request.fHelp || request.params.size() > 4)
1466 | throw std::runtime_error(
1467 | "listtransactions (dummy count skip include_watchonly)\n"
dummy needs to be changed to label here.
Fixed in 665d00fce4bc53a9ea9dc5a7d457d586af357bf3
Added 1 commit 8fcb76508493cd09d4895e7f3ad11cc5b945056e -> 665d00fce4bc53a9ea9dc5a7d457d586af357bf3 (pr/list-label.1 -> pr/list-label.2, compare) with suggested fixes. Squashed 665d00fce4bc53a9ea9dc5a7d457d586af357bf3 -> fa7fae5c3612cf77c91b92a39c14e73478424e85 (pr/list-label.2 -> pr/list-label.3) Updated fa7fae5c3612cf77c91b92a39c14e73478424e85 -> 4deba4ced9fc4edd1a40837c083080b6ed4c8163 (pr/list-label.3 -> pr/list-label.4) with release notes changes to reflect the intent to backport this to 0.17.1
ACK 4deba4ced9fc4edd1a40837c083080b6ed4c8163
1463 | @@ -1460,10 +1464,12 @@ UniValue listtransactions(const JSONRPCRequest& request) 1464 | 1465 | if (request.fHelp || request.params.size() > 4) 1466 | throw std::runtime_error( 1467 | - "listtransactions (dummy count skip include_watchonly)\n" 1468 | + "listtransactions (label count skip include_watchonly)\n"
nit, fix consistency by adding spaces after ( and before )?
Updated 4deba4ced9fc4edd1a40837c083080b6ed4c8163 -> 7cbe74f1524fc8621eb339d5eddd9530826c8461 (pr/list-label.4 -> pr/list-label.5) removing release notes and changing whitespace as suggested.
Very nitty comment; it feels like this functionality is closer to listreceivedbylabel than to listtransactions (as the latter is about all transactions which affect the balance of the wallet - and formerly account) rather than just incoming payments. Would it make sense to add it as an extra option to listreceivedbylabel (verbose or so), or a separate RPC, instead?
Would it make sense to add it as an extra option to
listreceivedbylabel(verbose or so), or a separate RPC, instead?
listreceivedbylabel doesn't take a label argument or list transactions in any way, it just lists total received coins per label, as per the code.
ACK 7cbe74f1524fc8621eb339d5eddd9530826c8461. Only change since 4deba4c is removing release notes and changing whitespace.
Would it make sense to add it as an extra option to listreceivedbylabel (verbose or so), or a separate RPC, instead?
It'd be good to improve listreceivedbylabel. But filtering by label in listtransactions used to work previously and I think was just removed by accident.
You could maybe say that listtransactions shouldn't return labels or filter by label at all, since outgoing transactions won't have labels. But I don't think it makes sense to keep returning labels and only remove the ability to filter them.
1374 | @@ -1375,8 +1375,9 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
1375 | * @param fLong Whether to include the JSON version of the transaction.
1376 | * @param ret The UniValue into which the result is stored.
1377 | * @param filter The "is mine" filter bool.
IMO this should be renamed to avoid confusion, to something like filter_ismine
Rebased 7cbe74f1524fc8621eb339d5eddd9530826c8461 -> 671d8ee370de4824f4ab30b904bf59514f5e52e5 (pr/list-label.5 -> pr/list-label.6) due to conflict with #14437. Also renamed filter variable as suggested by MeshCollider.
Unless I am mistaken this has been "backported" in 5150accdd2a7c7f0edf964d56bd7d34b5f740cdc. So this must go into 0.18.0 instead. (assigned new milestone)
1355 | @@ -1352,10 +1356,12 @@ UniValue listtransactions(const JSONRPCRequest& request) 1356 | 1357 | if (request.fHelp || request.params.size() > 4) 1358 | throw std::runtime_error( 1359 | - "listtransactions (dummy count skip include_watchonly)\n" 1360 | + "listtransactions ( label count skip include_watchonly )\n"
From the documentation below, label is a string, so should be surrounded by quotation marks in the oneline doc.
"listtransactions ( \"label\" count skip include_watchonly )\n"
re: #14411 (review)
From the documentation below, label is a string, so should be surrounded by quotation marks in the oneline doc.
Done in rebase.
This change partially reverts #13075 and #14023.
Fixes #14382
Suggested by MeshCollider <dobsonsa68@gmail.com> in
https://github.com/bitcoin/bitcoin/pull/14411#discussion_r232134086
Rebased 671d8ee370de4824f4ab30b904bf59514f5e52e5 -> da427dbd48ae8d12a2a79a7514a813e78064fe52 (pr/list-label.6 -> pr/list-label.7) due to conflict with #14720
ACK da427dbd48ae8d12a2a79a7514a813e78064fe52 (Only checked that the rebase was done properly from the last time people reviewed this. Also checked that the tests are the same as in the backport 5150accdd2a7c7f0edf964d56bd7d34b5f740cdc, didn't look at the code)
utACK da427dbd48ae8d12a2a79a7514a813e78064fe52
Milestone
0.18.0