waiter

package
v0.105.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const PollingBasedRetryCount = 3

PollingBasedRetryCount is a threshold for a number of subsequent failed attempts to get block count from the RPC server for PollingBased. If it fails to retrieve block count PollingBasedRetryCount times in a raw then transaction awaiting attempt considered to be failed and an error is returned.

Variables

View Source
var (
	// ErrTxNotAccepted is returned when transaction wasn't accepted to the chain
	// even after ValidUntilBlock block persist.
	ErrTxNotAccepted = errors.New("transaction was not accepted to chain")
	// ErrContextDone is returned when Waiter context has been done in the middle
	// of transaction awaiting process and no result was received yet.
	ErrContextDone = errors.New("waiter context done")
	// ErrAwaitingNotSupported is returned from Wait method if Waiter instance
	// doesn't support transaction awaiting.
	ErrAwaitingNotSupported = errors.New("awaiting not supported")
	// ErrMissedEvent is returned when RPCEventBased closes receiver channel
	// which happens if missed event was received from the RPC server.
	ErrMissedEvent = errors.New("some event was missed")
)

Functions

This section is empty.

Types

type EventBased

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

EventBased is a websocket-based Waiter.

func NewEventBased

func NewEventBased(waiter RPCEventBased) (*EventBased, error)

NewEventBased creates an instance of Waiter supporting websocket event-based transaction awaiting. EventBased contains PollingBased under the hood and falls back to polling when subscription-based awaiting fails.

func (*EventBased) Wait

func (w *EventBased) Wait(h util.Uint256, vub uint32, err error) (res *state.AppExecResult, waitErr error)

Wait implements Waiter interface.

func (*EventBased) WaitAny

func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uint256) (res *state.AppExecResult, waitErr error)

WaitAny implements Waiter interface.

type Null

type Null struct{}

Null is a Waiter stub that doesn't support transaction awaiting functionality.

func NewNull

func NewNull() Null

NewNull creates an instance of Waiter stub.

func (Null) Wait

func (Null) Wait(h util.Uint256, vub uint32, err error) (*state.AppExecResult, error)

Wait implements Waiter interface.

func (Null) WaitAny

func (Null) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uint256) (*state.AppExecResult, error)

WaitAny implements Waiter interface.

type PollingBased

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

PollingBased is a polling-based Waiter.

func NewPollingBased

func NewPollingBased(waiter RPCPollingBased) (*PollingBased, error)

NewPollingBased creates an instance of Waiter supporting poll-based transaction awaiting.

func (*PollingBased) Wait

func (w *PollingBased) Wait(h util.Uint256, vub uint32, err error) (*state.AppExecResult, error)

Wait implements Waiter interface.

func (*PollingBased) WaitAny

func (w *PollingBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uint256) (*state.AppExecResult, error)

WaitAny implements Waiter interface.

type RPCEventBased

type RPCEventBased interface {
	RPCPollingBased

	ReceiveHeadersOfAddedBlocks(flt *neorpc.BlockFilter, rcvr chan<- *block.Header) (string, error)
	ReceiveBlocks(flt *neorpc.BlockFilter, rcvr chan<- *block.Block) (string, error)
	ReceiveExecutions(flt *neorpc.ExecutionFilter, rcvr chan<- *state.AppExecResult) (string, error)
	Unsubscribe(id string) error
}

RPCEventBased is an interface that enables improved transaction awaiting functionality based on web-socket Block and ApplicationLog notifications. RPCEventBased contains RPCPollingBased under the hood and falls back to polling when subscription-based awaiting fails.

type RPCPollingBased

type RPCPollingBased interface {
	// Context should return the RPC client context to be able to gracefully
	// shut down all running processes (if so).
	Context() context.Context
	GetVersion() (*result.Version, error)
	GetBlockCount() (uint32, error)
	GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error)
}

RPCPollingBased is an interface that enables transaction awaiting functionality based on periodical BlockCount and ApplicationLog polls.

type Waiter

type Waiter interface {
	// Wait allows to wait until transaction will be accepted to the chain. It can be
	// used as a wrapper for Send or SignAndSend and accepts transaction hash,
	// ValidUntilBlock value and an error. It returns transaction execution result
	// or an error if transaction wasn't accepted to the chain. Notice that "already
	// exists" err value is not treated as an error by this routine because it
	// means that the transactions given might be already accepted or soon going
	// to be accepted. Such transaction can be waited for in a usual way, potentially
	// with positive result, so that's what will happen.
	Wait(h util.Uint256, vub uint32, err error) (*state.AppExecResult, error)
	// WaitAny waits until at least one of the specified transactions will be accepted
	// to the chain until vub (including). It returns execution result of this
	// transaction or an error if none of the transactions was accepted to the chain.
	// It uses underlying RPCPollingBased or RPCEventBased context to interrupt
	// awaiting process, but additional ctx can be passed as an argument for the same
	// purpose.
	WaitAny(ctx context.Context, vub uint32, hashes ...util.Uint256) (*state.AppExecResult, error)
}

Waiter is an interface providing transaction awaiting functionality.

func New

func New(base any, v *result.Version) Waiter

New creates Waiter instance. It can be either websocket-based or polling-base, otherwise Waiter stub is returned. As a first argument it accepts RPCEventBased implementation, RPCPollingBased implementation or not an implementation of these two interfaces. It returns websocket-based waiter, polling-based waiter or a stub correspondingly.

Jump to

Keyboard shortcuts

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