chainntnfs/bitcoindnotify: add chainParams parameter to bitcoindnotify.New

In this commit, we add the current chain parameters to the
BitcoindNotifier. This will be used in a future commit in order to
convert outputs scripts into addresses. This is needed since the
bitcoind backend uses these addresses to detect whether the script
encoded within it was spent by a transaction in the chain.
This commit is contained in:
Wilmer Paulino
2018-12-06 21:14:04 -08:00
parent 1ee8d7518c
commit 686e734e22
3 changed files with 25 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcwallet/chain"
"github.com/lightningnetwork/lnd/chainntnfs"
)
@@ -11,9 +12,9 @@ import (
// createNewNotifier creates a new instance of the ChainNotifier interface
// implemented by BitcoindNotifier.
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
if len(args) != 3 {
if len(args) != 4 {
return nil, fmt.Errorf("incorrect number of arguments to "+
".New(...), expected 2, instead passed %v", len(args))
".New(...), expected 4, instead passed %v", len(args))
}
chainConn, ok := args[0].(*chain.BitcoindConn)
@@ -22,19 +23,25 @@ func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
"is incorrect, expected a *chain.BitcoindConn")
}
spendHintCache, ok := args[1].(chainntnfs.SpendHintCache)
chainParams, ok := args[1].(*chaincfg.Params)
if !ok {
return nil, errors.New("second argument to bitcoindnotify.New " +
"is incorrect, expected a *chaincfg.Params")
}
spendHintCache, ok := args[2].(chainntnfs.SpendHintCache)
if !ok {
return nil, errors.New("third argument to bitcoindnotify.New " +
"is incorrect, expected a chainntnfs.SpendHintCache")
}
confirmHintCache, ok := args[2].(chainntnfs.ConfirmHintCache)
confirmHintCache, ok := args[3].(chainntnfs.ConfirmHintCache)
if !ok {
return nil, errors.New("third argument to bitcoindnotify.New " +
return nil, errors.New("fourth argument to bitcoindnotify.New " +
"is incorrect, expected a chainntnfs.ConfirmHintCache")
}
return New(chainConn, spendHintCache, confirmHintCache), nil
return New(chainConn, chainParams, spendHintCache, confirmHintCache), nil
}
// init registers a driver for the BtcdNotifier concrete implementation of the