broadcaster

package
v0.0.0-...-fa14253 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockNumberMod

func BlockNumberMod(n uint64) func(number uint64) bool

BlockNumberMod returns true if the block number % n is 0

func EachBlockNumber

func EachBlockNumber() func(number uint64) bool

EachBlockNumber returns true

Types

type BlockOptions

type BlockOptions struct {
	// Number returns true if the block with the given number should be handled
	Number func(number uint64) bool
}

BlockOptions contains options to filter blocks

type Broadcaster

type Broadcaster interface {
	// RegisterEventHandler registers the given handler for specific events based on the given filters.
	RegisterEventHandler(id string, chainID uint64, handler HandleEventFunc, opts EventOptions) (func(), error)

	// RegisterBlockHandler registers the given handler for blocks based on the given filters.
	RegisterBlockHandler(id string, chainID uint64, handler HandleBlockFunc, opts BlockOptions) (func(), error)

	// Start starts broadcasting on-chain data to subscribers
	Start(ctx context.Context) error

	// Stop stops broadcasting
	Stop() error

	// Healthcheck performs a healthcheck of a broadcaster
	Healthcheck(ctx context.Context) error
}

Broadcaster represents a behavior of events broadcaster.

func NewSingleChain

func NewSingleChain(
	logger logrus.FieldLogger,
	client Client,
	headStreamer HeadStreamer,
	opts Options,
) (Broadcaster, error)

NewSingleChain is the constructor of singleChainBroadcaster

type Client

type Client interface {
	ethereum.LogFilterer
	ethereum.ChainReader
}

Client represents the behavior of the on-chain data provider

type EventOptions

type EventOptions struct {
	// Contracts contains contract addresses to listen events from.
	Contracts []common.Address

	// Event types to receive, with value filter for each field in the event
	// No filter or an empty filter for a given field position mean: all values allowed
	// the key should be a result of AbigenLog.Topic() call
	// topic => topicValueFilters
	LogsWithTopics map[common.Hash][][]common.Hash
}

EventOptions contains options to filter events

type HandleBlockFunc

type HandleBlockFunc func(ctx context.Context, header types.Header)

HandleBlockFunc is the signature of a function to handle heads

type HandleEventFunc

type HandleEventFunc func(ctx context.Context, event types.Log)

HandleEventFunc is the signature of a function to handle events

type HeadStreamer

type HeadStreamer interface {
	Start(ctx context.Context)
	Stop()
	Next() *types.Header
}

func NewLongPollingHeadStreamer

func NewLongPollingHeadStreamer(
	logger logrus.FieldLogger,
	client Client,
	blockTime time.Duration,
	chainID uint64,
) HeadStreamer

func NewWSHeadStreamer

func NewWSHeadStreamer(
	logger logrus.FieldLogger,
	client Client,
	chainID uint64,
) HeadStreamer

type Options

type Options struct {
	ChainID   uint64
	BlockTime time.Duration
}

Options contains options to create a broadcaster

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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