lnwallet: modify FetchInputInfo to return additional information for utxos
This commit is contained in:
parent
8b398bdbd1
commit
9e8a1707cc
@ -496,23 +496,26 @@ func (w *WalletKit) BumpFee(ctx context.Context,
|
|||||||
//
|
//
|
||||||
// We'll gather all of the information required by the UtxoSweeper in
|
// We'll gather all of the information required by the UtxoSweeper in
|
||||||
// order to sweep the output.
|
// order to sweep the output.
|
||||||
txOut, err := w.cfg.Wallet.FetchInputInfo(op)
|
utxo, err := w.cfg.Wallet.FetchInputInfo(op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var witnessType input.WitnessType
|
var witnessType input.WitnessType
|
||||||
switch {
|
switch utxo.AddressType {
|
||||||
case txscript.IsPayToWitnessPubKeyHash(txOut.PkScript):
|
case lnwallet.WitnessPubKey:
|
||||||
witnessType = input.WitnessKeyHash
|
witnessType = input.WitnessKeyHash
|
||||||
case txscript.IsPayToScriptHash(txOut.PkScript):
|
case lnwallet.NestedWitnessPubKey:
|
||||||
witnessType = input.NestedWitnessKeyHash
|
witnessType = input.NestedWitnessKeyHash
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown input witness %v", op)
|
return nil, fmt.Errorf("unknown input witness %v", op)
|
||||||
}
|
}
|
||||||
|
|
||||||
signDesc := &input.SignDescriptor{
|
signDesc := &input.SignDescriptor{
|
||||||
Output: txOut,
|
Output: &wire.TxOut{
|
||||||
|
PkScript: utxo.PkScript,
|
||||||
|
Value: int64(utxo.Value),
|
||||||
|
},
|
||||||
HashType: txscript.SigHashAll,
|
HashType: txscript.SigHashAll,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package btcwallet
|
package btcwallet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
@ -21,11 +23,7 @@ import (
|
|||||||
// of ErrNotMine should be returned instead.
|
// of ErrNotMine should be returned instead.
|
||||||
//
|
//
|
||||||
// This is a part of the WalletController interface.
|
// This is a part of the WalletController interface.
|
||||||
func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error) {
|
func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*lnwallet.Utxo, error) {
|
||||||
var (
|
|
||||||
err error
|
|
||||||
output *wire.TxOut
|
|
||||||
)
|
|
||||||
// We manually look up the output within the tx store.
|
// We manually look up the output within the tx store.
|
||||||
txid := &prevOut.Hash
|
txid := &prevOut.Hash
|
||||||
txDetail, err := base.UnstableAPI(b.wallet).TxDetails(txid)
|
txDetail, err := base.UnstableAPI(b.wallet).TxDetails(txid)
|
||||||
@ -39,13 +37,40 @@ func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error)
|
|||||||
// we actually have control of this output. We do this because the check
|
// we actually have control of this output. We do this because the check
|
||||||
// above only guarantees that the transaction is somehow relevant to us,
|
// above only guarantees that the transaction is somehow relevant to us,
|
||||||
// like in the event of us being the sender of the transaction.
|
// like in the event of us being the sender of the transaction.
|
||||||
output = txDetail.TxRecord.MsgTx.TxOut[prevOut.Index]
|
pkScript := txDetail.TxRecord.MsgTx.TxOut[prevOut.Index].PkScript
|
||||||
if _, err := b.fetchOutputAddr(output.PkScript); err != nil {
|
if _, err := b.fetchOutputAddr(pkScript); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Then, we'll populate all of the information required by the struct.
|
||||||
|
addressType := lnwallet.UnknownAddressType
|
||||||
|
switch {
|
||||||
|
case txscript.IsPayToWitnessPubKeyHash(pkScript):
|
||||||
|
addressType = lnwallet.WitnessPubKey
|
||||||
|
case txscript.IsPayToScriptHash(pkScript):
|
||||||
|
addressType = lnwallet.NestedWitnessPubKey
|
||||||
|
}
|
||||||
|
|
||||||
return output, nil
|
// Determine the number of confirmations the output currently has.
|
||||||
|
_, currentHeight, err := b.GetBestBlock()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to retrieve current height: %v",
|
||||||
|
err)
|
||||||
|
}
|
||||||
|
confs := int64(0)
|
||||||
|
if txDetail.Block.Height != -1 {
|
||||||
|
confs = int64(currentHeight - txDetail.Block.Height)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &lnwallet.Utxo{
|
||||||
|
AddressType: addressType,
|
||||||
|
Value: btcutil.Amount(
|
||||||
|
txDetail.TxRecord.MsgTx.TxOut[prevOut.Index].Value,
|
||||||
|
),
|
||||||
|
PkScript: pkScript,
|
||||||
|
Confirmations: confs,
|
||||||
|
OutPoint: *prevOut,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchOutputAddr attempts to fetch the managed address corresponding to the
|
// fetchOutputAddr attempts to fetch the managed address corresponding to the
|
||||||
|
@ -135,7 +135,7 @@ type WalletController interface {
|
|||||||
// passed outpoint. If the base wallet determines this output is under
|
// passed outpoint. If the base wallet determines this output is under
|
||||||
// its control, then the original txout should be returned. Otherwise,
|
// its control, then the original txout should be returned. Otherwise,
|
||||||
// a non-nil error value of ErrNotMine should be returned instead.
|
// a non-nil error value of ErrNotMine should be returned instead.
|
||||||
FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error)
|
FetchInputInfo(prevOut *wire.OutPoint) (*Utxo, error)
|
||||||
|
|
||||||
// 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,
|
||||||
|
@ -774,7 +774,10 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
signDesc.Output = info
|
signDesc.Output = &wire.TxOut{
|
||||||
|
PkScript: info.PkScript,
|
||||||
|
Value: int64(info.Value),
|
||||||
|
}
|
||||||
signDesc.InputIndex = i
|
signDesc.InputIndex = i
|
||||||
|
|
||||||
inputScript, err := l.Cfg.Signer.ComputeInputScript(
|
inputScript, err := l.Cfg.Signer.ComputeInputScript(
|
||||||
|
13
mock.go
13
mock.go
@ -242,12 +242,15 @@ func (*mockWalletController) BackEnd() string {
|
|||||||
// FetchInputInfo will be called to get info about the inputs to the funding
|
// FetchInputInfo will be called to get info about the inputs to the funding
|
||||||
// transaction.
|
// transaction.
|
||||||
func (*mockWalletController) FetchInputInfo(
|
func (*mockWalletController) FetchInputInfo(
|
||||||
prevOut *wire.OutPoint) (*wire.TxOut, error) {
|
prevOut *wire.OutPoint) (*lnwallet.Utxo, error) {
|
||||||
txOut := &wire.TxOut{
|
utxo := &lnwallet.Utxo{
|
||||||
Value: int64(10 * btcutil.SatoshiPerBitcoin),
|
AddressType: lnwallet.WitnessPubKey,
|
||||||
PkScript: []byte("dummy"),
|
Value: 10 * btcutil.SatoshiPerBitcoin,
|
||||||
|
PkScript: []byte("dummy"),
|
||||||
|
Confirmations: 1,
|
||||||
|
OutPoint: *prevOut,
|
||||||
}
|
}
|
||||||
return txOut, nil
|
return utxo, nil
|
||||||
}
|
}
|
||||||
func (*mockWalletController) ConfirmedBalance(confs int32) (btcutil.Amount, error) {
|
func (*mockWalletController) ConfirmedBalance(confs int32) (btcutil.Amount, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user