chainwatcher

package
v0.1.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package chainwatcher provides methods/interfaces for chain agnostic event tracking

Index

Constants

View Source
const HeightCounterMetricName = "height_counter"

HeightCounterMetricName is the name of the height counter metric.

Variables

View Source
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.

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) 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 {
	// 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

type ConditionCheck func(blockHeight uint64) bool

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 {
	ListenOnContract(ctx context.Context, contractAddress string, eventLog chan interface{}) error
}

ContractWatcher is a contract watcher.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL