Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockRange ¶ added in v0.4.0
BlockRange is an inclusive block range.
func ChunkBlockRange ¶ added in v0.4.0
func ChunkBlockRange(from, to, size uint64) []BlockRange
ChunkBlockRange splits the inclusive block range [from, to] into ranges containing at most size blocks.
type ChainReader ¶
type ChainReader interface {
FilterLogs(context.Context, ethereum.FilterQuery) ([]types.Log, error)
HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
}
ChainReader provides access to Ethereum logs and block headers.
type Filter ¶
type Filter struct {
// Addresses restrict logs to the given contract addresses.
// See [ethereum.FilterQuery.Addresses].
Addresses []common.Address
// Topics restrict logs by indexed event topics.
// See [ethereum.FilterQuery.Topics].
Topics [][]common.Hash
}
Filter specifies which logs the indexer fetches.
type Indexer ¶
type Indexer[S State] struct { // Client provides access to Ethereum logs and block headers. Client ChainReader // DataDir stores checkpoints and cached log batches. DataDir string // FromBlock is the first block to index. FromBlock uint64 // Filter specifies which logs the indexer fetches. Filter Filter // LogFunc receives indexer log events. LogFunc func(msg string, args ...any) // MaxBlockRange is the maximum block span per backfill request. MaxBlockRange uint64 // FinalityDepth is the block depth considered finalized. FinalityDepth uint64 // CheckpointInterval is the minimum number of blocks between staged checkpoints. CheckpointInterval uint64 // MaxConcurrency bounds concurrent header fetches. MaxConcurrency int // State receives matching logs and is persisted in checkpoints with // encoding/gob. It must be a pointer so checkpoints can restore it in place. State S // contains filtered or unexported fields }
Indexer indexes Ethereum logs into State from a finalized block onward, handling reorgs and gob-encoded checkpoints.
func (*Indexer[S]) CachedFilterLogs ¶ added in v0.4.0
func (i *Indexer[S]) CachedFilterLogs(ctx context.Context, f Filter, r BlockRange) ([]types.Log, error)
CachedFilterLogs returns logs matching filter in the inclusive block range, using the cache in DataDir when available.
func (*Indexer[S]) ClearCheckpoint ¶ added in v0.4.0
ClearCheckpoint removes finalized and staged checkpoints from DataDir while preserving cached log ranges.
func (*Indexer[S]) HasCheckpoint ¶ added in v0.4.0
HasCheckpoint reports whether a finalized checkpoint exists in DataDir.