tracker

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Noncer

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

Noncer is a struct that manages nonces for transactions.

func NewNoncer

func NewNoncer(sender common.Address, refreshInterval time.Duration) *Noncer

NewNoncer creates a new Noncer instance.

func (*Noncer) Acquire

func (n *Noncer) Acquire() (uint64, bool)

Acquire gets the next available nonce. Along with the nonce to use, it returns whether this nonce is replacing another tx in the mempool that has the same nonce (in this case, a replacement with bumped gas should be used).

func (*Noncer) RemoveAcquired

func (n *Noncer) RemoveAcquired(nonce uint64)

RemoveAcquired removes a nonce from the acquired list, when a transaction is unable to be sent.

func (*Noncer) RemoveInFlight

func (n *Noncer) RemoveInFlight(nonce uint64)

RemoveInFlight removes a transaction from the in-flight list by its nonce.

func (*Noncer) SetInFlight

func (n *Noncer) SetInFlight(nonce uint64)

SetInFlight adds a transaction to the in-flight list. The transaction is indexed by its nonce.

func (*Noncer) Start

func (n *Noncer) Start(ctx context.Context, ethClient eth.Client)

func (*Noncer) Stats

func (n *Noncer) Stats() (int, int)

Stats returns the number of acquired nonces and the number of in-flight transactions.

type Response

type Response struct {
	*coretypes.Transaction

	MsgIDs       []string    // Message IDs that were included in the transaction.
	InitialTimes []time.Time // Times each message was initially fired.
	Error        error       // Build or send error.
	// contains filtered or unexported fields
}

Response represents a transaction that is currently being tracked by the transactor.

func (*Response) Hash

func (r *Response) Hash() common.Hash

Hash overrides the method on Transaction to avoid dereferencing a nil pointer.

func (*Response) Nonce

func (r *Response) Nonce() uint64

Nonce overrides the method on Transaction to avoid dereferencing a nil pointer.

func (*Response) Status

func (r *Response) Status() Status

Status returns the current status of a transaction owned by the transactor.

func (*Response) To

func (r *Response) To() *common.Address

To overrides the method on Transaction to avoid dereferencing a nil pointer.

type Status

type Status uint8

Status represents the current status of a tx owned by the transactor. These are used only after the tx status has been confirmed by erroring, the chain, or the configured timeout.

const (
	StatusPending Status = iota
	StatusError
	StatusSuccess
	StatusReverted
	StatusStale
)

type Subscriber

type Subscriber interface {
	// OnError is called when a transaction request fails to build or send.
	OnError(ctx context.Context, resp *Response)
	// OnSuccess is called when a transaction has been successfully included in a block.
	OnSuccess(resp *Response, receipt *coretypes.Receipt)
	// OnRevert is called when a transaction has been reverted.
	OnRevert(resp *Response, receipt *coretypes.Receipt)
	// OnStale is called when a transaction becomes stale after the configured timeout.
	OnStale(ctx context.Context, resp *Response, isPending bool)
}

Subscriber is an interface that defines methods for handling responses from the transactor.

type Subscription

type Subscription struct {
	Subscriber
	// contains filtered or unexported fields
}

Once started, a Subscription manages and invokes a Subscriber.

func NewSubscription

func NewSubscription(s Subscriber, logger log.Logger) *Subscription

func (*Subscription) Start

func (sub *Subscription) Start(ctx context.Context, ch chan *Response)

type Tracker

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

Tracker is a component that keeps track of the transactions that are already sent to the chain.

func New

func New(
	noncer *Noncer, dispatcher *event.Dispatcher[*Response], sender common.Address,
	txWaitingTimeout time.Duration,
) *Tracker

New creates a new transaction tracker.

func (*Tracker) SetClient

func (t *Tracker) SetClient(chain eth.Client)

func (*Tracker) Track

func (t *Tracker) Track(ctx context.Context, resp *Response)

Track adds a transaction response to the in-flight list and waits for a status.

Jump to

Keyboard shortcuts

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