2017-11-10 03:30:20 +03:00
|
|
|
package bitcoindnotify
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-07-17 02:50:47 +03:00
|
|
|
"github.com/btcsuite/btcwallet/chain"
|
2018-07-31 10:17:17 +03:00
|
|
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
2017-11-10 03:30:20 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// createNewNotifier creates a new instance of the ChainNotifier interface
|
|
|
|
// implemented by BitcoindNotifier.
|
|
|
|
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
|
2018-07-17 02:50:47 +03:00
|
|
|
if len(args) != 1 {
|
2017-11-10 03:30:20 +03:00
|
|
|
return nil, fmt.Errorf("incorrect number of arguments to "+
|
2018-07-17 02:50:47 +03:00
|
|
|
".New(...), expected 1, instead passed %v", len(args))
|
2017-11-10 03:30:20 +03:00
|
|
|
}
|
|
|
|
|
2018-07-17 02:50:47 +03:00
|
|
|
chainConn, ok := args[0].(*chain.BitcoindConn)
|
2017-11-10 03:30:20 +03:00
|
|
|
if !ok {
|
2018-07-17 02:50:47 +03:00
|
|
|
return nil, fmt.Errorf("first argument to bitcoindnotify.New " +
|
|
|
|
"is incorrect, expected a *chain.BitcoindConn")
|
2017-11-10 03:30:20 +03:00
|
|
|
}
|
|
|
|
|
2018-07-17 02:50:47 +03:00
|
|
|
return New(chainConn), nil
|
2017-11-10 03:30:20 +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))
|
|
|
|
}
|
|
|
|
}
|