ws

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected          = errors.New("websocket not connected")
	ErrUrlEmpty              = errors.New("url can not be empty")
	ErrUrlWrongScheme        = errors.New("websocket uri must start with ws or wss scheme")
	ErrUrlNamePassNotAllowed = errors.New("user name and password are not allowed in websocket uri")
)

Functions

This section is empty.

Types

type AccountResult

type AccountResult struct {
	Context struct {
		Slot uint64
	} `json:"context"`
	Value struct {
		rpc.Account
	} `json:"value"`
}

type Client

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

func NewClient

func NewClient(wsURL string, verbose bool) *Client

func (*Client) AccountSubscribe

func (c *Client) AccountSubscribe(account solana.PublicKey, commitment rpc.CommitmentType) (*Subscription, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) CloseAndReconnect

func (c *Client) CloseAndReconnect()

func (*Client) Dial

func (c *Client) Dial(ctx context.Context) (err error)

func (*Client) IsConnected

func (c *Client) IsConnected() bool

func (*Client) LogSubscribe

func (c *Client) LogSubscribe(account solana.PublicKey, commitment rpc.CommitmentType) (*Subscription, error)

func (*Client) ProgramSubscribe

func (c *Client) ProgramSubscribe(programId solana.PublicKey, commitment rpc.CommitmentType) (*Subscription, error)

func (*Client) SignatureSubscribe

func (c *Client) SignatureSubscribe(signature string, commitment rpc.CommitmentType) (*Subscription, error)

func (*Client) SlotSubscribe

func (c *Client) SlotSubscribe() (*Subscription, error)

type LogResult

type LogResult struct {
	Context struct {
		Slot uint64
	} `json:"context"`
	Value struct {
		Signature string   `json:"signature"`
		Logs      []string `json:"logs"`
	} `json:"value"`
}

type ProgramResult

type ProgramResult struct {
	Context struct {
		Slot uint64
	} `json:"context"`
	Value struct {
		PubKey  solana.PublicKey `json:"pubkey"`
		Account rpc.Account      `json:"account"`
	} `json:"value"`
}

type SignatureResult

type SignatureResult struct {
	Context struct {
		Slot uint64
	} `json:"context"`
	Value struct {
		Err interface{} `json:"err"`
	} `json:"value"`
}

type SlotResult

type SlotResult struct {
	Parent uint64
	Root   uint64
	Slot   uint64
}

type Subscription

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

func (*Subscription) Recv

func (s *Subscription) Recv(ctx context.Context) (interface{}, error)

Recv waits for a message to arrive through the WebSocket connection for this exact subscription.

It will either returns:

  • `<value>, nil` If the stream has a message available
  • `nil, err` If the subscription encounteted an error
  • `nil, context.Canceled` If the context received was canceled
  • `nil, context.DeadlineExceed` If the context timeout was reached

Upon receiving a `context.Canceled` or `context.DeadlineExceed`, the subscription is automatically unsubscribed.

*Future* It's not clear if `ctx context.Context` is appropriate here. Indeed, the gRPC way of doing things it to accept a `ctx context.Context` for the whole subscription lifecycle. The subscription is then tied to the context and closes automatically. The `Recv` method in this case does not accept a `ctx` object and uses the subscription one instead.

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe()

type Websocket

type Websocket struct {
	// Websocket ID
	Id uint64
	// Websocket Meta
	Meta map[string]interface{}

	Logger *zap.Logger

	Errors chan<- error

	Reconnect bool

	// default to 2 seconds
	ReconnectIntervalMin time.Duration
	// default to 30 seconds
	ReconnectIntervalMax time.Duration
	// interval, default to 1.5
	ReconnectIntervalFactor float64
	// default to 2 seconds
	HandshakeTimeout time.Duration
	// Verbose suppress connecting/reconnecting messages.
	Verbose bool

	// Cal function
	OnConnect    func(ws *Websocket)
	OnDisconnect func(ws *Websocket)

	OnConnectError    func(ws *Websocket, err error)
	OnDisconnectError func(ws *Websocket, err error)
	OnReadError       func(ws *Websocket, err error)
	OnWriteError      func(ws *Websocket, err error)

	*websocket.Conn
	// contains filtered or unexported fields
}

func (*Websocket) Close

func (ws *Websocket) Close()

func (*Websocket) Connect

func (ws *Websocket) Connect()

func (*Websocket) Dial

func (ws *Websocket) Dial(urlStr string) error

func (*Websocket) GetDialError

func (ws *Websocket) GetDialError() error

func (*Websocket) GetHTTPResponse

func (ws *Websocket) GetHTTPResponse() *http.Response

func (*Websocket) IsConnected

func (ws *Websocket) IsConnected() bool

func (*Websocket) ReadMessage

func (ws *Websocket) ReadMessage() (messageType int, message []byte, err error)

func (*Websocket) WriteJSON

func (ws *Websocket) WriteJSON(v interface{}) error

func (*Websocket) WriteMessage

func (ws *Websocket) WriteMessage(messageType int, data []byte) error

type WsOpts

type WsOpts func(dl *websocket.Dialer)

Jump to

Keyboard shortcuts

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