2016-08-04 08:13:10 +03:00
|
|
|
package btcdnotify
|
|
|
|
|
|
|
|
import (
|
2018-08-15 03:53:34 +03:00
|
|
|
"errors"
|
2016-08-04 08:13:10 +03:00
|
|
|
"fmt"
|
|
|
|
|
2018-12-07 08:14:02 +03:00
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
2018-06-05 04:34:16 +03:00
|
|
|
"github.com/btcsuite/btcd/rpcclient"
|
2018-07-31 10:17:17 +03:00
|
|
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
2016-08-04 08:13:10 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// createNewNotifier creates a new instance of the ChainNotifier interface
|
|
|
|
// implemented by BtcdNotifier.
|
|
|
|
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
|
2018-12-07 08:14:02 +03:00
|
|
|
if len(args) != 4 {
|
2018-08-15 03:53:34 +03:00
|
|
|
return nil, fmt.Errorf("incorrect number of arguments to "+
|
2018-12-07 08:14:02 +03:00
|
|
|
".New(...), expected 4, instead passed %v", len(args))
|
2016-08-04 08:13:10 +03:00
|
|
|
}
|
|
|
|
|
2017-08-25 04:54:17 +03:00
|
|
|
config, ok := args[0].(*rpcclient.ConnConfig)
|
2016-08-04 08:13:10 +03:00
|
|
|
if !ok {
|
2018-12-07 08:14:02 +03:00
|
|
|
return nil, errors.New("first argument to btcdnotify.New " +
|
2018-08-15 03:53:34 +03:00
|
|
|
"is incorrect, expected a *rpcclient.ConnConfig")
|
2016-08-04 08:13:10 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 08:14:02 +03:00
|
|
|
chainParams, ok := args[1].(*chaincfg.Params)
|
2018-08-15 03:53:34 +03:00
|
|
|
if !ok {
|
2018-12-07 08:14:02 +03:00
|
|
|
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 " +
|
2018-08-15 03:53:34 +03:00
|
|
|
"is incorrect, expected a chainntnfs.SpendHintCache")
|
|
|
|
}
|
|
|
|
|
2018-12-07 08:14:02 +03:00
|
|
|
confirmHintCache, ok := args[3].(chainntnfs.ConfirmHintCache)
|
2018-08-15 03:53:34 +03:00
|
|
|
if !ok {
|
2018-12-07 08:14:02 +03:00
|
|
|
return nil, errors.New("fourth argument to btcdnotify.New " +
|
2018-08-15 03:53:34 +03:00
|
|
|
"is incorrect, expected a chainntnfs.ConfirmHintCache")
|
|
|
|
}
|
|
|
|
|
2018-12-07 08:14:02 +03:00
|
|
|
return New(config, chainParams, spendHintCache, confirmHintCache)
|
2016-08-04 08:13:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|
|
|
|
}
|