2016-08-04 08:13:10 +03:00
|
|
|
package btcdnotify
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
2017-08-25 04:54:17 +03:00
|
|
|
"github.com/roasbeef/btcd/rpcclient"
|
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) {
|
|
|
|
if len(args) != 1 {
|
|
|
|
return nil, fmt.Errorf("incorrect number of arguments to .New(...), "+
|
|
|
|
"expected 1, instead passed %v", len(args))
|
|
|
|
}
|
|
|
|
|
2017-08-25 04:54:17 +03:00
|
|
|
config, ok := args[0].(*rpcclient.ConnConfig)
|
2016-08-04 08:13:10 +03:00
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("first argument to btcdnotifier.New is " +
|
2017-08-25 04:54:17 +03:00
|
|
|
"incorrect, expected a *rpcclient.ConnConfig")
|
2016-08-04 08:13:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return New(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|
|
|
|
}
|