Documentation ¶
Index ¶
Constants ¶
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 ¶
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.
type Null ¶
type Null struct{}
Null is a Waiter stub that doesn't support transaction awaiting functionality.
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.
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 ¶
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.