-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
driver.go
76 lines (65 loc) · 2.27 KB
/
driver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package bitcoindnotify
import (
"errors"
"fmt"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcwallet/chain"
"github.com/lightningnetwork/lnd/blockcache"
"github.com/lightningnetwork/lnd/chainntnfs"
)
// createNewNotifier creates a new instance of the ChainNotifier interface
// implemented by BitcoindNotifier.
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
if len(args) != 5 {
return nil, fmt.Errorf("incorrect number of arguments to "+
".New(...), expected 5, instead passed %v", len(args))
}
chainConn, ok := args[0].(*chain.BitcoindConn)
if !ok {
return nil, errors.New("first argument to bitcoindnotify.New " +
"is incorrect, expected a *chain.BitcoindConn")
}
chainParams, ok := args[1].(*chaincfg.Params)
if !ok {
return nil, errors.New("second argument to bitcoindnotify.New " +
"is incorrect, expected a *chaincfg.Params")
}
spendHintCache, ok := args[2].(chainntnfs.SpendHintCache)
if !ok {
return nil, errors.New("third argument to bitcoindnotify.New " +
"is incorrect, expected a chainntnfs.SpendHintCache")
}
confirmHintCache, ok := args[3].(chainntnfs.ConfirmHintCache)
if !ok {
return nil, errors.New("fourth argument to bitcoindnotify.New " +
"is incorrect, expected a chainntnfs.ConfirmHintCache")
}
blockCache, ok := args[4].(*blockcache.BlockCache)
if !ok {
return nil, errors.New("fifth argument to bitcoindnotify.New " +
"is incorrect, expected a *blockcache.BlockCache")
}
return New(chainConn, chainParams, spendHintCache,
confirmHintCache, blockCache), nil
}
// init registers a driver for the BtcdNotifier concrete implementation of the
// chainntnfs.ChainNotifier interface.
func init() {
// Register the driver.
notifierZMQ := &chainntnfs.NotifierDriver{
NotifierType: notifierTypeZMQ,
New: createNewNotifier,
}
if err := chainntnfs.RegisterNotifier(notifierZMQ); err != nil {
panic(fmt.Sprintf("failed to register notifier driver '%s': %v",
notifierTypeZMQ, err))
}
notifierRPC := &chainntnfs.NotifierDriver{
NotifierType: notifierTypeRPCPolling,
New: createNewNotifier,
}
if err := chainntnfs.RegisterNotifier(notifierRPC); err != nil {
panic(fmt.Sprintf("failed to register notifier driver '%s': %v",
notifierTypeRPCPolling, err))
}
}