rpcclient

package
v0.26.0-polygon Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHTTPClient

func DefaultHTTPClient(remoteAddr string) *http.Client

DefaultHTTPClient is used to create an http client with some default parameters. We overwrite the http.Client.Dial so we can do http over tcp or unix. remoteAddr should be fully featured (eg. with tcp:// or unix://)

func MaxReconnectAttempts added in v0.10.5

func MaxReconnectAttempts(max int) func(*WSClient)

MaxReconnectAttempts sets the maximum number of reconnect attempts before returning an error. It should only be used in the constructor and is not Goroutine-safe.

func OnReconnect added in v0.15.0

func OnReconnect(cb func()) func(*WSClient)

OnReconnect sets the callback, which will be called every time after successful reconnect.

func PingPeriod added in v0.10.5

func PingPeriod(pingPeriod time.Duration) func(*WSClient)

PingPeriod sets the duration for sending websocket pings. It should only be used in the constructor - not Goroutine-safe.

func ReadWait added in v0.10.5

func ReadWait(readWait time.Duration) func(*WSClient)

ReadWait sets the amount of time to wait before a websocket read times out. It should only be used in the constructor and is not Goroutine-safe.

func WriteWait added in v0.10.5

func WriteWait(writeWait time.Duration) func(*WSClient)

WriteWait sets the amount of time to wait before a websocket write times out. It should only be used in the constructor and is not Goroutine-safe.

Types

type HTTPClient

type HTTPClient interface {
	Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)
	Codec() *amino.Codec
	SetCodec(*amino.Codec)
}

HTTPClient is a common interface for JSONRPCClient and URIClient.

type JSONRPCCaller

type JSONRPCCaller interface {
	Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)
}

JSONRPCCaller implementers can facilitate calling the JSON RPC endpoint.

type JSONRPCClient

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

JSONRPCClient takes params as a slice

func NewJSONRPCClient

func NewJSONRPCClient(remote string) *JSONRPCClient

NewJSONRPCClient returns a JSONRPCClient pointed at the given address.

func NewJSONRPCClientWithHTTPClient

func NewJSONRPCClientWithHTTPClient(remote string, client *http.Client) *JSONRPCClient

NewJSONRPCClientWithHTTPClient returns a JSONRPCClient pointed at the given address using a custom http client The function panics if the provided client is nil or remote is invalid.

func (*JSONRPCClient) Call

func (c *JSONRPCClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)

Call will send the request for the given method through to the RPC endpoint immediately, without buffering of requests.

func (*JSONRPCClient) Codec added in v0.19.5

func (c *JSONRPCClient) Codec() *amino.Codec

func (*JSONRPCClient) NewRequestBatch

func (c *JSONRPCClient) NewRequestBatch() *JSONRPCRequestBatch

NewRequestBatch starts a batch of requests for this client.

func (*JSONRPCClient) SetCodec added in v0.19.5

func (c *JSONRPCClient) SetCodec(cdc *amino.Codec)

type JSONRPCRequestBatch

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

JSONRPCRequestBatch allows us to buffer multiple request/response structures into a single batch request. Note that this batch acts like a FIFO queue, and is thread-safe.

func (*JSONRPCRequestBatch) Call

func (b *JSONRPCRequestBatch) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)

Call enqueues a request to call the given RPC method with the specified parameters, in the same way that the `JSONRPCClient.Call` function would.

func (*JSONRPCRequestBatch) Clear

func (b *JSONRPCRequestBatch) Clear() int

Clear empties out the request batch.

func (*JSONRPCRequestBatch) Count

func (b *JSONRPCRequestBatch) Count() int

Count returns the number of enqueued requests waiting to be sent.

func (*JSONRPCRequestBatch) Send

func (b *JSONRPCRequestBatch) Send() ([]interface{}, error)

Send will attempt to send the current batch of enqueued requests, and then will clear out the requests once done. On success, this returns the deserialized list of results from each of the enqueued requests.

type URIClient

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

URI takes params as a map

func NewURIClient

func NewURIClient(remote string) *URIClient

The function panics if the provided remote is invalid.

func (*URIClient) Call

func (c *URIClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)

func (*URIClient) Codec added in v0.19.5

func (c *URIClient) Codec() *amino.Codec

func (*URIClient) SetCodec added in v0.19.5

func (c *URIClient) SetCodec(cdc *amino.Codec)

type WSClient

type WSClient struct {
	cmn.BaseService

	Address  string // IP:PORT or /path/to/socket
	Endpoint string // /websocket/url/endpoint
	Dialer   func(string, string) (net.Conn, error)

	// Time between sending a ping and receiving a pong. See
	// https://godoc.org/github.com/rcrowley/go-metrics#Timer.
	PingPongLatencyTimer metrics.Timer

	// Single user facing channel to read RPCResponses from, closed only when the client is being stopped.
	ResponsesCh chan types.RPCResponse
	// contains filtered or unexported fields
}

WSClient is a WebSocket client. The methods of WSClient are safe for use by multiple goroutines.

func NewWSClient

func NewWSClient(remoteAddr, endpoint string, options ...func(*WSClient)) *WSClient

NewWSClient returns a new client. See the commentary on the func(*WSClient) functions for a detailed description of how to configure ping period and pong wait time. The endpoint argument must begin with a `/`. The function panics if the provided address is invalid.

func (*WSClient) Call

func (c *WSClient) Call(ctx context.Context, method string, params map[string]interface{}) error

Call the given method. See Send description.

func (*WSClient) CallWithArrayParams added in v0.10.5

func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error

CallWithArrayParams the given method with params in a form of array. See Send description.

func (*WSClient) Codec added in v0.19.5

func (c *WSClient) Codec() *amino.Codec

func (*WSClient) IsActive added in v0.10.5

func (c *WSClient) IsActive() bool

IsActive returns true if the client is running and not reconnecting.

func (*WSClient) IsReconnecting added in v0.10.5

func (c *WSClient) IsReconnecting() bool

IsReconnecting returns true if the client is reconnecting right now.

func (*WSClient) OnStart

func (c *WSClient) OnStart() error

OnStart implements cmn.Service by dialing a server and creating read and write routines.

func (*WSClient) Send added in v0.10.5

func (c *WSClient) Send(ctx context.Context, request types.RPCRequest) error

Send the given RPC request to the server. Results will be available on ResponsesCh, errors, if any, on ErrorsCh. Will block until send succeeds or ctx.Done is closed.

func (*WSClient) SetCodec added in v0.19.5

func (c *WSClient) SetCodec(cdc *amino.Codec)

func (*WSClient) Stop added in v0.10.5

func (c *WSClient) Stop() error

Stop overrides cmn.Service#Stop. There is no other way to wait until Quit channel is closed.

func (*WSClient) String

func (c *WSClient) String() string

String returns WS client full address.

func (*WSClient) Subscribe

func (c *WSClient) Subscribe(ctx context.Context, query string) error

Subscribe to a query. Note the server must have a "subscribe" route defined.

func (*WSClient) Unsubscribe

func (c *WSClient) Unsubscribe(ctx context.Context, query string) error

Unsubscribe from a query. Note the server must have a "unsubscribe" route defined.

func (*WSClient) UnsubscribeAll added in v0.10.5

func (c *WSClient) UnsubscribeAll(ctx context.Context) error

UnsubscribeAll from all. Note the server must have a "unsubscribe_all" route defined.

Jump to

Keyboard shortcuts

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