event

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrTXAlreadyHandled is returned if received TX has already been signed.
	ErrTXAlreadyHandled = errors.New("received main tx has already been handled")
)

Functions

func BytesFromOpcode

func BytesFromOpcode(op Op) ([]byte, error)

BytesFromOpcode tries to retrieve bytes from Op.

func IntFromOpcode

func IntFromOpcode(op Op) (int64, error)

IntFromOpcode tries to retrieve int from Op.

func ParseStackArray

func ParseStackArray(event *state.ContainedNotificationEvent) ([]stackitem.Item, error)

ParseStackArray parses stack array from raw notification event received from neo-go RPC node.

func StringFromOpcode

func StringFromOpcode(op Op) (string, error)

StringFromOpcode tries to retrieve string from Op.

func UnexpectedArgNumErr

func UnexpectedArgNumErr(method string) error

UnexpectedArgNumErr returns error when notary parsers get unexpected amount of argument in contract call.

func UnexpectedOpcode

func UnexpectedOpcode(method string, op opcode.Opcode) error

UnexpectedOpcode returns error when notary parsers get unexpected opcode in contract call.

func WrongNumberOfParameters

func WrongNumberOfParameters(exp, act int) error

WrongNumberOfParameters returns an error about wrong number of smart contract parameters.

Types

type BlockCounter

type BlockCounter interface {
	BlockCount() (res uint32, err error)
}

BlockCounter must return block count of the network from which notary requests are received.

type BlockHandler

type BlockHandler func(*block.Block)

BlockHandler is a chain block processing function.

type Event

type Event interface {
	MorphEvent()
}

Event is an interface that is provided by Neo:Morph event structures.

type ExpiredTXError added in v0.37.0

type ExpiredTXError struct {
	CurrentBlockHeight             uint32
	FallbackTXNotValidBeforeHeight uint32
}

ExpiredTXError is returned if received fallback TX is already valid.

func (*ExpiredTXError) Error added in v0.37.0

func (e *ExpiredTXError) Error() string

type Handler

type Handler func(Event)

Handler is an Event processing function.

func WorkerPoolHandler

func WorkerPoolHandler(w util2.WorkerPool, h Handler, log *logger.Logger) Handler

WorkerPoolHandler sets closure over worker pool w with passed handler h.

type Listener

type Listener interface {
	// Listen must start the event listener.
	//
	// Must listen to events with the parser installed.
	Listen(context.Context)

	// ListenWithError must start the event listener.
	//
	// Must listen to events with the parser installed.
	//
	// Must send error to channel if subscriber channel has been closed or
	// it could not be started.
	ListenWithError(context.Context, chan<- error)

	// SetNotificationParser must set the parser of particular contract event.
	//
	// Parser of each event must be set once. All parsers must be set before Listen call.
	//
	// Must ignore nil parsers and all calls after listener has been started.
	SetNotificationParser(NotificationParserInfo)

	// RegisterNotificationHandler must register the event handler for particular notification event of contract.
	//
	// The specified handler must be called after each capture and parsing of the event.
	//
	// Must ignore nil handlers.
	RegisterNotificationHandler(NotificationHandlerInfo)

	// EnableNotarySupport enables notary request listening. Passed hash is
	// notary mainTX signer. In practise, it means that listener will subscribe
	// for only notary requests that are going to be paid with passed hash.
	//
	// Must not be called after Listen or ListenWithError.
	EnableNotarySupport(util.Uint160, client.AlphabetKeys, BlockCounter)

	// SetNotaryParser must set the parser of particular notary request event.
	//
	// Parser of each event must be set once. All parsers must be set before Listen call.
	//
	// Must ignore nil parsers and all calls after listener has been started.
	//
	// Has no effect if EnableNotarySupport was not called before Listen or ListenWithError.
	SetNotaryParser(NotaryParserInfo)

	// RegisterNotaryHandler must register the event handler for particular notification event of contract.
	//
	// The specified handler must be called after each capture and parsing of the event.
	//
	// Must ignore nil handlers.
	//
	// Has no effect if EnableNotarySupport was not called before Listen or ListenWithError.
	RegisterNotaryHandler(NotaryHandlerInfo)

	// RegisterBlockHandler must register chain block handler.
	//
	// The specified handler must be called after each capture and parsing of the new block from chain.
	//
	// Must ignore nil handlers.
	RegisterBlockHandler(BlockHandler)

	// Stop must stop the event listener.
	Stop()
}

Listener is an interface of smart contract notification event listener.

func NewListener

func NewListener(p ListenerParams) (Listener, error)

NewListener create the notification event listener instance and returns Listener interface.

type ListenerParams

type ListenerParams struct {
	Logger *logger.Logger

	Subscriber subscriber.Subscriber

	WorkerPoolCapacity int
}

ListenerParams is a group of parameters for Listener constructor.

type NotaryEvent

type NotaryEvent interface {
	ScriptHash() util.Uint160
	Type() NotaryType
	Params() []Op

	Raw() *payload.P2PNotaryRequest
}

NotaryEvent is an interface that is provided by Neo:Morph notary event structures.

type NotaryHandlerInfo

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

NotaryHandlerInfo is a structure that groups the parameters of the handler of particular notary event.

func (NotaryHandlerInfo) Handler

func (nhi NotaryHandlerInfo) Handler() Handler

Handler returns an event handler.

func (*NotaryHandlerInfo) SetHandler

func (nhi *NotaryHandlerInfo) SetHandler(v Handler)

SetHandler is an event handler setter.

type NotaryParser

type NotaryParser func(NotaryEvent) (Event, error)

NotaryParser is a function that constructs Event from the NotaryEvent event.

type NotaryParserInfo

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

NotaryParserInfo is a structure that groups the parameters of particular notary request event parser.

func (*NotaryParserInfo) SetParser

func (n *NotaryParserInfo) SetParser(p NotaryParser)

type NotaryPreparator

type NotaryPreparator interface {
	Prepare(*payload.P2PNotaryRequest) (NotaryEvent, error)
}

NotaryPreparator constructs NotaryEvent from the NotaryRequest event.

type NotaryType

type NotaryType string

NotaryType is a notary event enumeration type.

func NotaryTypeFromBytes

func NotaryTypeFromBytes(data []byte) NotaryType

NotaryTypeFromBytes converts bytes slice to NotaryType.

func NotaryTypeFromString

func NotaryTypeFromString(str string) NotaryType

NotaryTypeFromString converts string to NotaryType.

func (NotaryType) Equal

func (t NotaryType) Equal(t2 NotaryType) bool

Equal compares two NotaryType values and returns true if they are equal.

func (NotaryType) String

func (t NotaryType) String() string

String returns casted to string NotaryType.

type NotificationHandlerInfo

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

NotificationHandlerInfo is a structure that groups the parameters of the handler of particular contract event.

func (NotificationHandlerInfo) Handler

func (s NotificationHandlerInfo) Handler() Handler

Handler returns an event handler.

func (*NotificationHandlerInfo) SetHandler

func (s *NotificationHandlerInfo) SetHandler(v Handler)

SetHandler is an event handler setter.

type NotificationParser

type NotificationParser func(*state.ContainedNotificationEvent) (Event, error)

NotificationParser is a function that constructs Event from the StackItem list.

type NotificationParserInfo

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

NotificationParserInfo is a structure that groups the parameters of particular contract notification event parser.

func (*NotificationParserInfo) SetParser

SetParser is an event parser setter.

func (*NotificationParserInfo) SetType

func (s *NotificationParserInfo) SetType(v Type)

SetType is an event type setter.

type Op

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

Op is wrapper over Neo VM's opcode and its parameter.

func (Op) Code

func (o Op) Code() opcode.Opcode

Code returns Neo VM opcode.

func (Op) Param

func (o Op) Param() []byte

Param returns parameter of wrapped Neo VM opcode.

type Preparator

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

Preparator implements NotaryPreparator interface.

func (Preparator) Prepare

Prepare converts raw notary requests to NotaryEvent.

Returns ErrTXAlreadyHandled if transaction shouldn't be parsed and handled. It is not "error case". Every handled transaction is expected to be received one more time from the Notary service but already signed. This happens since every notary call is a new notary request in fact.

type PreparatorPrm

type PreparatorPrm struct {
	AlphaKeys client.AlphabetKeys

	// BlockCount must return block count of the network
	// from which notary requests are received.
	BlockCounter BlockCounter
}

PreparatorPrm groups the required parameters of the Preparator constructor.

type Type

type Type string

Type is a notification event enumeration type.

func TypeFromBytes

func TypeFromBytes(data []byte) Type

TypeFromBytes converts bytes slice to Type.

func TypeFromString

func TypeFromString(str string) Type

TypeFromString converts string to Type.

func (Type) Equal

func (t Type) Equal(t2 Type) bool

Equal compares two Type values and returns true if they are equal.

func (Type) String

func (t Type) String() string

String returns casted to string Type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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