chainntnfs: declare common ErrChainNotifierShuttingDown for all backends

This commit is contained in:
Wilmer Paulino 2018-12-10 18:25:41 -08:00
parent 50650d054e
commit be2c321c8c
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
4 changed files with 20 additions and 33 deletions

@ -26,11 +26,6 @@ const (
)
var (
// ErrChainNotifierShuttingDown is used when we are trying to
// measure a spend notification when notifier is already stopped.
ErrChainNotifierShuttingDown = errors.New("chainntnfs: system interrupt " +
"while attempting to register for spend notification.")
// ErrTransactionNotFound is an error returned when we attempt to find a
// transaction by manually scanning the chain within a specific range
// but it is not found.
@ -498,7 +493,6 @@ func (b *BitcoindNotifier) confDetailsFromTxIndex(txid *chainhash.Hash,
fmt.Errorf("unable to get block hash %v for "+
"historical dispatch: %v", rawTxRes.BlockHash, err)
}
block, err := b.chainConn.GetBlockVerbose(blockHash)
if err != nil {
return nil, chainntnfs.TxNotFoundIndex,
@ -559,7 +553,7 @@ func (b *BitcoindNotifier) confDetailsManually(confRequest chainntnfs.ConfReques
select {
case <-b.quit:
return nil, chainntnfs.TxNotFoundManually,
ErrChainNotifierShuttingDown
chainntnfs.ErrChainNotifierShuttingDown
default:
}
@ -728,7 +722,7 @@ func (b *BitcoindNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
select {
case b.notificationRegistry <- historicalDispatch:
case <-b.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
}
return ntfn.Event, nil
@ -805,7 +799,7 @@ func (b *BitcoindNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
select {
case b.notificationRegistry <- historicalDispatch:
case <-b.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
}
return ntfn.Event, nil
@ -829,7 +823,7 @@ func (b *BitcoindNotifier) dispatchSpendDetailsManually(
// processing the next height.
select {
case <-b.quit:
return ErrChainNotifierShuttingDown
return chainntnfs.ErrChainNotifierShuttingDown
default:
}
@ -923,7 +917,7 @@ func (b *BitcoindNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
case b.notificationRegistry <- dispatch:
return ntfn.Event, nil
case <-b.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
}
}

@ -26,13 +26,6 @@ const (
notifierType = "btcd"
)
var (
// ErrChainNotifierShuttingDown is used when we are trying to
// measure a spend notification when notifier is already stopped.
ErrChainNotifierShuttingDown = errors.New("chainntnfs: system interrupt " +
"while attempting to register for spend notification.")
)
// chainUpdate encapsulates an update to the current main chain. This struct is
// used as an element within an unbounded queue in order to avoid blocking the
// main rpc dispatch rule.
@ -610,7 +603,7 @@ func (b *BtcdNotifier) confDetailsManually(confRequest chainntnfs.ConfRequest,
select {
case <-b.quit:
return nil, chainntnfs.TxNotFoundManually,
ErrChainNotifierShuttingDown
chainntnfs.ErrChainNotifierShuttingDown
default:
}
@ -964,7 +957,7 @@ func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
case b.notificationRegistry <- dispatch:
return ntfn.Event, nil
case <-b.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
}
}

@ -1,6 +1,7 @@
package chainntnfs
import (
"errors"
"fmt"
"sync"
@ -9,6 +10,12 @@ import (
"github.com/btcsuite/btcd/wire"
)
var (
// ErrChainNotifierShuttingDown is used when we are trying to
// measure a spend notification when notifier is already stopped.
ErrChainNotifierShuttingDown = errors.New("chain notifier shutting down")
)
// TxConfStatus denotes the status of a transaction's lookup.
type TxConfStatus uint8

@ -27,13 +27,6 @@ const (
notifierType = "neutrino"
)
var (
// ErrChainNotifierShuttingDown is used when we are trying to
// measure a spend notification when notifier is already stopped.
ErrChainNotifierShuttingDown = errors.New("chainntnfs: system interrupt " +
"while attempting to register for spend notification.")
)
// NeutrinoNotifier is a version of ChainNotifier that's backed by the neutrino
// Bitcoin light client. Unlike other implementations, this implementation
// speaks directly to the p2p network. As a result, this implementation of the
@ -503,7 +496,7 @@ func (n *NeutrinoNotifier) historicalConfDetails(confRequest chainntnfs.ConfRequ
// processing the next height.
select {
case <-n.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
default:
}
@ -710,13 +703,13 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
errChan: errChan,
}:
case <-n.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
}
select {
case err = <-errChan:
case <-n.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
}
if err != nil {
return nil, fmt.Errorf("unable to update filter: %v", err)
@ -856,13 +849,13 @@ func (n *NeutrinoNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
errChan: errChan,
}:
case <-n.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
}
select {
case err = <-errChan:
case <-n.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
}
if err != nil {
return nil, fmt.Errorf("unable to update filter: %v", err)
@ -879,7 +872,7 @@ func (n *NeutrinoNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
select {
case n.notificationRegistry <- dispatch:
case <-n.quit:
return nil, ErrChainNotifierShuttingDown
return nil, chainntnfs.ErrChainNotifierShuttingDown
}
return ntfn.Event, nil