blocktracker

package
v0.0.0-...-e4f0010 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockEvent

type BlockEvent struct {
	Type    EventType
	Added   []*web3.Block
	Removed []*web3.Block
}

BlockEvent is an event emitted when a new block is included

type BlockProvider

type BlockProvider interface {
	GetBlockByHash(hash web3.Hash, full bool) (*web3.Block, error)
	GetBlockByNumber(i web3.BlockNumber, full bool) (*web3.Block, error)
}

BlockProvider are the eth1x methods required by the block tracker

type BlockTracker

type BlockTracker struct {
	// contains filtered or unexported fields
}

BlockTracker is an interface to track new blocks on the chain

func NewBlockTracker

func NewBlockTracker(provider BlockProvider, opts ...ConfigOption) *BlockTracker

func (*BlockTracker) AcquireLock

func (b *BlockTracker) AcquireLock() Lock

func (*BlockTracker) AddBlockLocked

func (t *BlockTracker) AddBlockLocked(block *web3.Block) error

func (*BlockTracker) BlocksBlocked

func (b *BlockTracker) BlocksBlocked() []*web3.Block

func (*BlockTracker) Close

func (b *BlockTracker) Close() error

func (*BlockTracker) HandleBlockEvent

func (t *BlockTracker) HandleBlockEvent(block *web3.Block) (*BlockEvent, error)

func (*BlockTracker) HandleReconcile

func (t *BlockTracker) HandleReconcile(block *web3.Block) error

func (*BlockTracker) Init

func (t *BlockTracker) Init() (err error)

func (*BlockTracker) LastBlocked

func (b *BlockTracker) LastBlocked() *web3.Block

func (*BlockTracker) Len

func (b *BlockTracker) Len() int

func (*BlockTracker) MaxBlockBacklog

func (b *BlockTracker) MaxBlockBacklog() uint64

func (*BlockTracker) Start

func (b *BlockTracker) Start() error

func (*BlockTracker) Subscribe

func (b *BlockTracker) Subscribe() chan *BlockEvent

type BlockTrackerInterface

type BlockTrackerInterface interface {
	Track(context.Context, func(block *web3.Block) error) error
}

type Config

type Config struct {
	Tracker         BlockTrackerInterface
	MaxBlockBacklog uint64
}

func DefaultConfig

func DefaultConfig() *Config

type ConfigOption

type ConfigOption func(*Config)

func WithBlockMaxBacklog

func WithBlockMaxBacklog(b uint64) ConfigOption

type Event

type Event struct {
	Type    EventType
	Added   []*web3.Log
	Removed []*web3.Log
}

Event is an event emitted when a new log is included

type EventType

type EventType int

EventType is the type of the event

const (
	// EventAdd happens when a new event is included in the chain
	EventAdd EventType = iota
	// EventDel may happen when there is a reorg and a past event is deleted
	EventDel
)

type JSONBlockTracker

type JSONBlockTracker struct {
	PollInterval time.Duration
	// contains filtered or unexported fields
}

JSONBlockTracker implements the BlockTracker interface using the http jsonrpc endpoint

func NewJSONBlockTracker

func NewJSONBlockTracker(logger *log.Logger, provider BlockProvider) *JSONBlockTracker

NewJSONBlockTracker creates a new json block tracker

func (*JSONBlockTracker) Track

func (k *JSONBlockTracker) Track(ctx context.Context, handle func(block *web3.Block) error) error

Track implements the BlockTracker interface

type Lock

type Lock struct {
	Locked bool
	// contains filtered or unexported fields
}

func (*Lock) Lock

func (l *Lock) Lock()

func (*Lock) Unlock

func (l *Lock) Unlock()

type SubscriptionBlockTracker

type SubscriptionBlockTracker struct {
	// contains filtered or unexported fields
}

SubscriptionBlockTracker is an interface to track new blocks using the newHeads subscription endpoint

func NewSubscriptionBlockTracker

func NewSubscriptionBlockTracker(logger *log.Logger, client *jsonrpc.Client) (*SubscriptionBlockTracker, error)

NewSubscriptionBlockTracker creates a new block tracker using the subscription endpoint

func (*SubscriptionBlockTracker) Track

func (s *SubscriptionBlockTracker) Track(ctx context.Context, handle func(block *web3.Block) error) error

Track implements the BlockTracker interface

Jump to

Keyboard shortcuts

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