websocketrpc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubscribeAccountRequest   = "accountSubscribe"
	UnsubscribeAccountRequest = "accountUnsubscribe"
)

Predefined subscribe/unsubscribe request methods.

View Source
const (
	EncodingJSONParsed = "jsonParsed"
	EncodingBase58     = "base58"
	EncodingBase64     = "base64"
	EncodingBase64Zstd = "base64+zstd"
)

Predefined encoding types.

View Source
const (
	CommitmentFinalized = "finalized"
	CommitmentConfirmed = "confirmed"
	CommitmentProcessed = "processed"
)

Predefined commitment levels.

View Source
const (
	EventAccountNotification = "accountNotification"
)

Predefined event names.

Variables

View Source
var (
	ErrInvalidResponse  = errors.New("invalid response")
	ErrConnectionClosed = errors.New("connection closed")
)

Predefined errors.

Functions

func AccountSubscribeRequestPayload

func AccountSubscribeRequestPayload(base58Addr string) []interface{}

Account subscribe request payload. It's a helper function to create a request payload for the account subscribe request, but you can also create the payload manually.

func AccountUnsubscribeRequestPayload

func AccountUnsubscribeRequestPayload(subscriptionID interface{}) []interface{}

AccountUnsubscribeRequestPayload returns an account unsubscribe request payload.

Types

type Client

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

func NewClient

func NewClient(conn *websocket.Conn, opts ...ClientOption) *Client

NewClient creates a new websocket rpc client. It accepts a websocket connection and optional client options.

func (*Client) ListenNewTransactions

func (c *Client) ListenNewTransactions(event events.EventName, payload interface{}) error

ListenNewTransactions listens for new transactions created event.

func (*Client) ListenTransactionUpdates

func (c *Client) ListenTransactionUpdates(event events.EventName, payload interface{}) error

ListenTransactionUpdates listens for transaction updates.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run websocket rpc service.

func (*Client) Subscribe

func (c *Client) Subscribe(base58Addr string) error

Subscribe subscribes for account notifications to the given wallet address.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(subID float64) error

Unsubscribe unsubscribes from account notifications for the given subscription ID.

func (*Client) UnsubscribeByAddress

func (c *Client) UnsubscribeByAddress(base58Addr string) error

UnsubscribeByAddress unsubscribes from account notifications for the given wallet address.

type ClientOption

type ClientOption func(*Client)

func WithEventsEmitter

func WithEventsEmitter(e eventsEmitter) ClientOption

WithEventsEmitter sets the events emitter for the client.

func WithLogger

func WithLogger(l logger) ClientOption

WithLogger sets the logger for the client.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error represents a JSON-RPC error

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface

type Event

type Event struct {
	Version string       `json:"jsonrpc"`
	Method  string       `json:"method"`
	Params  *EventParams `json:"params,omitempty"`
}

Event represents a JSON-RPC event

type EventHandler

type EventHandler func(base58Addr string, event json.RawMessage) error

type EventParams

type EventParams struct {
	Result       json.RawMessage `json:"result,omitempty"`
	Subscription json.Number     `json:"subscription,omitempty"`
}

EventParams represents the params of a JSON-RPC event

type NotificationPayload

type NotificationPayload struct {
	Result struct {
		Context struct {
			Slot int `json:"slot"`
		} `json:"context"`
		Value json.RawMessage `json:"value"`
	} `json:"result"`
	Subscription int `json:"subscription"`
}

NotificationPayload represents an notification payload from the websocket server. See https://docs.solana.com/api/websocket

type Request

type Request struct {
	Version string      `json:"jsonrpc"`
	ID      uint64      `json:"id,omitempty"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
}

Request represents a JSON-RPC notification

type Response

type Response struct {
	Version string          `json:"jsonrpc"`
	ID      uint64          `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

Response represents a JSON-RPC response

type ResponseCallback

type ResponseCallback func(json.RawMessage, error) error

Jump to

Keyboard shortcuts

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