chainntnfs/neutrinonotify: clean up neutrinonotify.New
This commit is contained in:
parent
686e734e22
commit
969acf6145
@ -11,9 +11,9 @@ import (
|
|||||||
// createNewNotifier creates a new instance of the ChainNotifier interface
|
// createNewNotifier creates a new instance of the ChainNotifier interface
|
||||||
// implemented by NeutrinoNotifier.
|
// implemented by NeutrinoNotifier.
|
||||||
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
|
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
|
||||||
if len(args) != 2 {
|
if len(args) != 3 {
|
||||||
return nil, fmt.Errorf("incorrect number of arguments to "+
|
return nil, fmt.Errorf("incorrect number of arguments to "+
|
||||||
".New(...), expected 2, instead passed %v", len(args))
|
".New(...), expected 3, instead passed %v", len(args))
|
||||||
}
|
}
|
||||||
|
|
||||||
config, ok := args[0].(*neutrino.ChainService)
|
config, ok := args[0].(*neutrino.ChainService)
|
||||||
@ -34,7 +34,7 @@ func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
|
|||||||
"is incorrect, expected a chainntfs.ConfirmHintCache")
|
"is incorrect, expected a chainntfs.ConfirmHintCache")
|
||||||
}
|
}
|
||||||
|
|
||||||
return New(config, spendHintCache, confirmHintCache)
|
return New(config, spendHintCache, confirmHintCache), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// init registers a driver for the NeutrinoNotify concrete implementation of
|
// init registers a driver for the NeutrinoNotify concrete implementation of
|
||||||
|
@ -93,15 +93,16 @@ var _ chainntnfs.ChainNotifier = (*NeutrinoNotifier)(nil)
|
|||||||
// NOTE: The passed neutrino node should already be running and active before
|
// NOTE: The passed neutrino node should already be running and active before
|
||||||
// being passed into this function.
|
// being passed into this function.
|
||||||
func New(node *neutrino.ChainService, spendHintCache chainntnfs.SpendHintCache,
|
func New(node *neutrino.ChainService, spendHintCache chainntnfs.SpendHintCache,
|
||||||
confirmHintCache chainntnfs.ConfirmHintCache) (*NeutrinoNotifier, error) {
|
confirmHintCache chainntnfs.ConfirmHintCache) *NeutrinoNotifier {
|
||||||
|
|
||||||
notifier := &NeutrinoNotifier{
|
return &NeutrinoNotifier{
|
||||||
notificationCancels: make(chan interface{}),
|
notificationCancels: make(chan interface{}),
|
||||||
notificationRegistry: make(chan interface{}),
|
notificationRegistry: make(chan interface{}),
|
||||||
|
|
||||||
blockEpochClients: make(map[uint64]*blockEpochRegistration),
|
blockEpochClients: make(map[uint64]*blockEpochRegistration),
|
||||||
|
|
||||||
p2pNode: node,
|
p2pNode: node,
|
||||||
|
chainConn: &NeutrinoChainConn{node},
|
||||||
|
|
||||||
rescanErr: make(chan error),
|
rescanErr: make(chan error),
|
||||||
|
|
||||||
@ -112,8 +113,6 @@ func New(node *neutrino.ChainService, spendHintCache chainntnfs.SpendHintCache,
|
|||||||
|
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifier, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start contacts the running neutrino light client and kicks off an initial
|
// Start contacts the running neutrino light client and kicks off an initial
|
||||||
@ -132,8 +131,11 @@ func (n *NeutrinoNotifier) Start() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
n.bestHeight = uint32(startingPoint.Height)
|
n.bestHeight = uint32(startingPoint.Height)
|
||||||
|
n.txNotifier = chainntnfs.NewTxNotifier(
|
||||||
|
n.bestHeight, chainntnfs.ReorgSafetyLimit, n.confirmHintCache,
|
||||||
|
n.spendHintCache,
|
||||||
|
)
|
||||||
|
|
||||||
// Next, we'll create our set of rescan options. Currently it's
|
// Next, we'll create our set of rescan options. Currently it's
|
||||||
// required that a user MUST set an addr/outpoint/txid when creating a
|
// required that a user MUST set an addr/outpoint/txid when creating a
|
||||||
@ -152,13 +154,6 @@ func (n *NeutrinoNotifier) Start() error {
|
|||||||
neutrino.WatchInputs(zeroInput),
|
neutrino.WatchInputs(zeroInput),
|
||||||
}
|
}
|
||||||
|
|
||||||
n.txNotifier = chainntnfs.NewTxNotifier(
|
|
||||||
n.bestHeight, chainntnfs.ReorgSafetyLimit, n.confirmHintCache,
|
|
||||||
n.spendHintCache,
|
|
||||||
)
|
|
||||||
|
|
||||||
n.chainConn = &NeutrinoChainConn{n.p2pNode}
|
|
||||||
|
|
||||||
// Finally, we'll create our rescan struct, start it, and launch all
|
// Finally, we'll create our rescan struct, start it, and launch all
|
||||||
// the goroutines we need to operate this ChainNotifier instance.
|
// the goroutines we need to operate this ChainNotifier instance.
|
||||||
n.chainView = n.p2pNode.NewRescan(rescanOptions...)
|
n.chainView = n.p2pNode.NewRescan(rescanOptions...)
|
||||||
|
@ -53,8 +53,6 @@ func (n *NeutrinoNotifier) UnsafeStart(bestHeight int32,
|
|||||||
n.confirmHintCache, n.spendHintCache,
|
n.confirmHintCache, n.spendHintCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
n.chainConn = &NeutrinoChainConn{n.p2pNode}
|
|
||||||
|
|
||||||
// Finally, we'll create our rescan struct, start it, and launch all
|
// Finally, we'll create our rescan struct, start it, and launch all
|
||||||
// the goroutines we need to operate this ChainNotifier instance.
|
// the goroutines we need to operate this ChainNotifier instance.
|
||||||
n.chainView = n.p2pNode.NewRescan(rescanOptions...)
|
n.chainView = n.p2pNode.NewRescan(rescanOptions...)
|
||||||
|
Loading…
Reference in New Issue
Block a user