client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: Apache-2.0, Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func ConvTCM392CM4

func ConvTCM392CM4(c *CM39ResultTx, ret *coretypes.ResultTx)

func ConvTCM39ResultABCIQuery2CM4

func ConvTCM39ResultABCIQuery2CM4(c *CM39ResultABCIQuery, ret *coretypes.ResultABCIQuery)

func DefaultHTTPClient

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

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

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

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

func PingPeriod

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

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

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 CM39ResponseDeliverTx

type CM39ResponseDeliverTx struct {
	Code      uint32       `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Data      []byte       `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	Log       string       `protobuf:"bytes,3,opt,name=log,proto3" json:"log,omitempty"`
	Info      string       `protobuf:"bytes,4,opt,name=info,proto3" json:"info,omitempty"`
	GasWanted int64        `protobuf:"varint,5,opt,name=gas_wanted,json=gasWanted,proto3" json:"gas_wanted,omitempty"`
	GasUsed   int64        `protobuf:"varint,6,opt,name=gas_used,json=gasUsed,proto3" json:"gas_used,omitempty"`
	Events    []abci.Event `protobuf:"bytes,7,rep,name=events,proto3" json:"events,omitempty"`
	Codespace string       `protobuf:"bytes,8,opt,name=codespace,proto3" json:"codespace,omitempty"`
}

type CM39ResponseQuery

type CM39ResponseQuery struct {
	Code uint32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	// bytes data = 2; // use "value" instead.
	Log       string        `protobuf:"bytes,3,opt,name=log,proto3" json:"log,omitempty"`
	Info      string        `protobuf:"bytes,4,opt,name=info,proto3" json:"info,omitempty"`
	Index     int64         `protobuf:"varint,5,opt,name=index,proto3" json:"index,omitempty"`
	Key       []byte        `protobuf:"bytes,6,opt,name=key,proto3" json:"key,omitempty"`
	Value     []byte        `protobuf:"bytes,7,opt,name=value,proto3" json:"value,omitempty"`
	Proof     *merkle.Proof `protobuf:"bytes,8,opt,name=proof,proto3" json:"proof,omitempty"`
	Height    int64         `protobuf:"varint,9,opt,name=height,proto3" json:"height,omitempty"`
	Codespace string        `protobuf:"bytes,10,opt,name=codespace,proto3" json:"codespace,omitempty"`
}

type CM39ResultABCIQuery

type CM39ResultABCIQuery struct {
	Response CM39ResponseQuery `json:"response"`
}

Query abci msg

type CM39ResultBroadcastTxCommit

type CM39ResultBroadcastTxCommit struct {
	CheckTx   abci.ResponseCheckTx  `json:"check_tx"`
	DeliverTx CM39ResponseDeliverTx `json:"deliver_tx"`
	Hash      bytes.HexBytes        `json:"hash"`
	Height    int64                 `json:"height"`
}

type CM39ResultTx

type CM39ResultTx struct {
	Hash     bytes.HexBytes        `json:"hash"`
	Height   int64                 `json:"height"`
	Index    uint32                `json:"index"`
	TxResult CM39ResponseDeliverTx `json:"tx_result"`
	Tx       types.Tx              `json:"tx"`
	Proof    types.TxProof         `json:"proof,omitempty"`
}

Result of querying for a tx

type Caller

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

Caller implementers can facilitate calling the JSON-RPC endpoint.

type Client

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

Client 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.

Client is safe for concurrent use by multiple goroutines.

func New

func New(remote string) (*Client, error)

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

func NewWithHTTPClient

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

NewWithHTTPClient returns a Client 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 (*Client) Call

func (c *Client) 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 (*Client) Codec

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

func (*Client) NewRequestBatch

func (c *Client) NewRequestBatch() *RequestBatch

NewRequestBatch starts a batch of requests for this client.

func (*Client) SetCodec

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

type Cm39HttpJSONClientAdapter

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

func NewCm39HttpJSONClient

func NewCm39HttpJSONClient(remote string, client *http.Client) (*Cm39HttpJSONClientAdapter, error)

func (*Cm39HttpJSONClientAdapter) Call

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

type HTTPClient

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 RequestBatch

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

RequestBatch 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 (*RequestBatch) Call

func (b *RequestBatch) 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 `Client.Call` function would.

func (*RequestBatch) Clear

func (b *RequestBatch) Clear() int

Clear empties out the request batch.

func (*RequestBatch) Count

func (b *RequestBatch) Count() int

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

func (*RequestBatch) Send

func (b *RequestBatch) 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
}

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 NewURI

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

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

func (*URIClient) Call

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

Call issues a POST form HTTP request.

func (*URIClient) Codec

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

func (*URIClient) SetCodec

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

type WSClient

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 NewWS

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

NewWS 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

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

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

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

func (*WSClient) IsActive

func (c *WSClient) IsActive() bool

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

func (*WSClient) IsReconnecting

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 service.Service by dialing a server and creating read and write routines.

func (*WSClient) Send

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

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

func (*WSClient) Stop

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

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

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