common

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyBlockHash = errors.New("block hash is empty")

Functions

func IndexLogs

func IndexLogs(
	ctx context.Context,
	eventChannel <-chan types.Log,
	contract IContract,
)

- IndexLogs will run until the eventChannel is closed, passing each event to the logStorer. - If an event fails to be stored, and the error is retryable, it will sleep for 100ms and try again. - The only non-retriable errors should be things like malformed events or failed validations.

Types

type Block

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

type BlockTracker

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

* BlockTracker keeps a database record of the latest block that has been indexed for a contract address and allows the user to increase the value. *

func NewBlockTracker

func NewBlockTracker(
	ctx context.Context,
	client blockchain.ChainClient,
	address common.Address,
	queries *queries.Queries,
	deploymentBlock uint64,
) (*BlockTracker, error)

Return a new BlockTracker initialized to the latest block from the DB

func (*BlockTracker) GetLatestBlock

func (bt *BlockTracker) GetLatestBlock() (uint64, []byte)

func (*BlockTracker) UpdateLatestBlock

func (bt *BlockTracker) UpdateLatestBlock(
	ctx context.Context,
	block uint64,
	hashBytes []byte,
) error

type IBlockTracker

type IBlockTracker interface {
	GetLatestBlock() (uint64, []byte)
	UpdateLatestBlock(ctx context.Context, block uint64, hash []byte) error
}

Tracks the latest block number and hash for a contract.

type IContract

type IContract interface {
	IBlockTracker
	IReorgHandler
	ILogStorer
	Address() common.Address
	Topics() []common.Hash
	Logger() *zap.Logger
}

An IContract is a contract that can be indexed.

type ILogStorer

type ILogStorer interface {
	StoreLog(ctx context.Context, event types.Log) re.RetryableError
}

Takes a log event and stores it, returning either an error that may be retriable, non-retriable, or nil.

type ILogStreamer

type ILogStreamer interface {
	GetEventChannel(id string) <-chan types.Log
	Start() error
	Stop()
}

An ILogStreamer streams logs from a source through a channel.

type IReorgHandler

type IReorgHandler interface {
	HandleLog(ctx context.Context, event types.Log) re.RetryableError
}

Jump to

Keyboard shortcuts

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