tendermint: github.com/tendermint/tendermint/rpc/lib/client Index | Files

package rpcclient

import "github.com/tendermint/tendermint/rpc/lib/client"

Index

Package Files

decode.go encode.go http_json_client.go http_uri_client.go ws_client.go

Constants

const (
    // URIClientRequestID in a request ID used by URIClient
    URIClientRequestID = types.JSONRPCIntID(-1)
)

func DefaultHTTPClient Uses

func DefaultHTTPClient(remoteAddr string) (*http.Client, error)

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://). An error will be returned in case of invalid remoteAddr.

func MaxReconnectAttempts Uses

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 Uses

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

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

func PingPeriod Uses

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 Uses

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 Uses

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.

type HTTPClient Uses

type HTTPClient interface {
    // Call calls the given method with the params and returns a result.
    Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)
    // Codec returns an amino codec used.
    Codec() *amino.Codec
    // SetCodec sets an amino codec.
    SetCodec(*amino.Codec)
}

HTTPClient is a common interface for JSON-RPC HTTP clients.

type JSONRPCCaller Uses

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 Uses

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

JSONRPCClient is a JSON-RPC client, which sends POST HTTP requests to the remote server.

Request values are amino encoded. Response is expected to be amino encoded. New amino codec is used if no other codec was set using SetCodec.

JSONRPCClient is safe for concurrent use by multiple goroutines.

func NewJSONRPCClient Uses

func NewJSONRPCClient(remote string) (*JSONRPCClient, error)

NewJSONRPCClient returns a JSONRPCClient pointed at the given address. An error is returned on invalid remote. The function panics when remote is nil.

func NewJSONRPCClientWithHTTPClient Uses

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

NewJSONRPCClientWithHTTPClient returns a JSONRPCClient pointed at the given address using a custom http client. An error is returned on invalid remote. The function panics when remote is nil.

func (*JSONRPCClient) Call Uses

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

Call issues a POST HTTP request. Requests are JSON encoded. Content-Type: text/json.

func (*JSONRPCClient) Codec Uses

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

func (*JSONRPCClient) NewRequestBatch Uses

func (c *JSONRPCClient) NewRequestBatch() *JSONRPCRequestBatch

NewRequestBatch starts a batch of requests for this client.

func (*JSONRPCClient) SetCodec Uses

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

type JSONRPCRequestBatch Uses

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 Uses

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 Uses

func (b *JSONRPCRequestBatch) Clear() int

Clear empties out the request batch.

func (*JSONRPCRequestBatch) Count Uses

func (b *JSONRPCRequestBatch) Count() int

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

func (*JSONRPCRequestBatch) Send Uses

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 Uses

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

URIClient is a JSON-RPC client, which sends POST form HTTP requests to the remote server.

Request values are amino encoded. Response is expected to be amino encoded. New amino codec is used if no other codec was set using SetCodec.

URIClient is safe for concurrent use by multiple goroutines.

func NewURIClient Uses

func NewURIClient(remote string) (*URIClient, error)

NewURIClient returns a new client. An error is returned on invalid remote. The function panics when remote is nil.

func (*URIClient) Call Uses

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

Call issues a POST form HTTP request.

func (*URIClient) Codec Uses

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

func (*URIClient) SetCodec Uses

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

type WSClient Uses

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

    // Single user facing channel to read RPCResponses from, closed only when the
    // client is being stopped.
    ResponsesCh chan types.RPCResponse

    service.BaseService

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

WSClient is a JSON-RPC client, which uses WebSocket for communication with the remote server.

WSClient is safe for concurrent use by multiple goroutines.

func NewWSClient Uses

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

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 `/`. An error is returned on invalid remote. The function panics when remote is nil.

func (*WSClient) Call Uses

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

Call enqueues a call request onto the Send queue. Requests are JSON encoded.

func (*WSClient) CallWithArrayParams Uses

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

CallWithArrayParams enqueues a call request onto the Send queue. Params are in a form of array (e.g. []interface{}{"abcd"}). Requests are JSON encoded.

func (*WSClient) Codec Uses

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

func (*WSClient) IsActive Uses

func (c *WSClient) IsActive() bool

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

func (*WSClient) IsReconnecting Uses

func (c *WSClient) IsReconnecting() bool

IsReconnecting returns true if the client is reconnecting right now.

func (*WSClient) OnStart Uses

func (c *WSClient) OnStart() error

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

func (*WSClient) Send Uses

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 Uses

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

func (*WSClient) Stop Uses

func (c *WSClient) Stop() error

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

func (*WSClient) String Uses

func (c *WSClient) String() string

String returns WS client full address.

func (*WSClient) Subscribe Uses

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 Uses

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 Uses

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

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

Package rpcclient imports 19 packages (graph) and is imported by 35 packages. Updated 2020-01-10. Refresh now. Tools for package owners.