lnwallet: expose optional account filter for several WalletController methods

This commit is contained in:
Wilmer Paulino 2021-02-19 17:41:50 -08:00
parent f38bf4d7fa
commit f91e7cde59
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
14 changed files with 138 additions and 76 deletions

@ -321,7 +321,9 @@ func (w *WalletKit) ListUnspent(ctx context.Context,
// be shown available to us. // be shown available to us.
var utxos []*lnwallet.Utxo var utxos []*lnwallet.Utxo
err = w.cfg.CoinSelectionLocker.WithCoinSelectLock(func() error { err = w.cfg.CoinSelectionLocker.WithCoinSelectLock(func() error {
utxos, err = w.cfg.Wallet.ListUnspentWitness(minConfs, maxConfs) utxos, err = w.cfg.Wallet.ListUnspentWitness(
minConfs, maxConfs, "",
)
return err return err
}) })
if err != nil { if err != nil {
@ -854,9 +856,10 @@ func (w *WalletKit) ListSweeps(ctx context.Context,
// Some of our sweeps could have been replaced by fee, or dropped out // Some of our sweeps could have been replaced by fee, or dropped out
// of the mempool. Here, we lookup our wallet transactions so that we // of the mempool. Here, we lookup our wallet transactions so that we
// can match our list of sweeps against the list of transactions that // can match our list of sweeps against the list of transactions that
// the wallet is still tracking. // the wallet is still tracking. Sweeps are currently always swept to
// the default wallet account.
transactions, err := w.cfg.Wallet.ListTransactionDetails( transactions, err := w.cfg.Wallet.ListTransactionDetails(
0, btcwallet.UnconfirmedHeight, 0, btcwallet.UnconfirmedHeight, lnwallet.DefaultAccountName,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -1057,7 +1060,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
if len(packet.UnsignedTx.TxIn) > 0 { if len(packet.UnsignedTx.TxIn) > 0 {
// Get a list of all unspent witness outputs. // Get a list of all unspent witness outputs.
utxos, err := w.cfg.Wallet.ListUnspentWitness( utxos, err := w.cfg.Wallet.ListUnspentWitness(
defaultMinConf, defaultMaxConf, defaultMinConf, defaultMaxConf, "",
) )
if err != nil { if err != nil {
return err return err

@ -52,7 +52,8 @@ func (w *WalletController) FetchInputInfo(
} }
// ConfirmedBalance currently returns dummy values. // ConfirmedBalance currently returns dummy values.
func (w *WalletController) ConfirmedBalance(confs int32) (btcutil.Amount, error) { func (w *WalletController) ConfirmedBalance(confs int32,
_ string) (btcutil.Amount, error) {
return 0, nil return 0, nil
} }
@ -94,7 +95,7 @@ func (w *WalletController) CreateSimpleTx(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 (w *WalletController) ListUnspentWitness(minconfirms, func (w *WalletController) ListUnspentWitness(minconfirms,
maxconfirms int32) ([]*lnwallet.Utxo, error) { maxconfirms int32, _ string) ([]*lnwallet.Utxo, error) {
// If the mock already has a list of utxos, return it. // If the mock already has a list of utxos, return it.
if w.Utxos != nil { if w.Utxos != nil {
@ -119,7 +120,7 @@ func (w *WalletController) ListUnspentWitness(minconfirms,
// ListTransactionDetails currently returns dummy values. // ListTransactionDetails currently returns dummy values.
func (w *WalletController) ListTransactionDetails(_, func (w *WalletController) ListTransactionDetails(_,
_ int32) ([]*lnwallet.TransactionDetail, error) { _ int32, _ string) ([]*lnwallet.TransactionDetail, error) {
return nil, nil return nil, nil
} }

@ -223,13 +223,19 @@ func (b *BtcWallet) Stop() error {
// ConfirmedBalance returns the sum of all the wallet's unspent outputs that // ConfirmedBalance returns the sum of all the wallet's unspent outputs that
// have at least confs confirmations. If confs is set to zero, then all unspent // have at least confs confirmations. If confs is set to zero, then all unspent
// outputs, including those currently in the mempool will be included in the // outputs, including those currently in the mempool will be included in the
// final sum. // final sum. The account parameter serves as a filter to retrieve the balance
// for a specific account. When empty, the confirmed balance of all wallet
// accounts is returned.
// //
// This is a part of the WalletController interface. // This is a part of the WalletController interface.
func (b *BtcWallet) ConfirmedBalance(confs int32) (btcutil.Amount, error) { func (b *BtcWallet) ConfirmedBalance(confs int32,
accountFilter string) (btcutil.Amount, error) {
var balance btcutil.Amount var balance btcutil.Amount
witnessOutputs, err := b.ListUnspentWitness(confs, math.MaxInt32) witnessOutputs, err := b.ListUnspentWitness(
confs, math.MaxInt32, accountFilter,
)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -463,16 +469,25 @@ func (b *BtcWallet) ReleaseOutput(id wtxmgr.LockID, op wire.OutPoint) error {
return b.wallet.ReleaseOutput(id, op) return b.wallet.ReleaseOutput(id, op)
} }
// ListUnspentWitness returns a slice of all the unspent outputs the wallet // ListUnspentWitness returns all unspent outputs which are version 0 witness
// controls which pay to witness programs either directly or indirectly. // programs. The 'minconfirms' and 'maxconfirms' parameters indicate the minimum
// and maximum number of confirmations an output needs in order to be returned
// by this method. Passing -1 as 'minconfirms' indicates that even unconfirmed
// outputs should be returned. Using MaxInt32 as 'maxconfirms' implies returning
// all outputs with at least 'minconfirms'. The account parameter serves as a
// filter to retrieve the unspent outputs for a specific account. When empty,
// the unspent outputs of all wallet accounts are returned.
// //
// NOTE: This method requires the global coin selection lock to be held. // NOTE: This method requires the global coin selection lock to be held.
// //
// This is a part of the WalletController interface. // This is a part of the WalletController interface.
func (b *BtcWallet) ListUnspentWitness(minConfs, maxConfs int32) ( func (b *BtcWallet) ListUnspentWitness(minConfs, maxConfs int32,
[]*lnwallet.Utxo, error) { accountFilter string) ([]*lnwallet.Utxo, error) {
// First, grab all the unfiltered currently unspent outputs. // First, grab all the unfiltered currently unspent outputs.
unspentOutputs, err := b.wallet.ListUnspent(minConfs, maxConfs, "") unspentOutputs, err := b.wallet.ListUnspent(
minConfs, maxConfs, accountFilter,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -690,14 +705,18 @@ func unminedTransactionsToDetail(
return txDetail, nil return txDetail, nil
} }
// ListTransactionDetails returns a list of all transactions which are // ListTransactionDetails returns a list of all transactions which are relevant
// relevant to the wallet. It takes inclusive start and end height to allow // to the wallet over [startHeight;endHeight]. If start height is greater than
// paginated queries. Unconfirmed transactions can be included in the query // end height, the transactions will be retrieved in reverse order. To include
// by providing endHeight = UnconfirmedHeight (= -1). // unconfirmed transactions, endHeight should be set to the special value -1.
// This will return transactions from the tip of the chain until the start
// height (inclusive) and unconfirmed transactions. The account parameter serves
// as a filter to retrieve the transactions relevant to a specific account. When
// empty, transactions of all wallet accounts are returned.
// //
// This is a part of the WalletController interface. // This is a part of the WalletController interface.
func (b *BtcWallet) ListTransactionDetails(startHeight, func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
endHeight int32) ([]*lnwallet.TransactionDetail, error) { accountFilter string) ([]*lnwallet.TransactionDetail, error) {
// Grab the best block the wallet knows of, we'll use this to calculate // Grab the best block the wallet knows of, we'll use this to calculate
// # of confirmations shortly below. // # of confirmations shortly below.
@ -707,7 +726,7 @@ func (b *BtcWallet) ListTransactionDetails(startHeight,
// We'll attempt to find all transactions from start to end height. // We'll attempt to find all transactions from start to end height.
start := base.NewBlockIdentifierFromHeight(startHeight) start := base.NewBlockIdentifierFromHeight(startHeight)
stop := base.NewBlockIdentifierFromHeight(endHeight) stop := base.NewBlockIdentifierFromHeight(endHeight)
txns, err := b.wallet.GetTransactions(start, stop, "", nil) txns, err := b.wallet.GetTransactions(start, stop, accountFilter, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -159,12 +159,14 @@ type WalletController interface {
// ConfirmedBalance returns the sum of all the wallet's unspent outputs // ConfirmedBalance returns the sum of all the wallet's unspent outputs
// that have at least confs confirmations. If confs is set to zero, // that have at least confs confirmations. If confs is set to zero,
// then all unspent outputs, including those currently in the mempool // then all unspent outputs, including those currently in the mempool
// will be included in the final sum. // will be included in the final sum. The account parameter serves as a
// filter to retrieve the balance for a specific account. When empty,
// the confirmed balance of all wallet accounts is returned.
// //
// NOTE: Only witness outputs should be included in the computation of // NOTE: Only witness outputs should be included in the computation of
// the total spendable balance of the wallet. We require this as only // the total spendable balance of the wallet. We require this as only
// witness inputs can be used for funding channels. // witness inputs can be used for funding channels.
ConfirmedBalance(confs int32) (btcutil.Amount, error) ConfirmedBalance(confs int32, accountFilter string) (btcutil.Amount, error)
// NewAddress returns the next external or internal address for the // NewAddress returns the next external or internal address for the
// wallet dictated by the value of the `change` parameter. If change is // wallet dictated by the value of the `change` parameter. If change is
@ -221,10 +223,13 @@ type WalletController interface {
// needs in order to be returned by this method. Passing -1 as // needs in order to be returned by this method. Passing -1 as
// 'minconfirms' indicates that even unconfirmed outputs should be // 'minconfirms' indicates that even unconfirmed outputs should be
// returned. Using MaxInt32 as 'maxconfirms' implies returning all // returned. Using MaxInt32 as 'maxconfirms' implies returning all
// outputs with at least 'minconfirms'. // outputs with at least 'minconfirms'. The account parameter serves as
// a filter to retrieve the unspent outputs for a specific account.
// When empty, the unspent outputs of all wallet accounts are returned.
// //
// NOTE: This method requires the global coin selection lock to be held. // NOTE: This method requires the global coin selection lock to be held.
ListUnspentWitness(minconfirms, maxconfirms int32) ([]*Utxo, error) ListUnspentWitness(minconfirms, maxconfirms int32,
accountFilter string) ([]*Utxo, error)
// ListTransactionDetails returns a list of all transactions which are // ListTransactionDetails returns a list of all transactions which are
// relevant to the wallet over [startHeight;endHeight]. If start height // relevant to the wallet over [startHeight;endHeight]. If start height
@ -232,9 +237,11 @@ type WalletController interface {
// reverse order. To include unconfirmed transactions, endHeight should // reverse order. To include unconfirmed transactions, endHeight should
// be set to the special value -1. This will return transactions from // be set to the special value -1. This will return transactions from
// the tip of the chain until the start height (inclusive) and // the tip of the chain until the start height (inclusive) and
// unconfirmed transactions. // unconfirmed transactions. The account parameter serves as a filter to
ListTransactionDetails(startHeight, // retrieve the transactions relevant to a specific account. When
endHeight int32) ([]*TransactionDetail, error) // empty, transactions of all wallet accounts are returned.
ListTransactionDetails(startHeight, endHeight int32,
accountFilter string) ([]*TransactionDetail, error)
// LockOutpoint marks an outpoint as locked meaning it will no longer // LockOutpoint marks an outpoint as locked meaning it will no longer
// be deemed as eligible for coin selection. Locking outputs are // be deemed as eligible for coin selection. Locking outputs are

@ -101,7 +101,7 @@ var (
func assertProperBalance(t *testing.T, lw *lnwallet.LightningWallet, func assertProperBalance(t *testing.T, lw *lnwallet.LightningWallet,
numConfirms int32, amount float64) { numConfirms int32, amount float64) {
balance, err := lw.ConfirmedBalance(numConfirms) balance, err := lw.ConfirmedBalance(numConfirms, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
t.Fatalf("unable to query for balance: %v", err) t.Fatalf("unable to query for balance: %v", err)
} }
@ -208,7 +208,7 @@ func assertTxInWallet(t *testing.T, w *lnwallet.LightningWallet,
// We'll fetch all of our transaction and go through each one until // We'll fetch all of our transaction and go through each one until
// finding the expected transaction with its expected confirmation // finding the expected transaction with its expected confirmation
// status. // status.
txs, err := w.ListTransactionDetails(0, btcwallet.UnconfirmedHeight) txs, err := w.ListTransactionDetails(0, btcwallet.UnconfirmedHeight, "")
if err != nil { if err != nil {
t.Fatalf("unable to retrieve transactions: %v", err) t.Fatalf("unable to retrieve transactions: %v", err)
} }
@ -248,7 +248,7 @@ func loadTestCredits(miner *rpctest.Harness, w *lnwallet.LightningWallet,
if err != nil { if err != nil {
return fmt.Errorf("unable to create amt: %v", err) return fmt.Errorf("unable to create amt: %v", err)
} }
expectedBalance, err := w.ConfirmedBalance(1) expectedBalance, err := w.ConfirmedBalance(1, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
return err return err
} }
@ -294,7 +294,7 @@ func loadTestCredits(miner *rpctest.Harness, w *lnwallet.LightningWallet,
timeout := time.After(30 * time.Second) timeout := time.After(30 * time.Second)
for range ticker.C { for range ticker.C {
balance, err := w.ConfirmedBalance(1) balance, err := w.ConfirmedBalance(1, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
return err return err
} }
@ -1191,7 +1191,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
t.Fatalf("Couldn't sync Alice's wallet: %v", err) t.Fatalf("Couldn't sync Alice's wallet: %v", err)
} }
txDetails, err := alice.ListTransactionDetails( txDetails, err := alice.ListTransactionDetails(
startHeight, chainTip, startHeight, chainTip, "",
) )
if err != nil { if err != nil {
t.Fatalf("unable to fetch tx details: %v", err) t.Fatalf("unable to fetch tx details: %v", err)
@ -1305,7 +1305,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
// with a confirmation height of 0, indicating that it has not been // with a confirmation height of 0, indicating that it has not been
// mined yet. // mined yet.
txDetails, err = alice.ListTransactionDetails( txDetails, err = alice.ListTransactionDetails(
chainTip, btcwallet.UnconfirmedHeight, chainTip, btcwallet.UnconfirmedHeight, "",
) )
if err != nil { if err != nil {
t.Fatalf("unable to fetch tx details: %v", err) t.Fatalf("unable to fetch tx details: %v", err)
@ -1361,9 +1361,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
if err != nil { if err != nil {
t.Fatalf("Couldn't sync Alice's wallet: %v", err) t.Fatalf("Couldn't sync Alice's wallet: %v", err)
} }
txDetails, err = alice.ListTransactionDetails( txDetails, err = alice.ListTransactionDetails(chainTip, chainTip, "")
chainTip, chainTip,
)
if err != nil { if err != nil {
t.Fatalf("unable to fetch tx details: %v", err) t.Fatalf("unable to fetch tx details: %v", err)
} }
@ -1410,9 +1408,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
// Query for transactions only in the latest block. We do not expect // Query for transactions only in the latest block. We do not expect
// any transactions to be returned. // any transactions to be returned.
txDetails, err = alice.ListTransactionDetails( txDetails, err = alice.ListTransactionDetails(chainTip, chainTip, "")
chainTip, chainTip,
)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
@ -2189,7 +2185,7 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet,
} }
// Get the original balance. // Get the original balance.
origBalance, err := w.ConfirmedBalance(1) origBalance, err := w.ConfirmedBalance(1, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
t.Fatalf("unable to query for balance: %v", err) t.Fatalf("unable to query for balance: %v", err)
} }
@ -2205,7 +2201,7 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet,
t.Fatalf("unable to set up mining node: %v", err) t.Fatalf("unable to set up mining node: %v", err)
} }
defer r2.TearDown() defer r2.TearDown()
newBalance, err := w.ConfirmedBalance(1) newBalance, err := w.ConfirmedBalance(1, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
t.Fatalf("unable to query for balance: %v", err) t.Fatalf("unable to query for balance: %v", err)
} }
@ -2297,7 +2293,7 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet,
} }
// Now we check that the wallet balance stays the same. // Now we check that the wallet balance stays the same.
newBalance, err = w.ConfirmedBalance(1) newBalance, err = w.ConfirmedBalance(1, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
t.Fatalf("unable to query for balance: %v", err) t.Fatalf("unable to query for balance: %v", err)
} }
@ -2320,7 +2316,7 @@ func testChangeOutputSpendConfirmation(r *rpctest.Harness,
// Assuming a balance of 80 BTC and a transaction fee of 2500 sat/kw, // Assuming a balance of 80 BTC and a transaction fee of 2500 sat/kw,
// we'll craft the following transaction so that Alice doesn't have any // we'll craft the following transaction so that Alice doesn't have any
// UTXOs left. // UTXOs left.
aliceBalance, err := alice.ConfirmedBalance(0) aliceBalance, err := alice.ConfirmedBalance(0, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
t.Fatalf("unable to retrieve alice's balance: %v", err) t.Fatalf("unable to retrieve alice's balance: %v", err)
} }
@ -2345,7 +2341,7 @@ func testChangeOutputSpendConfirmation(r *rpctest.Harness,
// With the transaction sent and confirmed, Alice's balance should now // With the transaction sent and confirmed, Alice's balance should now
// be 0. // be 0.
aliceBalance, err = alice.ConfirmedBalance(0) aliceBalance, err = alice.ConfirmedBalance(0, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
t.Fatalf("unable to retrieve alice's balance: %v", err) t.Fatalf("unable to retrieve alice's balance: %v", err)
} }
@ -2401,7 +2397,7 @@ func testSpendUnconfirmed(miner *rpctest.Harness,
// First we will empty out bob's wallet, sending the entire balance // First we will empty out bob's wallet, sending the entire balance
// to alice. // to alice.
bobBalance, err := bob.ConfirmedBalance(0) bobBalance, err := bob.ConfirmedBalance(0, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
t.Fatalf("unable to retrieve bob's balance: %v", err) t.Fatalf("unable to retrieve bob's balance: %v", err)
} }

@ -396,14 +396,33 @@ func (l *LightningWallet) Shutdown() error {
return nil return nil
} }
// ConfirmedBalance returns the current confirmed balance of the wallet. This // ConfirmedBalance returns the current confirmed balance of a wallet account.
// methods wraps the interal WalletController method so we're able to properly // This methods wraps the internal WalletController method so we're able to
// hold the coin select mutex while we compute the balance. // properly hold the coin select mutex while we compute the balance.
func (l *LightningWallet) ConfirmedBalance(confs int32) (btcutil.Amount, error) { func (l *LightningWallet) ConfirmedBalance(confs int32,
account string) (btcutil.Amount, error) {
l.coinSelectMtx.Lock() l.coinSelectMtx.Lock()
defer l.coinSelectMtx.Unlock() defer l.coinSelectMtx.Unlock()
return l.WalletController.ConfirmedBalance(confs) return l.WalletController.ConfirmedBalance(confs, account)
}
// ListUnspentWitnessFromDefaultAccount returns all unspent outputs from the
// default wallet account which are version 0 witness programs. The 'minConfs'
// and 'maxConfs' parameters indicate the minimum and maximum number of
// confirmations an output needs in order to be returned by this method. Passing
// -1 as 'minConfs' indicates that even unconfirmed outputs should be returned.
// Using MaxInt32 as 'maxConfs' implies returning all outputs with at least
// 'minConfs'.
//
// NOTE: This method requires the global coin selection lock to be held.
func (l *LightningWallet) ListUnspentWitnessFromDefaultAccount(
minConfs, maxConfs int32) ([]*Utxo, error) {
return l.WalletController.ListUnspentWitness(
minConfs, maxConfs, DefaultAccountName,
)
} }
// LockedOutpoints returns a list of all currently locked outpoint. // LockedOutpoints returns a list of all currently locked outpoint.
@ -922,8 +941,12 @@ func (l *LightningWallet) currentNumAnchorChans() (int, error) {
func (l *LightningWallet) CheckReservedValue(in []wire.OutPoint, func (l *LightningWallet) CheckReservedValue(in []wire.OutPoint,
out []*wire.TxOut, numAnchorChans int) (btcutil.Amount, error) { out []*wire.TxOut, numAnchorChans int) (btcutil.Amount, error) {
// Get all unspent coins in the wallet. // Get all unspent coins in the wallet. We only care about those part of
witnessOutputs, err := l.ListUnspentWitness(0, math.MaxInt32) // the wallet's default account as we know we can readily sign for those
// at any time.
witnessOutputs, err := l.ListUnspentWitnessFromDefaultAccount(
0, math.MaxInt32,
)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -2022,7 +2045,9 @@ func NewCoinSource(w *LightningWallet) *CoinSource {
func (c *CoinSource) ListCoins(minConfs int32, func (c *CoinSource) ListCoins(minConfs int32,
maxConfs int32) ([]chanfunding.Coin, error) { maxConfs int32) ([]chanfunding.Coin, error) {
utxos, err := c.wallet.ListUnspentWitness(minConfs, maxConfs) utxos, err := c.wallet.ListUnspentWitnessFromDefaultAccount(
minConfs, maxConfs,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -12,6 +12,7 @@ import (
"github.com/lightningnetwork/lnd/chainreg" "github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/funding" "github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/tor" "github.com/lightningnetwork/lnd/tor"
) )
@ -180,7 +181,9 @@ func initAutoPilot(svr *server, cfg *lncfg.AutoPilot,
netParams: netParams, netParams: netParams,
}, },
WalletBalance: func() (btcutil.Amount, error) { WalletBalance: func() (btcutil.Amount, error) {
return svr.cc.Wallet.ConfirmedBalance(cfg.MinConfs) return svr.cc.Wallet.ConfirmedBalance(
cfg.MinConfs, lnwallet.DefaultAccountName,
)
}, },
Graph: autopilot.ChannelGraphFromDatabase(svr.localChanDB.ChannelGraph()), Graph: autopilot.ChannelGraphFromDatabase(svr.localChanDB.ChannelGraph()),
Constraints: atplConstraints, Constraints: atplConstraints,

@ -1023,7 +1023,7 @@ func (r *rpcServer) ListUnspent(ctx context.Context,
var utxos []*lnwallet.Utxo var utxos []*lnwallet.Utxo
err = r.server.cc.Wallet.WithCoinSelectLock(func() error { err = r.server.cc.Wallet.WithCoinSelectLock(func() error {
utxos, err = r.server.cc.Wallet.ListUnspentWitness( utxos, err = r.server.cc.Wallet.ListUnspentWitness(
minConfs, maxConfs, minConfs, maxConfs, "",
) )
return err return err
}) })
@ -1191,7 +1191,7 @@ func (r *rpcServer) SendCoins(ctx context.Context,
sweepTxPkg, err := sweep.CraftSweepAllTx( sweepTxPkg, err := sweep.CraftSweepAllTx(
feePerKw, lnwallet.DefaultDustLimit(), feePerKw, lnwallet.DefaultDustLimit(),
uint32(bestHeight), nil, targetAddr, wallet, uint32(bestHeight), nil, targetAddr, wallet,
wallet.WalletController, wallet.WalletController, wallet, wallet.WalletController,
r.server.cc.FeeEstimator, r.server.cc.Signer, r.server.cc.FeeEstimator, r.server.cc.Signer,
) )
if err != nil { if err != nil {
@ -1243,7 +1243,7 @@ func (r *rpcServer) SendCoins(ctx context.Context,
sweepTxPkg, err = sweep.CraftSweepAllTx( sweepTxPkg, err = sweep.CraftSweepAllTx(
feePerKw, lnwallet.DefaultDustLimit(), feePerKw, lnwallet.DefaultDustLimit(),
uint32(bestHeight), outputs, targetAddr, wallet, uint32(bestHeight), outputs, targetAddr, wallet,
wallet.WalletController, wallet.WalletController, wallet, wallet.WalletController,
r.server.cc.FeeEstimator, r.server.cc.Signer, r.server.cc.FeeEstimator, r.server.cc.Signer,
) )
if err != nil { if err != nil {
@ -2763,7 +2763,9 @@ func (r *rpcServer) WalletBalance(ctx context.Context,
in *lnrpc.WalletBalanceRequest) (*lnrpc.WalletBalanceResponse, error) { in *lnrpc.WalletBalanceRequest) (*lnrpc.WalletBalanceResponse, error) {
// Get total balance, from txs that have >= 0 confirmations. // Get total balance, from txs that have >= 0 confirmations.
totalBal, err := r.server.cc.Wallet.ConfirmedBalance(0) totalBal, err := r.server.cc.Wallet.ConfirmedBalance(
0, lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2771,7 +2773,9 @@ func (r *rpcServer) WalletBalance(ctx context.Context,
// Get confirmed balance, from txs that have >= 1 confirmations. // Get confirmed balance, from txs that have >= 1 confirmations.
// TODO(halseth): get both unconfirmed and confirmed balance in one // TODO(halseth): get both unconfirmed and confirmed balance in one
// call, as this is racy. // call, as this is racy.
confirmedBal, err := r.server.cc.Wallet.ConfirmedBalance(1) confirmedBal, err := r.server.cc.Wallet.ConfirmedBalance(
1, lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -4963,7 +4967,7 @@ func (r *rpcServer) GetTransactions(ctx context.Context,
} }
transactions, err := r.server.cc.Wallet.ListTransactionDetails( transactions, err := r.server.cc.Wallet.ListTransactionDetails(
req.StartHeight, endHeight, req.StartHeight, endHeight, "",
) )
if err != nil { if err != nil {
return nil, err return nil, err

@ -87,7 +87,7 @@ func (b *mockBackend) PublishTransaction(tx *wire.MsgTx, _ string) error {
return err return err
} }
func (b *mockBackend) ListUnspentWitness(minconfirms, maxconfirms int32) ( func (b *mockBackend) ListUnspentWitnessFromDefaultAccount(minconfirms, maxconfirms int32) (
[]*lnwallet.Utxo, error) { []*lnwallet.Utxo, error) {
b.lock.Lock() b.lock.Lock()
defer b.lock.Unlock() defer b.lock.Unlock()

@ -11,12 +11,13 @@ type Wallet interface {
// broadcasts the passed transaction to the Bitcoin network. // broadcasts the passed transaction to the Bitcoin network.
PublishTransaction(tx *wire.MsgTx, label string) error PublishTransaction(tx *wire.MsgTx, label string) error
// ListUnspentWitness returns all unspent outputs which are version 0 // ListUnspentWitnessFromDefaultAccount returns all unspent outputs
// witness programs. The 'minconfirms' and 'maxconfirms' parameters // which are version 0 witness programs from the default wallet account.
// indicate the minimum and maximum number of confirmations an output // The 'minconfirms' and 'maxconfirms' parameters indicate the minimum
// needs in order to be returned by this method. // and maximum number of confirmations an output needs in order to be
ListUnspentWitness(minconfirms, maxconfirms int32) ([]*lnwallet.Utxo, // returned by this method.
error) ListUnspentWitnessFromDefaultAccount(minconfirms, maxconfirms int32) (
[]*lnwallet.Utxo, error)
// WithCoinSelectLock will execute the passed function closure in a // WithCoinSelectLock will execute the passed function closure in a
// synchronized manner preventing any coin selection operations from // synchronized manner preventing any coin selection operations from

@ -333,7 +333,9 @@ func (t *txInputSet) tryAddWalletInputsIfNeeded() error {
// Retrieve wallet utxos. Only consider confirmed utxos to prevent // Retrieve wallet utxos. Only consider confirmed utxos to prevent
// problems around RBF rules for unconfirmed inputs. // problems around RBF rules for unconfirmed inputs.
utxos, err := t.wallet.ListUnspentWitness(1, math.MaxInt32) utxos, err := t.wallet.ListUnspentWitnessFromDefaultAccount(
1, math.MaxInt32,
)
if err != nil { if err != nil {
return err return err
} }

@ -112,7 +112,7 @@ type mockWallet struct {
Wallet Wallet
} }
func (m *mockWallet) ListUnspentWitness(minconfirms, maxconfirms int32) ( func (m *mockWallet) ListUnspentWitnessFromDefaultAccount(minconfirms, maxconfirms int32) (
[]*lnwallet.Utxo, error) { []*lnwallet.Utxo, error) {
return []*lnwallet.Utxo{ return []*lnwallet.Utxo{

@ -99,9 +99,10 @@ func DetermineFeePerKw(feeEstimator chainfee.Estimator,
// UtxoSource is an interface that allows a caller to access a source of UTXOs // UtxoSource is an interface that allows a caller to access a source of UTXOs
// to use when crafting sweep transactions. // to use when crafting sweep transactions.
type UtxoSource interface { type UtxoSource interface {
// ListUnspentWitness returns all UTXOs from the source that have // ListUnspentWitness returns all UTXOs from the default wallet account
// between minConfs and maxConfs number of confirmations. // that have between minConfs and maxConfs number of confirmations.
ListUnspentWitness(minConfs, maxConfs int32) ([]*lnwallet.Utxo, error) ListUnspentWitnessFromDefaultAccount(minConfs, maxConfs int32) (
[]*lnwallet.Utxo, error)
} }
// CoinSelectionLocker is an interface that allows the caller to perform an // CoinSelectionLocker is an interface that allows the caller to perform an
@ -192,7 +193,7 @@ func CraftSweepAllTx(feeRate chainfee.SatPerKWeight, dustLimit btcutil.Amount,
// Now that we can be sure that no other coin selection // Now that we can be sure that no other coin selection
// operations are going on, we can grab a clean snapshot of the // operations are going on, we can grab a clean snapshot of the
// current UTXO state of the wallet. // current UTXO state of the wallet.
utxos, err := utxoSource.ListUnspentWitness( utxos, err := utxoSource.ListUnspentWitnessFromDefaultAccount(
1, math.MaxInt32, 1, math.MaxInt32,
) )
if err != nil { if err != nil {

@ -119,7 +119,7 @@ func newMockUtxoSource(utxos []*lnwallet.Utxo) *mockUtxoSource {
} }
} }
func (m *mockUtxoSource) ListUnspentWitness(minConfs int32, func (m *mockUtxoSource) ListUnspentWitnessFromDefaultAccount(minConfs int32,
maxConfs int32) ([]*lnwallet.Utxo, error) { maxConfs int32) ([]*lnwallet.Utxo, error) {
return m.outputs, nil return m.outputs, nil