Add query options to listunspent RPC call #8952

Open
wants to merge 1 commit into
from

Projects

None yet

2 participants

@pedrobranco
Contributor
pedrobranco commented Oct 18, 2016 edited

This PR adds a new optional JSON options for listunspent RPC call:

  • Return unspents greater or equal than a specific amount in BTC: minimumAmount (default = 0).
  • Return unspents lower or equal than a specific amount in BTC: maximumAmount (default = MAX_MONEY = 21000000.0 BTC).
  • Return unspents with a total number lower or equal than a specific number: maximumCount (default=0=unlimited).
  • Return unspents which total is greater or equal than a specific amount in BTC: minimumSumAmount (default = MAX_MONEY = 21000000.0 BTC).
> bitcoin-cli help listunspent
...
4. query options    (json, optional) JSON with query options
    {
      "minimumAmount"    (numeric or string, default=0) Minimum value of each UTXO in BTC
      "maximumAmount"    (numeric or string, default=21000000=unlimited) Maximum value of each UTXO in BTC
      "maximumCount"     (numeric or string, default=0=unlimited) Maximum number of UTXOs
      "minimumSumAmount" (numeric or string, default=21000000=unlimited) Minimum sum value all UTXOs in BTC
    }
...

When selecting unspents on client side in a wallet with a large set of small unspents makes the call listunspent slow. Using with minimumAmount option could improve the performance of the RPC call, performance which depends on the size of wallet, the distribution of the unspents and the minimumAmount selected.

Example:

> bitcoin-cli listunspent 0 9999999 '[]' '{ "minimumAmount": 10, "maximumAmount": 80, "minimumSumAmount": 50, "maximumCount": 3 }'

Note: this PR also changes/simplifies the code in AvailableCoins to make the longest calls later in execution time, which also could improve performance in some listunspent results.

@laanwj laanwj added the RPC/REST/ZMQ label Oct 18, 2016
@laanwj
Member
laanwj commented Oct 19, 2016

Concept ACK

@pedrobranco
Contributor

WDYT of adding new options like maximumAmount (which ables to define a range with minimumAmount) or maybe sumAmount (return unspents until the respective sum is bigger than sumAmount) ?

@laanwj
Member
laanwj commented Oct 19, 2016

Yes, would make sense. Passing the JSON "query object" is a good idea.

@pedrobranco
Contributor
pedrobranco commented Oct 19, 2016 edited

I'm willing to implement I've also implemented maximumAmount, minimumSumAmount and maximumCount options.

minimumAmount and maximumAmount are options to filter unspents, but maximumCount and minimumSumAmount are grouping options which returns unspents until satisfies one of these conditions.

@pedrobranco pedrobranco changed the title from Add selection options to listunspent RPC call to Add query options to listunspent RPC call Oct 19, 2016
@luke-jr luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Dec 21, 2016
@pedrobranco @luke-jr pedrobranco + luke-jr Add query options to listunspent rpc call
Github-Pull: #8952
Rebased-From: 98d0a6f
ed5bc96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment