1ee8d7518c
In this commit, we add the current chain parameters to the BtcdNotifier. This will be used in a future commit in order to convert outputs scripts into addresses. This is needed since the btcd backend uses these addresses to detect whether the script encoded within it was spent by a transaction in the chain.
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package btcdnotify
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
"github.com/btcsuite/btcd/rpcclient"
|
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
|
)
|
|
|
|
// createNewNotifier creates a new instance of the ChainNotifier interface
|
|
// implemented by BtcdNotifier.
|
|
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
|
|
if len(args) != 4 {
|
|
return nil, fmt.Errorf("incorrect number of arguments to "+
|
|
".New(...), expected 4, instead passed %v", len(args))
|
|
}
|
|
|
|
config, ok := args[0].(*rpcclient.ConnConfig)
|
|
if !ok {
|
|
return nil, errors.New("first argument to btcdnotify.New " +
|
|
"is incorrect, expected a *rpcclient.ConnConfig")
|
|
}
|
|
|
|
chainParams, ok := args[1].(*chaincfg.Params)
|
|
if !ok {
|
|
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[3].(chainntnfs.ConfirmHintCache)
|
|
if !ok {
|
|
return nil, errors.New("fourth argument to btcdnotify.New " +
|
|
"is incorrect, expected a chainntnfs.ConfirmHintCache")
|
|
}
|
|
|
|
return New(config, chainParams, spendHintCache, confirmHintCache)
|
|
}
|
|
|
|
// init registers a driver for the BtcdNotifier concrete implementation of the
|
|
// chainntnfs.ChainNotifier interface.
|
|
func init() {
|
|
// Register the driver.
|
|
notifier := &chainntnfs.NotifierDriver{
|
|
NotifierType: notifierType,
|
|
New: createNewNotifier,
|
|
}
|
|
|
|
if err := chainntnfs.RegisterNotifier(notifier); err != nil {
|
|
panic(fmt.Sprintf("failed to register notifier driver '%s': %v",
|
|
notifierType, err))
|
|
}
|
|
}
|