evmwatcher

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 13 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.
	OnEvent(chainName string, event *Event) error
}

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

type Option

type Option func(*EVMWatcher)

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 WithRequestInterval

func WithRequestInterval(interval time.Duration) Option

WithRequestInterval sets the minimum gap between two RPC calls.

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