Documentation ¶
Index ¶
- Constants
- Variables
- func AccountSubscribeRequestPayload(base58Addr string) []interface{}
- func AccountUnsubscribeRequestPayload(subscriptionID interface{}) []interface{}
- type Client
- func (c *Client) ListenNewTransactions(event events.EventName, payload interface{}) error
- func (c *Client) ListenTransactionUpdates(event events.EventName, payload interface{}) error
- func (c *Client) Run(ctx context.Context) error
- func (c *Client) Subscribe(base58Addr string) error
- func (c *Client) Unsubscribe(subID float64) error
- func (c *Client) UnsubscribeByAddress(base58Addr string) error
- type ClientOption
- type Error
- type Event
- type EventHandler
- type EventParams
- type NotificationPayload
- type Request
- type Response
- type ResponseCallback
Constants ¶
const ( SubscribeAccountRequest = "accountSubscribe" UnsubscribeAccountRequest = "accountUnsubscribe" )
Predefined subscribe/unsubscribe request methods.
const ( EncodingJSONParsed = "jsonParsed" EncodingBase58 = "base58" EncodingBase64 = "base64" EncodingBase64Zstd = "base64+zstd" )
Predefined encoding types.
const ( CommitmentFinalized = "finalized" CommitmentConfirmed = "confirmed" CommitmentProcessed = "processed" )
Predefined commitment levels.
const (
EventAccountNotification = "accountNotification"
)
Predefined event names.
Variables ¶
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 ¶
ListenNewTransactions listens for new transactions created event.
func (*Client) ListenTransactionUpdates ¶
ListenTransactionUpdates listens for transaction updates.
func (*Client) Subscribe ¶
Subscribe subscribes for account notifications to the given wallet address.
func (*Client) Unsubscribe ¶
Unsubscribe unsubscribes from account notifications for the given subscription ID.
func (*Client) UnsubscribeByAddress ¶
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.
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