Documentation
¶
Overview ¶
Callback functions ¶
This library uses callback functions to allow the users to execute the code needed when certain events are triggered.
the Stream struct accepts the following callback functions
InitHandler func(*eos.ABI)
Called when the first message on the stream arrives. This message contains the abi with all the information about the functions/types exposed by the websocket api.
BlockHandler func(*ship.GetBlocksResultV0)
Called when the stream reveives a block message from the server.
TraceHandler func([]*ship.TransactionTraceV0)
When the stream reveives a block message from the server and the Block has any traces attached to it. these traces are then passed to this callback.
StatusHandler func(*ship.GetStatusResultV0)
Called when the stream reveives a status message.
CloseHandler func()
Called when a stream has closed the socket connection (in `(*Stream) Shutdown()` function)
Index ¶
- Constants
- Variables
- type BlockFn
- type CloseFn
- type InitFn
- type Option
- func WithBlockHandler(value BlockFn) Option
- func WithCloseHandler(value CloseFn) Option
- func WithConnectTimeout(value time.Duration) Option
- func WithEndBlock(value uint32) Option
- func WithInitHandler(value InitFn) Option
- func WithIrreversibleOnly(value bool) Option
- func WithMaxMessagesInFlight(value uint32) Option
- func WithShutdownTimeout(value time.Duration) Option
- func WithStartBlock(value uint32) Option
- func WithStatusHandler(value StatusFn) Option
- func WithTableDeltaHandler(value TableDeltaFn) Option
- func WithTraceHandler(value TraceFn) Option
- func WithTraces() Option
- type StatusFn
- type Stream
- type TableDeltaFn
- type TraceFn
Constants ¶
const NULL_BLOCK_NUMBER uint32 = 0xffffffff
Variables ¶
var ErrEndBlockReached = errors.New("ship: end block reached")
Functions ¶
This section is empty.
Types ¶
type BlockFn ¶ added in v0.2.1
type BlockFn func(*ship.GetBlocksResultV0)
type Option ¶ added in v0.2.1
type Option func(*Stream)
func WithBlockHandler ¶ added in v0.2.1
Option to set Stream.BlockHandler
func WithCloseHandler ¶ added in v0.2.1
Option to set Stream.CloseHandler
func WithConnectTimeout ¶ added in v0.2.2
Option to set Stream.ConnectTimeout
func WithEndBlock ¶ added in v0.2.1
Option to set Stream.EndBlock
func WithInitHandler ¶ added in v0.2.1
Option to set Stream.InitHandler
func WithIrreversibleOnly ¶ added in v0.2.1
Option to set Stream.IrreversibleOnly
func WithMaxMessagesInFlight ¶ added in v0.2.1
Option to set Stream.MaxMessagesInFlight
func WithShutdownTimeout ¶ added in v0.2.2
Option to set Stream.ShutdownTimeout
func WithStartBlock ¶ added in v0.2.1
Option to set Stream.StartBlock
func WithStatusHandler ¶ added in v0.2.1
Option to set Stream.StatusHandler
func WithTableDeltaHandler ¶ added in v0.2.4
func WithTableDeltaHandler(value TableDeltaFn) Option
Option to set Stream.TableDeltaHandler
func WithTraceHandler ¶ added in v0.2.1
Option to set Stream.TraceHandler
func WithTraces ¶ added in v0.2.5
func WithTraces() Option
Option to include traces without using a specific trace handler
type StatusFn ¶ added in v0.2.1
type StatusFn func(*ship.GetStatusResultV0)
type Stream ¶ added in v0.2.3
type Stream struct { // Specifies the duration for the connection to be established before the client bails out. ConnectTimeout time.Duration // Specifies the duration for Shutdown() to wait before forcefully disconnecting the socket. ShutdownTimeout time.Duration // Block to start receiving notifications on. StartBlock uint32 // Block to end receiving notifications on. EndBlock uint32 // if only irreversible blocks should be sent. IrreversibleOnly bool // Max messages that can be sent from the server without being acked. MaxMessagesInFlight uint32 // Callback functions InitHandler InitFn BlockHandler BlockFn TraceHandler TraceFn TableDeltaHandler TableDeltaFn StatusHandler StatusFn CloseHandler CloseFn // contains filtered or unexported fields }
func (*Stream) Connect ¶ added in v0.2.3
Connect uses context.Background internally; to specify the context, use ConnectContext.
func (*Stream) ConnectContext ¶ added in v0.2.3
ConnectContext connects to a ship node using the provided context
The provided Context must be non-nil. If the context expires or is canceled before the connection is complete, an error is returned.
func (*Stream) Run ¶ added in v0.2.3
Run starts the stream. Messages from the server is read and forwarded to the appropriate callback function. This function will block until an error occur or the stream is closed. Either way the return value is never nil.
func (*Stream) SendBlocksRequest ¶ added in v0.2.3
Send a blocks request to the ship server. This tells the server to start sending block message to the client.
func (*Stream) SendStatusRequest ¶ added in v0.2.3
Send a status request to the ship server. This tells the server to start sending status message to the client.
type TableDeltaFn ¶ added in v0.2.4
type TableDeltaFn func(*ship.TableDeltaArray)
type TraceFn ¶ added in v0.2.1
type TraceFn func(*ship.TransactionTraceArray)