blocksub

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package blocksub implements an Ethereum block subscriber that works with polling and/or websockets.

Index

Constants

This section is empty.

Variables

View Source
var ErrStopped = errors.New("already stopped")

Functions

This section is empty.

Types

type BlockSub

type BlockSub struct {
	PollTimeout time.Duration // 10 seconds by default (8,640 requests per day)
	SubTimeout  time.Duration // 60 seconds by default, after this timeout the subscriber will reconnect
	DebugOutput bool

	CurrentHeader      *ethtypes.Header
	CurrentBlockNumber uint64
	CurrentBlockHash   string
	// contains filtered or unexported fields
}

func NewBlockSub

func NewBlockSub(ctx context.Context, ethNodeHTTPURI string, ethNodeWebsocketURI string) *BlockSub

func (*BlockSub) IsRunning

func (s *BlockSub) IsRunning() bool

func (*BlockSub) Start

func (s *BlockSub) Start() (err error)

Start starts polling and websocket threads.

func (*BlockSub) Stop

func (s *BlockSub) Stop()

Stop closes all subscriptions and stops the polling and websocket threads.

func (*BlockSub) Subscribe

func (s *BlockSub) Subscribe(ctx context.Context) Subscription

Subscribe is used to create a new subscription.

type BlockSubscriber added in v0.4.1

type BlockSubscriber interface {
	IsRunning() bool
	Subscribe(ctx context.Context) Subscription
	Start() (err error)
	Stop()
}

type Subscription

type Subscription struct {
	C chan *ethtypes.Header // Channel to receive the headers on.
	// contains filtered or unexported fields
}

Subscription will push new headers to a subscriber until the context is done or Unsubscribe() is called, at which point the subscription is stopped and the header channel closed.

func NewSubscription

func NewSubscription(ctx context.Context) Subscription

func (*Subscription) Done

func (sub *Subscription) Done() <-chan struct{}

func (*Subscription) Unsubscribe

func (sub *Subscription) Unsubscribe()

Unsubscribe unsubscribes the notification and closes the header channel. It can safely be called more than once.

Jump to

Keyboard shortcuts

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