lnwallet: remove p2pkh as an address type, wallet is now pure segwit

In this commit, we modify the mechanics of the wallet to only allow
derivation of segwit-like addresses. Additionally, the ConfirmedBalance
method on the WalletController now only has a single argument, as it’s
assumed that the wallet is itself only concerned with segwit outputs.
This commit is contained in:
Olaoluwa Osuntokun 2018-02-17 15:36:53 -08:00
parent 4b20e805fe
commit a144018e98
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 18 additions and 28 deletions

View File

@ -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
}

View File

@ -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