Documentation
¶
Index ¶
- type EVMWatcher
- type Event
- type EventInterface
- type Logger
- type Option
- func WithConfirmations(n uint64) Option
- func WithDebug(enabled bool) Option
- func WithGapHealInterval(d time.Duration) Option
- func WithLogger(logger Logger) Option
- func WithMaxBlockRange(blocks uint64) Option
- func WithMaxCatchUpBlocks(blocks uint64) Option
- func WithPollInterval(d time.Duration) Option
- func WithRequestInterval(interval time.Duration) Option
- func WithSkipGapThreshold(blocks uint64) Option
- type StorageInterface
- type WatcherData
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
WithConfirmations delays delivery and watermark until a block is N blocks behind the chain head. 0 (default) keeps the current immediate-delivery behavior.
func WithGapHealInterval ¶ added in v0.0.10
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
WithLogger injects a custom logger. nil is ignored.
func WithMaxBlockRange ¶
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
WithMaxCatchUpBlocks limits how many blocks a single backfill run may scan. 0 means unlimited.
func WithPollInterval ¶ added in v0.0.2
WithPollInterval sets the poll interval used when confirmations > 0.
func WithRequestInterval ¶
WithRequestInterval sets the minimum gap between two RPC calls.
func WithSkipGapThreshold ¶ added in v0.0.6
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 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.