Skip to content

Commit

Permalink
Merge pull request lightningnetwork#6190 from ErikEk/listunspent-deaf…
Browse files Browse the repository at this point in the history
…ult-values

walletrpc: add default values to listunspent
  • Loading branch information
Roasbeef authored Mar 16, 2022
2 parents 6c80a30 + 74db83b commit f13399b
Show file tree
Hide file tree
Showing 7 changed files with 485 additions and 436 deletions.
2 changes: 2 additions & 0 deletions docs/release-notes/release-notes-0.15.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
* [A nightly build of the `lnd` docker image is now created
automatically](https://github.com/lightningnetwork/lnd/pull/6160).

* Add default values to [walletrpc.ListUnspent RPC call](https://github.com/lightningnetwork/lnd/pull/6190).

* [Add `.vs/` folder to `.gitignore`](https://github.com/lightningnetwork/lnd/pull/6178).

* [Chain backend healthchecks disabled for --nochainbackend mode](https://github.com/lightningnetwork/lnd/pull/6184)
Expand Down
851 changes: 433 additions & 418 deletions lnrpc/walletrpc/walletkit.pb.go

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion lnrpc/walletrpc/walletkit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ option go_package = "github.com/lightningnetwork/lnd/lnrpc/walletrpc";
service WalletKit {
/*
ListUnspent returns a list of all utxos spendable by the wallet with a
number of confirmations between the specified minimum and maximum.
number of confirmations between the specified minimum and maximum. By
default, all utxos are listed. To list only the unconfirmed utxos, set
the unconfirmed_only to true.
*/
rpc ListUnspent (ListUnspentRequest) returns (ListUnspentResponse);

Expand Down Expand Up @@ -240,6 +242,14 @@ message ListUnspentRequest {

// An optional filter to only include outputs belonging to an account.
string account = 3;

/*
When min_confs and max_confs are zero, setting false implicitly
overrides max_confs to be MaxInt32, otherwise max_confs remains
zero. An error is returned if the value is true and both min_confs
and max_confs are non-zero. (default: false)
*/
bool unconfirmed_only = 4;
}

message ListUnspentResponse {
Expand Down
6 changes: 5 additions & 1 deletion lnrpc/walletrpc/walletkit.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@
},
"/v2/wallet/utxos": {
"post": {
"summary": "ListUnspent returns a list of all utxos spendable by the wallet with a\nnumber of confirmations between the specified minimum and maximum.",
"summary": "ListUnspent returns a list of all utxos spendable by the wallet with a\nnumber of confirmations between the specified minimum and maximum. By\ndefault, all utxos are listed. To list only the unconfirmed utxos, set\nthe unconfirmed_only to true.",
"operationId": "WalletKit_ListUnspent",
"responses": {
"200": {
Expand Down Expand Up @@ -1276,6 +1276,10 @@
"account": {
"type": "string",
"description": "An optional filter to only include outputs belonging to an account."
},
"unconfirmed_only": {
"type": "boolean",
"title": "When min_confs and max_confs are zero, setting false implicitly\noverrides max_confs to be MaxInt32, otherwise max_confs remains\nzero. An error is returned if the value is true and both min_confs\nand max_confs are non-zero. (default: false)"
}
}
},
Expand Down
8 changes: 6 additions & 2 deletions lnrpc/walletrpc/walletkit_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 21 additions & 7 deletions lnrpc/walletrpc/walletkit_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -322,16 +323,29 @@ func (w *WalletKit) internalScope() waddrmgr.KeyScope {
}
}

// ListUnspent returns useful information about each unspent output owned by the
// wallet, as reported by the underlying `ListUnspentWitness`; the information
// returned is: outpoint, amount in satoshis, address, address type,
// scriptPubKey in hex and number of confirmations. The result is filtered to
// contain outputs whose number of confirmations is between a
// minimum and maximum number of confirmations specified by the user, with 0
// meaning unconfirmed.
// ListUnspent returns useful information about each unspent output owned by
// the wallet, as reported by the underlying `ListUnspentWitness`; the
// information returned is: outpoint, amount in satoshis, address, address
// type, scriptPubKey in hex and number of confirmations. The result is
// filtered to contain outputs whose number of confirmations is between a
// minimum and maximum number of confirmations specified by the user.
func (w *WalletKit) ListUnspent(ctx context.Context,
req *ListUnspentRequest) (*ListUnspentResponse, error) {

// Force min_confs and max_confs to be zero if unconfirmed_only is
// true.
if req.UnconfirmedOnly && (req.MinConfs != 0 || req.MaxConfs != 0) {
return nil, fmt.Errorf("min_confs and max_confs must be zero if " +
"unconfirmed_only is true")
}

// When unconfirmed_only is inactive and max_confs is zero (default
// values), we will override max_confs to be a MaxInt32, in order
// to return all confirmed and unconfirmed utxos as a default response.
if req.MaxConfs == 0 && !req.UnconfirmedOnly {
req.MaxConfs = math.MaxInt32
}

// Validate the confirmation arguments.
minConfs, maxConfs, err := lnrpc.ParseConfs(req.MinConfs, req.MaxConfs)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,13 +1078,13 @@ func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64,
return &txHash, nil
}

// ListUnspent returns useful information about each unspent output owned by the
// wallet, as reported by the underlying `ListUnspentWitness`; the information
// returned is: outpoint, amount in satoshis, address, address type,
// scriptPubKey in hex and number of confirmations. The result is filtered to
// contain outputs whose number of confirmations is between a minimum and
// maximum number of confirmations specified by the user, with 0 meaning
// unconfirmed.
// ListUnspent returns useful information about each unspent output owned by
// the wallet, as reported by the underlying `ListUnspentWitness`; the
// information returned is: outpoint, amount in satoshis, address, address
// type, scriptPubKey in hex and number of confirmations. The result is
// filtered to contain outputs whose number of confirmations is between a
// minimum and maximum number of confirmations specified by the user, with
// 0 meaning unconfirmed.
func (r *rpcServer) ListUnspent(ctx context.Context,
in *lnrpc.ListUnspentRequest) (*lnrpc.ListUnspentResponse, error) {

Expand Down

0 comments on commit f13399b

Please sign in to comment.