Add a maxconfirms argument to ListUnspentWitness

This change was inspired by #1984 - the underlying call to
ListUnspent supports a (min, max) range so it makes sense that
the WalletController interface can also support this; a
default no-maximum can be expressed using a MaxInt32 value.
This commit is contained in:
AdamISZ 2018-10-28 15:55:18 +01:00
parent eaba39d20e
commit 567306b010
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
4 changed files with 14 additions and 10 deletions

@ -217,7 +217,7 @@ func (b *BtcWallet) Stop() error {
func (b *BtcWallet) ConfirmedBalance(confs int32) (btcutil.Amount, error) { func (b *BtcWallet) ConfirmedBalance(confs int32) (btcutil.Amount, error) {
var balance btcutil.Amount var balance btcutil.Amount
witnessOutputs, err := b.ListUnspentWitness(confs) witnessOutputs, err := b.ListUnspentWitness(confs, math.MaxInt32)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -299,9 +299,9 @@ func (b *BtcWallet) UnlockOutpoint(o wire.OutPoint) {
// controls which pay to witness programs either directly or indirectly. // controls which pay to witness programs either directly or indirectly.
// //
// This is a part of the WalletController interface. // This is a part of the WalletController interface.
func (b *BtcWallet) ListUnspentWitness(minConfs int32) ([]*lnwallet.Utxo, error) { func (b *BtcWallet) ListUnspentWitness(minConfs, maxConfs int32) (
[]*lnwallet.Utxo, error) {
// First, grab all the unfiltered currently unspent outputs. // First, grab all the unfiltered currently unspent outputs.
maxConfs := int32(math.MaxInt32)
unspentOutputs, err := b.wallet.ListUnspent(minConfs, maxConfs, nil) unspentOutputs, err := b.wallet.ListUnspent(minConfs, maxConfs, nil)
if err != nil { if err != nil {
return nil, err return nil, err

@ -160,11 +160,13 @@ type WalletController interface {
feeRate SatPerKWeight) (*chainhash.Hash, error) feeRate SatPerKWeight) (*chainhash.Hash, error)
// ListUnspentWitness returns all unspent outputs which are version 0 // ListUnspentWitness returns all unspent outputs which are version 0
// witness programs. The 'confirms' parameter indicates the minimum // witness programs. The 'minconfirms' and 'maxconfirms' parameters
// number of confirmations an output needs in order to be returned by // indicate the minimum and maximum number of confirmations an output
// this method. Passing -1 as 'confirms' indicates that even // needs in order to be returned by this method. Passing -1 as
// unconfirmed outputs should be returned. // 'minconfirms' indicates that even unconfirmed outputs should be
ListUnspentWitness(confirms int32) ([]*Utxo, error) // returned. Using MaxInt32 as 'maxconfirms' implies returning all
// outputs with at least 'minconfirms'.
ListUnspentWitness(minconfirms, maxconfirms int32) ([]*Utxo, error)
// ListTransactionDetails returns a list of all transactions which are // ListTransactionDetails returns a list of all transactions which are
// relevant to the wallet. // relevant to the wallet.

@ -5,6 +5,7 @@ import (
"crypto/sha256" "crypto/sha256"
"errors" "errors"
"fmt" "fmt"
"math"
"net" "net"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -1276,7 +1277,7 @@ func (l *LightningWallet) selectCoinsAndChange(feeRate SatPerKWeight,
// Find all unlocked unspent witness outputs that satisfy the minimum // Find all unlocked unspent witness outputs that satisfy the minimum
// number of confirmations required. // number of confirmations required.
coins, err := l.ListUnspentWitness(minConfs) coins, err := l.ListUnspentWitness(minConfs, math.MaxInt32)
if err != nil { if err != nil {
return err return err
} }

@ -234,7 +234,8 @@ func (*mockWalletController) SendOutputs(outputs []*wire.TxOut,
// ListUnspentWitness is called by the wallet when doing coin selection. We just // ListUnspentWitness is called by the wallet when doing coin selection. We just
// need one unspent for the funding transaction. // need one unspent for the funding transaction.
func (m *mockWalletController) ListUnspentWitness(confirms int32) ([]*lnwallet.Utxo, error) { func (m *mockWalletController) ListUnspentWitness(minconfirms,
maxconfirms int32) ([]*lnwallet.Utxo, error) {
utxo := &lnwallet.Utxo{ utxo := &lnwallet.Utxo{
AddressType: lnwallet.WitnessPubKey, AddressType: lnwallet.WitnessPubKey,
Value: btcutil.Amount(10 * btcutil.SatoshiPerBitcoin), Value: btcutil.Amount(10 * btcutil.SatoshiPerBitcoin),