lnwallet: modify FetchInputInfo to return additional information for utxos

This commit is contained in:
Wilmer Paulino committed 2019-08-22 13:49:41 -07:00
1 parent 8b398bdbd1
commit 9e8a1707cc
5 files changed
+54 -20

No files matched your search

+33 -8
View File
@@ -1,6 +1,8 @@
package btcwallet
import (
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
@@ -21,11 +23,7 @@ import (
// of ErrNotMine should be returned instead.
//
// This is a part of the WalletController interface.
func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error) {
var (
err error
output *wire.TxOut
)
func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*lnwallet.Utxo, error) {
// We manually look up the output within the tx store.
txid := &prevOut.Hash
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
// above only guarantees that the transaction is somehow relevant to us,
// like in the event of us being the sender of the transaction.
output = txDetail.TxRecord.MsgTx.TxOut[prevOut.Index]
if _, err := b.fetchOutputAddr(output.PkScript); err != nil {
pkScript := txDetail.TxRecord.MsgTx.TxOut[prevOut.Index].PkScript
if _, err := b.fetchOutputAddr(pkScript); err != nil {
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
+1 -1
View File
@@ -135,7 +135,7 @@ type WalletController interface {
// passed outpoint. If the base wallet determines this output is under
// its control, then the original txout should be returned. Otherwise,
// 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
// that have at least confs confirmations. If confs is set to zero,
+4 -1
View File
@@ -774,7 +774,10 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
return
}
signDesc.Output = info
signDesc.Output = &wire.TxOut{
PkScript: info.PkScript,
Value: int64(info.Value),
}
signDesc.InputIndex = i
inputScript, err := l.Cfg.Signer.ComputeInputScript(