scanner

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ChainID string
	// Startup strategy
	StartBlock   uint64
	ForceStart   bool
	Rewind       uint64
	CursorRewind uint64 // Safety rewind from saved cursor

	BatchSize uint64
	Interval  time.Duration
	ReorgSafe uint64
	UseBloom  bool
}

Config holds configuration parameters for the Scanner.

type Filter

type Filter struct {
	// Contracts is the list of contract addresses to listen to (Log.Address).
	// If empty, listens to all contracts.
	Contracts []common.Address

	// Topics is the list of event topics to listen to.
	// Maps to eth_getLogs topics parameter: [[A, B], [C], null, [D]]
	// Logical relation: (Topic0 in [A, B]) AND (Topic1 in [C])
	Topics [][]common.Hash
}

Filter defines the scanning rules for the scanner. It is used both for generating RPC request parameters and for local Bloom Filter checks.

func NewFilter

func NewFilter() *Filter

NewFilter creates a new filter

func (*Filter) AddContract

func (f *Filter) AddContract(addrs ...common.Address) *Filter

AddContract adds contract addresses to listen to

func (*Filter) IsHeavy

func (f *Filter) IsHeavy() bool

IsHeavy determines if the filter is too complex for efficient local Bloom Filter checks. Rule of thumb: Bloom filter tends to saturate if topics at any position > 20 or contracts > 20.

func (*Filter) MatchesBloom

func (f *Filter) MatchesBloom(bloom types.Bloom) bool

MatchesBloom uses the local Bloom Filter to quickly check if a block might contain matching logs. Returns false if it definitely doesn't contain matching logs (Safe to Skip). Returns true if it might contain matching logs (Need to Fetch).

func (*Filter) SetTopic

func (f *Filter) SetTopic(pos int, hashes ...common.Hash) *Filter

SetTopic sets the topics at a specific position pos: 0-3 (0 is typically the event signature hash)

func (*Filter) ToQuery

func (f *Filter) ToQuery(fromBlock, toBlock uint64) ethereum.FilterQuery

ToQuery converts the filter to go-ethereum standard query parameters

type Handler

type Handler func(ctx context.Context, logs []types.Log) error

Handler is a callback function type for processing scanned logs.

type Scanner

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

Scanner orchestrates the scanning of blocks and processing of logs.

func New

func New(client rpc.Client, store storage.Persistence, cfg Config, filter *Filter) *Scanner

New creates and initializes a new Scanner instance.

func (*Scanner) SetHandler

func (s *Scanner) SetHandler(h Handler)

SetHandler sets the callback function to be called when logs are received

func (*Scanner) Start

func (s *Scanner) Start(ctx context.Context) error

Start begins the scanning loop (blocks until context is cancelled)

Jump to

Keyboard shortcuts

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