Documentation ¶
Index ¶
- type BackoffSleeper
- type HeadTrackable
- type HeadTracker
- func (ht *HeadTracker) Connected() bool
- func (ht *HeadTracker) ExportedDone() chan struct{}
- func (ht *HeadTracker) GetChainWithBackfill(ctx context.Context, head *models.Head, depth int64) (*models.Head, error)
- func (ht *HeadTracker) HighestSeenHead() *models.Head
- func (ht *HeadTracker) Save(h *models.Head) error
- func (ht *HeadTracker) Start() error
- func (ht *HeadTracker) Stop() error
- type ManagedSubscription
- type Sleeper
- type Unsubscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackoffSleeper ¶
BackoffSleeper is a sleeper that backs off on subsequent attempts.
func NewBackoffSleeper ¶
func NewBackoffSleeper() *BackoffSleeper
NewBackoffSleeper returns a BackoffSleeper that is configured to sleep for 0 seconds initially, then backs off from 1 second minimum to 10 seconds maximum.
func (*BackoffSleeper) After ¶
func (bs *BackoffSleeper) After() time.Duration
After returns the duration for the next stop, and increments the backoff.
func (*BackoffSleeper) Duration ¶
func (bs *BackoffSleeper) Duration() time.Duration
Duration returns the current duration value.
func (*BackoffSleeper) Reset ¶
func (bs *BackoffSleeper) Reset()
Reset resets the backoff intervals.
func (*BackoffSleeper) Sleep ¶
func (bs *BackoffSleeper) Sleep()
Sleep waits for the given duration, incrementing the back off.
type HeadTrackable ¶
type HeadTrackable interface { Connect(head *models.Head) error Disconnect() OnNewLongestChain(ctx context.Context, head *models.Head) }
HeadTrackable represents any object that wishes to respond to ethereum events, after being attached to HeadTracker.
type HeadTracker ¶
type HeadTracker struct {
// contains filtered or unexported fields
}
HeadTracker holds and stores the latest block number seen in a thread safe manner. Reconstitutes the last block number from the data store on reboot.
func NewHeadTracker ¶
func NewHeadTracker( ethClient client.Client, store store.Store, config *types.Config, callbacks []HeadTrackable, sleepers ...Sleeper) *HeadTracker
NewHeadTracker instantiates a new HeadTracker using the db to persist new block numbers. Can be passed in an optional sleeper object that will dictate how often it tries to reconnect.
func (*HeadTracker) Connected ¶
func (ht *HeadTracker) Connected() bool
Connected returns whether or not this HeadTracker is connected.
func (*HeadTracker) ExportedDone ¶
func (ht *HeadTracker) ExportedDone() chan struct{}
ExportedDone exports the done channel for testing
func (*HeadTracker) GetChainWithBackfill ¶
func (ht *HeadTracker) GetChainWithBackfill(ctx context.Context, head *models.Head, depth int64) (*models.Head, error)
GetChainWithBackfill returns a chain of the given length, backfilling any heads that may be missing from the database
func (*HeadTracker) HighestSeenHead ¶
func (ht *HeadTracker) HighestSeenHead() *models.Head
HighestSeenHead returns the block header with the highest number that has been seen, or nil
func (*HeadTracker) Save ¶
func (ht *HeadTracker) Save(h *models.Head) error
Save updates the latest block number, if indeed the latest, and persists this number in case of reboot. Thread safe.
func (*HeadTracker) Start ¶
func (ht *HeadTracker) Start() error
Start retrieves the last persisted block number from the HeadTracker, subscribes to new heads, and if successful fires Connect on the HeadTrackable argument.
func (*HeadTracker) Stop ¶
func (ht *HeadTracker) Stop() error
Stop unsubscribes all connections and fires Disconnect.
type ManagedSubscription ¶
type ManagedSubscription struct {
// contains filtered or unexported fields
}
ManagedSubscription encapsulates the connecting, backfilling, and clean up of an ethereum node subscription.
func NewManagedSubscription ¶
func NewManagedSubscription( logSubscriber client.Client, filter ethereum.FilterQuery, callback func(models.Log), ) (*ManagedSubscription, error)
NewManagedSubscription subscribes to the ethereum node with the passed filter and delegates incoming logs to callback.
func (ManagedSubscription) Unsubscribe ¶
func (sub ManagedSubscription) Unsubscribe()
Unsubscribe closes channels and cleans up resources.
type Sleeper ¶
Sleeper interface is used for tasks that need to be done on some interval, excluding Cron, like reconnecting.
type Unsubscriber ¶
type Unsubscriber interface {
Unsubscribe()
}
Unsubscriber is the interface for all subscriptions, allowing one to unsubscribe.