diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index 4e900608..4d83ae62 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -9,6 +9,7 @@ import ( "time" "github.com/btcsuite/btcd/btcjson" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/rpcclient" "github.com/btcsuite/btcd/wire" @@ -64,7 +65,8 @@ type BtcdNotifier struct { started int32 // To be used atomically. stopped int32 // To be used atomically. - chainConn *rpcclient.Client + chainConn *rpcclient.Client + chainParams *chaincfg.Params notificationCancels chan interface{} notificationRegistry chan interface{} @@ -98,10 +100,13 @@ var _ chainntnfs.ChainNotifier = (*BtcdNotifier)(nil) // New returns a new BtcdNotifier instance. This function assumes the btcd node // detailed in the passed configuration is already running, and willing to // accept new websockets clients. -func New(config *rpcclient.ConnConfig, spendHintCache chainntnfs.SpendHintCache, +func New(config *rpcclient.ConnConfig, chainParams *chaincfg.Params, + spendHintCache chainntnfs.SpendHintCache, confirmHintCache chainntnfs.ConfirmHintCache) (*BtcdNotifier, error) { notifier := &BtcdNotifier{ + chainParams: chainParams, + notificationCancels: make(chan interface{}), notificationRegistry: make(chan interface{}), diff --git a/chainntnfs/btcdnotify/btcd_test.go b/chainntnfs/btcdnotify/btcd_test.go index 18bd1bb3..f76f9b94 100644 --- a/chainntnfs/btcdnotify/btcd_test.go +++ b/chainntnfs/btcdnotify/btcd_test.go @@ -37,7 +37,7 @@ func setUpNotifier(t *testing.T, h *rpctest.Harness) *BtcdNotifier { hintCache := initHintCache(t) rpcCfg := h.RPCConfig() - notifier, err := New(&rpcCfg, hintCache, hintCache) + notifier, err := New(&rpcCfg, chainntnfs.NetParams, hintCache, hintCache) if err != nil { t.Fatalf("unable to create notifier: %v", err) } diff --git a/chainntnfs/btcdnotify/driver.go b/chainntnfs/btcdnotify/driver.go index 1cda9192..901426f2 100644 --- a/chainntnfs/btcdnotify/driver.go +++ b/chainntnfs/btcdnotify/driver.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/rpcclient" "github.com/lightningnetwork/lnd/chainntnfs" ) @@ -11,30 +12,36 @@ import ( // createNewNotifier creates a new instance of the ChainNotifier interface // implemented by BtcdNotifier. 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)) } config, ok := args[0].(*rpcclient.ConnConfig) if !ok { - return nil, errors.New("first argument to btcdnotifier.New " + + return nil, errors.New("first argument to btcdnotify.New " + "is incorrect, expected a *rpcclient.ConnConfig") } - spendHintCache, ok := args[1].(chainntnfs.SpendHintCache) + chainParams, ok := args[1].(*chaincfg.Params) if !ok { - return nil, errors.New("second argument to btcdnotifier.New " + + return nil, errors.New("second argument to btcdnotify.New " + + "is incorrect, expected a *chaincfg.Params") + } + + spendHintCache, ok := args[2].(chainntnfs.SpendHintCache) + if !ok { + return nil, errors.New("third argument to btcdnotify.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 btcdnotifier.New " + + return nil, errors.New("fourth argument to btcdnotify.New " + "is incorrect, expected a chainntnfs.ConfirmHintCache") } - return New(config, spendHintCache, confirmHintCache) + return New(config, chainParams, spendHintCache, confirmHintCache) } // init registers a driver for the BtcdNotifier concrete implementation of the