-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Add query options to listunspent RPC call #8952
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
Add query options to listunspent RPC call #8952
Conversation
57b9e76 to
3f89e80
Compare
e1881d9 to
2e423ea
Compare
|
Concept ACK |
|
WDYT of adding new options like |
2e423ea to
5cf4057
Compare
|
Yes, would make sense. Passing the JSON "query object" is a good idea. |
|
|
5cf4057 to
6660c22
Compare
6660c22 to
98d0a6f
Compare
Github-Pull: bitcoin#8952 Rebased-From: 98d0a6fb81b33a2cef429d3d6f9d56dd47508076
luke-jr
left 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.
utACK code, one nit.
src/wallet/rpcwallet.cpp
Outdated
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.
Instead of the dual meanings, just say default=unlimited (and make sure 0 doesn't behave in such a manner).
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.
👍
98d0a6f to
ae6a0c0
Compare
|
Looks like it! but as we're past the feature freeze for 0.14 and this is a new feature, merging this will have to wait until 0.14 is branched off. |
|
About tests: there aren't any tests specifically for testing |
|
Yes, tests for that would be great. They'd make it possible to automatically detect when something breaks this functionality. |
| nTotal += pcoin->tx->vout[i].nValue; | ||
|
|
||
| if (nTotal >= nMinimumSumAmount) { | ||
| return; |
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.
Maybe I'm misreading, but this (nMinimumSumAmount) sounds like a maximum, not a minimum. Esp. since it defaults to MAX_MONEY rather than 0.
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 see no issue here since is to be used like it was a minorant set of unspents which satisfies the passed value. If It it was called maximum it should not retrieve unspents which sum are greater than the passed value.
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 are collecting the sum of the nValue and once the total exceeds the minimum you stop. Generally speaking,
int minimumSum = 5;
int values[] = {1,2,3,2,3};
int sum = 0;
for (int i = 0; i < 5; i++) {
sum += values[i];
if (sum >= minimumSum) break;
}The above looks inverted to me, and will no doubt confuse the user. If you used the word minorant, it might help, but the minorant would be the vout set not the sum, I believe?
Anyway, if I'm the only one bothered by this feel free to keep as is.
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.
@kallewoof Any suggestions? nTargetSumAmount?
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.
@pedrobranco I say keep it as it is if no one else complains.
src/wallet/rpcwallet.cpp
Outdated
| " \"minimumAmount\" (numeric or string, default=0) Minimum value of each UTXO in " + CURRENCY_UNIT + "\n" | ||
| " \"maximumAmount\" (numeric or string, default=unlimited) Maximum value of each UTXO in " + CURRENCY_UNIT + "\n" | ||
| " \"maximumCount\" (numeric or string, default=unlimited) Maximum number of UTXOs\n" | ||
| " \"minimumSumAmount\" (numeric or string, default=unlimited) Minimum sum value all UTXOs in " + CURRENCY_UNIT + "\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.
Typo: [...]Minimum sum value of all UTXOs in " (missing of).
| "\nReturns array of unspent transaction outputs\n" | ||
| "with between minconf and maxconf (inclusive) confirmations.\n" | ||
| "Optionally filter to only include txouts paid to specified addresses.\n" | ||
| "\nArguments:\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.
Need to add options to the first line, e.g.
"listunspent ( minconf maxconf [\"addresses\",...] [include_unsafe] [options] )\n"
@laanwj I'm already working on it. Can I submit in another PR? |
bba51b1 to
c03488f
Compare
|
This needs a rebase. @pedrobranco Tests could be submitted in a follow-up PR. |
c03488f to
4f6566d
Compare
4f6566d to
11ee5ec
Compare
|
Merged (and rebased) via 9390845 |
|
Thank you @laanwj 👍 |
|
@laanwj I suppose you forgot to close after merging? |
|
Yes, did'nt automatically happen as I did a rebase locally. Thanks
…On May 18, 2017 2:38 AM, "Pieter Wuille" ***@***.***> wrote:
@laanwj <https://github.com/laanwj> I suppose you forgot to close after
merging?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8952 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAHutptwk3F7P5M0nGbOo-1CacVVlXtZks5r65L5gaJpZM4KZrh9>
.
|
|
@pedrobranco I've been trying to use the minimumSumAmount along with the addresses parameter, and I keep getting fewer outputs than I should. Looking at the code it seems that the minimumSumAmount is applied first, finding a correct set of outputs, but then when the addresses/destinations are checked, some of those are removed. Is this the expected behavior? Shouldn't this be, first get all UTXO's that belong to addresses and then apply the filters? |
|
Looks like a bug. |
|
@fedelcs IIRC To fix this we should either:
|
|
Need to have a feature show all addresses' UTXO set with non-zero balance (not only own addresses like listunspent) in Bitcoin Core as a build-in feature. |
bc63d0e Add query options to listunspent rpc call (Pedro Branco) Tree-SHA512: 2d296eee8df4e7ac378206ac3003a300e6478502d4b814f1ed1a47614222b01cc35dba871345ced68629860c227aff2c9e4b7f0d4ed0aa7de8b04f26c983580f Signed-off-by: Pasta <[email protected]> # Conflicts: # src/rpc/client.cpp # src/wallet/rpcwallet.cpp # src/wallet/wallet.cpp # src/wallet/wallet.h
063abcf [Doc] Add query_options listunspent parameter to release notes (random-zebra) 602f622 [QA] Excercise query_options parameter in listunspent (random-zebra) 93d4789 [RPC] Backport RPCTypeCheckArgument function and use it inside listunspent (furszy) c073ef2 [RPC] Add query options to listunspent rpc call. (furszy) Pull request description: Adaptation of bitcoin#8952 This PR adds a new optional JSON options for `listunspent` RPC call: * Return unspents greater or equal than a specific amount in PIV: minimumAmount. * Return unspents lower or equal than a specific amount in PIV: maximumAmount. * Return unspents with a total number lower or equal than a specific number: maximumCount. * Return unspents which total is greater or equal than a specific amount in PIV: minimumSumAmount. ``` > pivx-cli help listunspent ... 5. query options (json, optional) JSON with query options { "minimumAmount" (numeric or string, default=0) Minimum value of each UTXO in PIV "maximumAmount" (numeric or string, default=unlimited) Maximum value of each UTXO in PIV "maximumCount" (numeric or string, default=0=unlimited) Maximum number of UTXOs "minimumSumAmount" (numeric or string, default=unlimited) Minimum sum value all UTXOs in PIV } ... ``` ACKs for top commit: random-zebra: ACK 063abcf Fuzzbawls: ACK 063abcf Tree-SHA512: 0a54636657be5e366ddfff374cacb2cac9e7667af99e67d96dfefc3255a06d431dfb75539c90af8727d97697933042cd19ddf968894e655a5fd20a7b6eaeb5aa
This PR adds a new optional JSON options for
listunspentRPC call:minimumAmount(default = 0).maximumAmount(default =MAX_MONEY= 21000000.0 BTC).maximumCount(default=0=unlimited).minimumSumAmount(default =MAX_MONEY= 21000000.0 BTC).When selecting unspents on client side in a wallet with a large set of small unspents makes the call
listunspentslow. Using withminimumAmountoption could improve the performance of the RPC call, performance which depends on the size of wallet, the distribution of the unspents and theminimumAmountselected.Example:
Note: this PR also changes/simplifies the code in
AvailableCoinsto make the longest calls later in execution time, which also could improve performance in somelistunspentresults.