diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index f9039ea7..9554f6f7 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -206,28 +206,17 @@ func (b *BtcWallet) Stop() error { // final sum. // // This is a part of the WalletController interface. -func (b *BtcWallet) ConfirmedBalance(confs int32, witness bool) (btcutil.Amount, error) { +func (b *BtcWallet) ConfirmedBalance(confs int32) (btcutil.Amount, error) { var balance btcutil.Amount - if witness { - witnessOutputs, err := b.ListUnspentWitness(confs) - if err != nil { - return 0, err - } - - for _, witnessOutput := range witnessOutputs { - balance += witnessOutput.Value - } - } else { - outputSum, err := b.wallet.CalculateBalance(confs) - if err != nil { - return 0, err - } - - balance = outputSum + witnessOutputs, err := b.ListUnspentWitness(confs) + if err != nil { + return 0, err } - // TODO(roasbeef): remove witness only distinction? + for _, witnessOutput := range witnessOutputs { + balance += witnessOutput.Value + } return balance, nil } diff --git a/lnwallet/interface.go b/lnwallet/interface.go index 58af4fd2..e5ad9bb8 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -20,19 +20,16 @@ var ErrNotMine = errors.New("the passed output doesn't belong to the wallet") type AddressType uint8 const ( - // UnknownAddressType represents an output with an unknown or non-standard - // script. - UnknownAddressType AddressType = iota - // WitnessPubKey represents a p2wkh address. - WitnessPubKey + WitnessPubKey AddressType = iota // NestedWitnessPubKey represents a p2sh output which is itself a // nested p2wkh output. NestedWitnessPubKey - // PubKeyHash represents a regular p2pkh output. - PubKeyHash + // UnknownAddressType represents an output with an unknown or non-standard + // script. + UnknownAddressType ) // ErrDoubleSpend is returned from PublishTransaction in case the @@ -127,14 +124,18 @@ type WalletController interface { // that 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 final sum. - ConfirmedBalance(confs int32, witness bool) (btcutil.Amount, error) + // + // NOTE: Only witness outputs should be included in the computation of + // the total spendable balance of the wallet. We require this as only + // witness inputs can be used for funding channels. + ConfirmedBalance(confs int32) (btcutil.Amount, error) // NewAddress returns the next external or internal address for the // wallet dictated by the value of the `change` parameter. If change is // true, then an internal address should be used, otherwise an external // address should be returned. The type of address returned is dictated - // by the wallet's capabilities, and may be of type: p2sh, p2pkh, - // p2wkh, p2wsh, etc. + // by the wallet's capabilities, and may be of type: p2sh, p2wkh, + // p2wsh, etc. NewAddress(addrType AddressType, change bool) (btcutil.Address, error) // GetPrivKey retrieves the underlying private key associated with the