lnwallet/btcwallet: fix bug in GetUtxo for BlockChainIO implementation

This commit fixes an unnoticed bug within btcwallet’s implementation of
the BlockChainIO interface, specifically the GetUtxo method. In order
to maintain compatibility with Bitcoin Core’s gettxout method, btcd
doesn’t return an error if the targeted output is actually spent.

We weren’t properly detecting this, but we do now by creating a new
error which is returned in the case of a nil error but a nil return
value.
This commit is contained in:
Olaoluwa Osuntokun 2016-12-26 23:30:24 -06:00
parent 98471256fa
commit 473f298524
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

View File

@ -2,11 +2,18 @@ package btcwallet
import (
"encoding/hex"
"errors"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/roasbeef/btcd/wire"
)
var (
// ErrOutputSpent is returned by the GetUtxo method if the target output
// for lookup has already been spent.
ErrOutputSpent = errors.New("target output has been spent")
)
// GetBestBlock returns the current height and hash of the best known block
// within the main chain.
//
@ -22,6 +29,8 @@ func (b *BtcWallet) GetUtxo(txid *wire.ShaHash, index uint32) (*wire.TxOut, erro
txout, err := b.rpc.GetTxOut(txid, index, false)
if err != nil {
return nil, err
} else if txout == nil {
return nil, ErrOutputSpent
}
pkScript, err := hex.DecodeString(txout.ScriptPubKey.Hex)