lnwallet: Extend Utxo struct with AddressType.
The Utxo struct now includes the address type and redeem/witness scripts. This is necessary for accurate fee estimation.
This commit is contained in:
parent
10a336db46
commit
c94130328a
@ -353,17 +353,28 @@ func (b *BtcWallet) ListUnspentWitness(minConfs int32) ([]*lnwallet.Utxo, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO(roasbeef): this assumes all p2sh outputs returned by
|
||||
// the wallet are nested p2sh...
|
||||
if txscript.IsPayToWitnessPubKeyHash(pkScript) ||
|
||||
txscript.IsPayToScriptHash(pkScript) {
|
||||
var addressType lnwallet.AddressType
|
||||
if txscript.IsPayToWitnessPubKeyHash(pkScript) {
|
||||
addressType = lnwallet.WitnessPubKey
|
||||
} else if txscript.IsPayToScriptHash(pkScript) {
|
||||
// TODO(roasbeef): This assumes all p2sh outputs returned by the
|
||||
// wallet are nested p2pkh. We can't check the redeem script because
|
||||
// the btcwallet service does not include it.
|
||||
addressType = lnwallet.NestedWitnessPubKey
|
||||
}
|
||||
|
||||
if addressType == lnwallet.WitnessPubKey ||
|
||||
addressType == lnwallet.NestedWitnessPubKey {
|
||||
|
||||
txid, err := chainhash.NewHashFromStr(output.TxID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
utxo := &lnwallet.Utxo{
|
||||
AddressType: addressType,
|
||||
Value: btcutil.Amount(output.Amount * 1e8),
|
||||
PkScript: pkScript,
|
||||
OutPoint: wire.OutPoint{
|
||||
Hash: *txid,
|
||||
Index: output.Vout,
|
||||
|
@ -20,8 +20,12 @@ 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 AddressType = iota
|
||||
WitnessPubKey
|
||||
|
||||
// NestedWitnessPubKey represents a p2sh output which is itself a
|
||||
// nested p2wkh output.
|
||||
@ -34,7 +38,11 @@ const (
|
||||
// Utxo is an unspent output denoted by its outpoint, and output value of the
|
||||
// original output.
|
||||
type Utxo struct {
|
||||
AddressType AddressType
|
||||
Value btcutil.Amount
|
||||
PkScript []byte
|
||||
RedeemScript []byte
|
||||
WitnessScript []byte
|
||||
wire.OutPoint
|
||||
}
|
||||
|
||||
|
2
mock.go
2
mock.go
@ -149,7 +149,9 @@ func (*mockWalletController) SendOutputs(outputs []*wire.TxOut) (*chainhash.Hash
|
||||
// need one unspent for the funding transaction.
|
||||
func (*mockWalletController) ListUnspentWitness(confirms int32) ([]*lnwallet.Utxo, error) {
|
||||
utxo := &lnwallet.Utxo{
|
||||
AddressType: lnwallet.WitnessPubKey,
|
||||
Value: btcutil.Amount(10 * btcutil.SatoshiPerBitcoin),
|
||||
PkScript: make([]byte, 22),
|
||||
OutPoint: wire.OutPoint{
|
||||
Hash: chainhash.Hash{},
|
||||
Index: 0,
|
||||
|
Loading…
Reference in New Issue
Block a user