chainntnfs/neutrinonotify: clean up neutrinonotify.New

This commit is contained in:
Wilmer Paulino 2018-12-06 21:14:07 -08:00
parent 686e734e22
commit 969acf6145
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
3 changed files with 11 additions and 18 deletions

@ -11,9 +11,9 @@ import (
// createNewNotifier creates a new instance of the ChainNotifier interface
// implemented by NeutrinoNotifier.
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
if len(args) != 2 {
if len(args) != 3 {
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)
@ -34,7 +34,7 @@ func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
"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

@ -93,15 +93,16 @@ var _ chainntnfs.ChainNotifier = (*NeutrinoNotifier)(nil)
// NOTE: The passed neutrino node should already be running and active before
// being passed into this function.
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{}),
notificationRegistry: make(chan interface{}),
blockEpochClients: make(map[uint64]*blockEpochRegistration),
p2pNode: node,
p2pNode: node,
chainConn: &NeutrinoChainConn{node},
rescanErr: make(chan error),
@ -112,8 +113,6 @@ func New(node *neutrino.ChainService, spendHintCache chainntnfs.SpendHintCache,
quit: make(chan struct{}),
}
return notifier, nil
}
// Start contacts the running neutrino light client and kicks off an initial
@ -132,8 +131,11 @@ func (n *NeutrinoNotifier) Start() error {
if err != nil {
return err
}
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
// 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),
}
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
// the goroutines we need to operate this ChainNotifier instance.
n.chainView = n.p2pNode.NewRescan(rescanOptions...)

@ -53,8 +53,6 @@ func (n *NeutrinoNotifier) UnsafeStart(bestHeight int32,
n.confirmHintCache, n.spendHintCache,
)
n.chainConn = &NeutrinoChainConn{n.p2pNode}
// Finally, we'll create our rescan struct, start it, and launch all
// the goroutines we need to operate this ChainNotifier instance.
n.chainView = n.p2pNode.NewRescan(rescanOptions...)