monitor

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEventStr

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

NewEventStr generates the event using contract address and event name in format "<addr>-<name>"

Types

type CallbackID

type CallbackID uint64

CallbackID is the unique callback ID for deadlines and events

type Config

type Config struct {
	EventName            string
	Contract             Contract
	StartBlock, EndBlock *big.Int
	Reset                bool
	CheckInterval        uint64
	BlockDelay           uint64 // if zero, use service.blockDelay by default
}

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
	CheckInterval uint64
	Callback      func(CallbackID, types.Log)
	// 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)) (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