Documentation ¶
Overview ¶
Package chainwatcher provides methods/interfaces for chain agnostic event tracking
Index ¶
- Constants
- Variables
- type BlockBroadcaster
- func (b *BlockBroadcaster) Emit(height uint64)
- func (b *BlockBroadcaster) GetMetrics(labels map[string]string) []prometheus.Collector
- func (b *BlockBroadcaster) Subscribe() <-chan uint64
- func (b *BlockBroadcaster) Unsubscribe(ch <-chan uint64)
- func (b *BlockBroadcaster) UpdateHeight(newHeight uint64)
- type BlockHeightWatcher
- type BlockSubscriberClient
- type ConditionCheck
- type ContractWatcher
Constants ¶
const HeightCounterMetricName = "height_counter"
HeightCounterMetricName is the name of the height counter metric.
Variables ¶
var PollInterval = time.Second * 5
PollInterval is how often to poll. This is exported for testing.
Functions ¶
This section is empty.
Types ¶
type BlockBroadcaster ¶
type BlockBroadcaster struct {
// contains filtered or unexported fields
}
BlockBroadcaster handles communications between block subcribers and clients. It Differs from BlockHeightWatcher in that it does not handle actually feteching heights from the rpc or reconnecting. We expose this for client/pool to allow multi-rpc block boradcasters. nolint: containedctx
func NewBlockBroadcaster ¶
func NewBlockBroadcaster(ctx context.Context, chainID uint64) *BlockBroadcaster
NewBlockBroadcaster creates a new block broadcaster.
func (*BlockBroadcaster) Emit ¶
func (b *BlockBroadcaster) Emit(height uint64)
Emit emits a new block height to all listeners.
func (*BlockBroadcaster) GetMetrics ¶
func (b *BlockBroadcaster) GetMetrics(labels map[string]string) []prometheus.Collector
GetMetrics gets metrics associated with block height watcher.
func (*BlockBroadcaster) Subscribe ¶
func (b *BlockBroadcaster) Subscribe() <-chan uint64
Subscribe creates a new block height subscriber.
func (*BlockBroadcaster) Unsubscribe ¶
func (b *BlockBroadcaster) Unsubscribe(ch <-chan uint64)
Unsubscribe removes a block height subscriber.
func (*BlockBroadcaster) UpdateHeight ¶
func (b *BlockBroadcaster) UpdateHeight(newHeight uint64)
UpdateHeight updates the block height and sends any heights in between last height and new height to the channel. as a reminder: BlockBroadcaster is a counter - heights go up, not down. UpdateHeight follows that interface.
type BlockHeightWatcher ¶
type BlockHeightWatcher interface { metrics.Instrumentable // Subscribe creates a new block height subscriber. Subscribe() <-chan uint64 // Unsubscribe removes a block height subscriber. Unsubscribe(ch <-chan uint64) }
BlockHeightWatcher creates a subscription to the block height for geth based chains. it uses the observer pattern to allow many subscribers.
func NewBlockHeightWatcher ¶
func NewBlockHeightWatcher(ctx context.Context, chainID uint64, reader BlockSubscriberClient) BlockHeightWatcher
NewBlockHeightWatcher creates a new block height subscriber. This creates a channel for getting the latest heights from a subscription and attempts to reconnect on disconnect.
type BlockSubscriberClient ¶
type BlockSubscriberClient interface { // LatestHeight gets the latest height block. An error is handled by the subscriber LatestHeight(ctx context.Context) (uint64, error) }
BlockSubscriberClient defines a method for getting a subscription to the chain-tip height on geth based rpc clients.
type ConditionCheck ¶
ConditionCheck is a function passed in by the caller that checks the block height against their condition and returns a bool indicating whether or not the context should be canceled.
type ContractWatcher ¶
type ContractWatcher interface { metrics.Instrumentable ListenOnContract(ctx context.Context, contractAddress string, eventLog chan interface{}) error }
ContractWatcher is a contract watcher.