sensors

package module
v0.0.0-...-bda5ec2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2018 License: MIT Imports: 7 Imported by: 0

README

eth-sensors

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrVersion       = errors.New("order version error")
	ErrWatcherExists = errors.New("watcher exists")
)

Errors

View Source
var (
	StatusCreated  = Status("CREATED")
	StatusPending  = Status("PENDING")
	StatusRunning  = Status("RUNNING")
	StatusSucceed  = Status("SUCCEED")
	StatusFailed   = Status("FAILED")
	StatusCanceled = Status("CANCELED")
)

Status .

Functions

func RegisterCacher

func RegisterCacher(name string, cacherF OrderCacherF)

RegisterCacher .

func RegisterNotifier

func RegisterNotifier(name string, notifier NotifierF)

RegisterNotifier .

func RegisterSensor

func RegisterSensor(name string, sensors CoreF)

RegisterSensor .

func RegisterStorage

func RegisterStorage(name string, cacherF OrderStorageF)

RegisterStorage .

Types

type CoreF

type CoreF func(config config.Config, plugin *Plugin) (Sensor, error)

CoreF sensors factory

type Notifier

type Notifier interface {
	// notify order status changed
	Notify(receiver *Watcher, order *Order) error
}

Notifier the eth tx event notifier

type NotifierF

type NotifierF func(config config.Config) (Notifier, error)

NotifierF notifier factory

type NotifierFunc

type NotifierFunc func(receiver *Watcher, order *Order) error

NotifierFunc .

func (NotifierFunc) Notify

func (fn NotifierFunc) Notify(receiver *Watcher, order *Order) error

Notify implement Notifier

type Option

type Option func(plugin *Plugin)

Option .

func WithNotifier

func WithNotifier(notifier NotifierF) Option

WithNotifier .

type Order

type Order struct {
	ID           string    `xorm:"pk"`
	TX           string    `xorm:"unique"`
	PendingBlock int64     `xorm:""`
	CommitBlock  int64     `xorm:""`
	ConfirmBlock int64     `xorm:""`
	Status       Status    `xorm:"index"`
	CreateTime   time.Time `xorm:"created"`
	PendingTime  time.Time `xorm:""`
	CommitTime   time.Time `xorm:""`
	ConfirmTime  time.Time `xorm:""`
	From         string    `xorm:"index"`
	To           string    `xorm:"index"`
	Value        string    `xorm:"default('0x0')"`
	Code         string    `xorm:""`
	GasLimits    string    `xorm:""`
	GasPrice     string    `xorm:""`
}

Order the eth tx order

func (*Order) TableName

func (table *Order) TableName() string

TableName .

type OrderCacher

type OrderCacher interface {
	Cache([]*Order)                                                             // load unconfirmed  orders
	Mint(tx string, block int64, time time.Time) (*Order, bool)                 // mint cached order with tx string
	Confirm(block int64, time time.Time) (timeout []*Order, confirmed []*Order) // confirm orders
	Pending() (*Order, bool)                                                    // pending order number
	Pend(order *Order)
}

OrderCacher .

type OrderCacherF

type OrderCacherF func(config config.Config) (OrderCacher, error)

OrderCacherF OrderCacher factory

type OrderStorage

type OrderStorage interface {
	Save(order *Order) error
	Update(order *Order) error
	Unconfirmed() ([]*Order, error)
}

OrderStorage .

type OrderStorageF

type OrderStorageF func(config config.Config) (OrderStorage, error)

OrderStorageF OrderStorage factory

type Plugin

type Plugin struct {
	slf4go.Logger
	NotifierCreator NotifierF

	OrderStorageCreator OrderStorageF
	OrderCacherCreator  OrderCacherF
	// contains filtered or unexported fields
}

Plugin sensors plugin object

type Sensor

type Sensor interface {
	// create a new watcher with config
	New(watcher *Watcher) (id string, err error)
	// delete watcher by watcher key
	Delete(key string) (err error)
	// list the register watcher
	List(page orm.Page) ([]*Watcher, int64, error)
}

Sensor The eth tx detect service

func New

func New(config config.Config, options ...Option) (Sensor, error)

New create sensors

type Status

type Status string

Status .

type Watcher

type Watcher struct {
	ID      string `xorm:"pk"`                    // watcher id
	Name    string `xorm:"index"`                 // watcher name
	Key     string `xorm:"unique"`                // watcher unique key provider by notifier
	Address string `xorm:"unique(address_erc20)"` // watched address
	ERC20   bool   `xorm:"unique(address_erc20)"` // true if the target address is a erc20 contract address
}

Watcher the eth event watcher managed by sensors

func (*Watcher) TableName

func (table *Watcher) TableName() string

TableName .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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