monitor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEventStr

func NewEventStr(chainId uint64, contractAddr common.Address, eventName string) string

NewEventStr generates the event using chainID, contract address and event name in the format "<chainID>-<contractAddr>-<eventName>". For backwards compatibility, If chainID is not set, this generates "<contractAddr>-<eventName">.

Types

type CallbackID

type CallbackID uint64

CallbackID is the unique callback ID for deadlines and events

type Config

type Config struct {
	ChainId   uint64
	Contract  Contract
	EventName string

	StartBlock, EndBlock *big.Int

	Reset         bool
	CheckInterval uint64
	BlockDelay    uint64 // if zero, use service.blockDelay by default
	ForwardDelay  uint64 // if zero, use BlockDelay
}

Config is used by external callers to pass in info, will be converted to Event for internal use Reason not use Event directly: Event is more like internal struct most fields are from previous MonitorService Monitor func args CheckInterval means to check log for event every CheckInterval x WatchService.polling if 0 or not set, defaultCheckInterval (1) will be used

type Contract

type Contract interface {
	GetAddr() common.Address
	GetABI() string
}

type Deadline

type Deadline struct {
	BlockNum *big.Int
	Callback func()
}

Deadline is the metadata of a deadline

type DeadlineQueue

type DeadlineQueue []*big.Int

DeadlineQueue is the priority queue for deadlines

func (DeadlineQueue) Len

func (dq DeadlineQueue) Len() int

func (DeadlineQueue) Less

func (dq DeadlineQueue) Less(i, j int) bool

func (*DeadlineQueue) Pop

func (dq *DeadlineQueue) Pop() (popped interface{})

func (*DeadlineQueue) Push

func (dq *DeadlineQueue) Push(x interface{})

func (DeadlineQueue) Swap

func (dq DeadlineQueue) Swap(i, j int)

func (*DeadlineQueue) Top

func (dq *DeadlineQueue) Top() (top interface{})

type Event

type Event struct {
	Addr          common.Address
	RawAbi        string
	Name          string
	WatchName     string
	StartBlock    *big.Int
	EndBlock      *big.Int
	BlockDelay    uint64
	ForwardDelay  uint64
	CheckInterval uint64
	Callback      func(CallbackID, types.Log) bool
	// contains filtered or unexported fields
}

Event is the metadata for an event

type Service

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

Service struct stores service parameters and registered deadlines and events

func NewService

func NewService(
	watch *watcher.WatchService, blockDelay uint64, enabled bool) *Service

NewService starts a new monitor service. If "enabled" is false, event monitoring will be disabled.

func (*Service) Close

func (s *Service) Close()

Close only set events map to empty map so all monitorEvent will exit due to isEventRemoved is true

func (*Service) GetCurrentBlockNumber

func (s *Service) GetCurrentBlockNumber() *big.Int

func (*Service) Init

func (s *Service) Init()

Init creates the event map

func (*Service) Monitor

func (s *Service) Monitor(cfg *Config, callback func(CallbackID, types.Log) bool) (CallbackID, error)

func (*Service) MonitorEvent

func (s *Service) MonitorEvent(e Event, reset bool) (CallbackID, error)

func (*Service) RegisterDeadline

func (s *Service) RegisterDeadline(d Deadline) CallbackID

RegisterDeadline registers the deadline and returns the ID

func (*Service) RemoveDeadline

func (s *Service) RemoveDeadline(id CallbackID)

RemoveDeadline removes a deadline from the monitor

func (*Service) RemoveEvent

func (s *Service) RemoveEvent(id CallbackID)

RemoveEvent removes an event from the monitor

Jump to

Keyboard shortcuts

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