evmwatcher

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EVMWatcher

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

EVMWatcher watches multiple contracts of one chain over a single connection, so that the whole chain shares one consistent block progress.

func NewEVMWatcher

func NewEVMWatcher(chainName, wssURL string, watcherData []WatcherData, storage StorageInterface, event EventInterface, options ...Option) *EVMWatcher

func (*EVMWatcher) AddWatcher

func (e *EVMWatcher) AddWatcher(watcherData WatcherData) error

func (*EVMWatcher) GetWatcherData

func (e *EVMWatcher) GetWatcherData() []WatcherData

func (*EVMWatcher) RemoveWatcher

func (e *EVMWatcher) RemoveWatcher(watcherData WatcherData) error

func (*EVMWatcher) Start

func (e *EVMWatcher) Start() error

func (*EVMWatcher) Stop

func (e *EVMWatcher) Stop()

type Event

type Event struct {
	ContractAddress common.Address
	EventName       string
	BlockNumber     uint64
	BlockHash       common.Hash
	TxHash          common.Hash
	TxIndex         uint
	LogIndex        uint
	Args            map[string]any
	// Removed is true when the log has been reverted by a chain reorg.
	Removed bool
	Raw     types.Log
}

Event is the decoded contract event delivered through EventInterface.

type EventInterface

type EventInterface interface {
	// OnEvent is called with the chain the event belongs to, so that one
	// implementation can serve several chains. Implementations must be
	// idempotent: a crash after OnEvent succeeds but before the committed
	// watermark is stored intentionally causes the event to be replayed.
	OnEvent(chainName string, event *Event) error
}

监听到事件之后向外通知的接口

type Logger added in v0.0.3

type Logger interface {
	Debugf(format string, args ...any)
	Infof(format string, args ...any)
	Warnf(format string, args ...any)
	Errorf(format string, args ...any)
}

Logger is the minimal logging interface used inside evmwatcher. Callers can inject their own implementation via WithLogger.

type Option

type Option func(*EVMWatcher)

func WithConfirmations added in v0.0.2

func WithConfirmations(n uint64) Option

WithConfirmations delays delivery and watermark until a block is N blocks behind the chain head. 0 (default) keeps the current immediate-delivery behavior.

func WithDebug added in v0.0.3

func WithDebug(enabled bool) Option

WithDebug enables Debug-level logs such as raw subscription logs.

func WithGapHealInterval added in v0.0.10

func WithGapHealInterval(d time.Duration) Option

WithGapHealInterval sets how often zero-confirmation mode scans for logs the live subscription may have missed. It is independent from confirmation polling.

func WithLogger added in v0.0.3

func WithLogger(logger Logger) Option

WithLogger injects a custom logger. nil is ignored.

func WithMaxBlockRange

func WithMaxBlockRange(blocks uint64) Option

WithMaxBlockRange sets the block span of one eth_getLogs call, it is shrunk automatically when the provider rejects the range.

func WithMaxCatchUpBlocks added in v0.0.6

func WithMaxCatchUpBlocks(blocks uint64) Option

WithMaxCatchUpBlocks limits how many blocks a single backfill run may scan. 0 means unlimited.

func WithPollInterval added in v0.0.2

func WithPollInterval(d time.Duration) Option

WithPollInterval sets the poll interval used when confirmations > 0.

func WithRequestInterval

func WithRequestInterval(interval time.Duration) Option

WithRequestInterval sets the minimum gap between two RPC calls.

func WithSkipGapThreshold added in v0.0.6

func WithSkipGapThreshold(blocks uint64) Option

WithSkipGapThreshold skips historical catch-up when head-stored exceeds this value and jumps the cursor to the current (safe) head. 0 disables skipping.

type StorageInterface

type StorageInterface interface {
	// GetWatchedBlockNumber returns the last watched block number of the given
	// chain, -1 means there is no progress recorded yet.
	GetWatchedBlockNumber(chainName string) (int64, error)
	SetWatchedBlockNumber(chainName string, blockNumber uint64) error
}

type WatcherData

type WatcherData struct {
	ContractAddress string
	ContractABI     string
	// EventNames is the watched event name list, empty means every event in the ABI.
	EventNames []string
}

WatcherData describes one contract and the events watched on it.

Jump to

Keyboard shortcuts

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