package module
v0.3.1 Latest Latest

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 8 Imported by: 1


Antelope SHIP Client

Test Go Reference Go Report Card

Client Implementation of Antelope state-history websocket.

Install package
go get -u

Documentation can be found over at


Henrik Hautakoski - Sw/eden -



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)



View Source
const NULL_BLOCK_NUMBER uint32 = 0xffffffff


View Source
var ErrEndBlockReached = errors.New("ship: end block reached")


This section is empty.


type BlockFn added in v0.2.1

type BlockFn func(*ship.GetBlocksResultV0)

type CloseFn added in v0.2.1

type CloseFn func()

type InitFn added in v0.2.1

type InitFn func(*chain.Abi)

type Option added in v0.2.1

type Option func(*Stream)

func WithBlockHandler added in v0.2.1

func WithBlockHandler(value BlockFn) Option

Option to set Stream.BlockHandler

func WithCloseHandler added in v0.2.1

func WithCloseHandler(value CloseFn) Option

Option to set Stream.CloseHandler

func WithConnectTimeout added in v0.2.2

func WithConnectTimeout(value time.Duration) Option

Option to set Stream.ConnectTimeout

func WithEndBlock added in v0.2.1

func WithEndBlock(value uint32) Option

Option to set Stream.EndBlock

func WithInitHandler added in v0.2.1

func WithInitHandler(value InitFn) Option

Option to set Stream.InitHandler

func WithIrreversibleOnly added in v0.2.1

func WithIrreversibleOnly(value bool) Option

Option to set Stream.IrreversibleOnly

func WithShutdownTimeout added in v0.2.2

func WithShutdownTimeout(value time.Duration) Option

Option to set Stream.ShutdownTimeout

func WithStartBlock added in v0.2.1

func WithStartBlock(value uint32) Option

Option to set Stream.StartBlock

func WithStatusHandler added in v0.2.1

func WithStatusHandler(value StatusFn) Option

Option to set Stream.StatusHandler

func WithTableDeltaHandler added in v0.2.4

func WithTableDeltaHandler(value TableDeltaFn) Option

func WithTraceHandler added in v0.2.1

func WithTraceHandler(value TraceFn) Option

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

	// Callback functions
	InitHandler       InitFn
	BlockHandler      BlockFn
	TraceHandler      TraceFn
	TableDeltaHandler TableDeltaFn
	StatusHandler     StatusFn
	CloseHandler      CloseFn
	// contains filtered or unexported fields

func NewStream added in v0.2.3

func NewStream(options ...Option) *Stream

Create a new stream

func (*Stream) Connect added in v0.2.3

func (s *Stream) Connect(url string) error

Connect uses context.Background internally; to specify the context, use ConnectContext.

func (*Stream) ConnectContext added in v0.2.3

func (s *Stream) ConnectContext(ctx context.Context, url string) error

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

func (s *Stream) Run() error

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

func (s *Stream) SendBlocksRequest() error

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

func (s *Stream) SendStatusRequest() error

Send a status request to the ship server. This tells the server to start sending status message to the client.

func (*Stream) Shutdown added in v0.2.3

func (s *Stream) Shutdown() error

Shutdown closes the stream gracefully by performing a websocket close handshake. This function will block until a close message is received from the server an error occure or timeout is exceeded.

type TableDeltaFn added in v0.2.4

type TableDeltaFn func(*ship.TableDeltaArray)

type TraceFn added in v0.2.1

type TraceFn func(*ship.TransactionTraceArray)


Path Synopsis

Jump to

Keyboard shortcuts

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