rpc

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 JSONRpcClient

type JSONRpcClient struct {
	*WSEvents
	// contains filtered or unexported fields
}

func NewJSONRpcClient

func NewJSONRpcClient(rpcAddr, wsAddr string, endpoint string, timeout uint, header http.Header) (JSONRpcClient, error)

func (JSONRpcClient) ABCIInfo

func (JSONRpcClient) ABCIQuery

func (c JSONRpcClient) ABCIQuery(ctx context.Context, path string, data tmbytes.HexBytes) (*ctypes.ResultABCIQuery, error)

func (JSONRpcClient) ABCIQueryWithOptions

func (c JSONRpcClient) ABCIQueryWithOptions(ctx context.Context, path string, data tmbytes.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)

func (JSONRpcClient) Block

func (c JSONRpcClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error)

func (JSONRpcClient) BlockByHash

func (c JSONRpcClient) BlockByHash(ctx context.Context, hash []byte) (*ctypes.ResultBlock, error)

func (JSONRpcClient) BlockResults

func (c JSONRpcClient) BlockResults(ctx context.Context, height *int64) (*ctypes.ResultBlockResults, error)

func (JSONRpcClient) BlockchainInfo

func (c JSONRpcClient) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)

func (JSONRpcClient) BroadcastEvidence

func (JSONRpcClient) BroadcastTxAsync

func (c JSONRpcClient) BroadcastTxAsync(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultBroadcastTx, error)

func (JSONRpcClient) BroadcastTxCommit

func (c JSONRpcClient) BroadcastTxCommit(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultBroadcastTxCommit, error)

func (JSONRpcClient) BroadcastTxSync

func (c JSONRpcClient) BroadcastTxSync(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultBroadcastTx, error)

func (*JSONRpcClient) Call

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

func (JSONRpcClient) CheckTx

func (JSONRpcClient) Commit

func (c JSONRpcClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error)

func (JSONRpcClient) ConsensusParams

func (c JSONRpcClient) ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error)

func (JSONRpcClient) ConsensusState

func (c JSONRpcClient) ConsensusState(ctx context.Context) (*ctypes.ResultConsensusState, error)

func (*JSONRpcClient) Do

func (c *JSONRpcClient) Do(req *http.Request) (*http.Response, error)

func (JSONRpcClient) DumpConsensusState

func (c JSONRpcClient) DumpConsensusState(ctx context.Context) (*ctypes.ResultDumpConsensusState, error)

func (JSONRpcClient) Genesis

func (JSONRpcClient) Health

func (JSONRpcClient) NetInfo

func (JSONRpcClient) NumUnconfirmedTxs

func (c JSONRpcClient) NumUnconfirmedTxs(ctx context.Context) (*ctypes.ResultUnconfirmedTxs, error)

func (JSONRpcClient) Quit

func (c JSONRpcClient) Quit() <-chan struct{}

func (JSONRpcClient) SetLogger

func (c JSONRpcClient) SetLogger(logger log.Logger)

func (JSONRpcClient) Status

func (JSONRpcClient) String

func (c JSONRpcClient) String() string

func (JSONRpcClient) Tx

func (c JSONRpcClient) Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.ResultTx, error)

func (JSONRpcClient) TxSearch

func (c JSONRpcClient) TxSearch(ctx context.Context, query string, prove bool, page, perPage *int, orderBy string) (*ctypes.ResultTxSearch, error)

func (JSONRpcClient) UnconfirmedTxs

func (c JSONRpcClient) UnconfirmedTxs(ctx context.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error)

func (JSONRpcClient) Validators

func (c JSONRpcClient) Validators(ctx context.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error)

type WSClient

type WSClient struct {
	Address  string // IP:PORT or /path/to/socket
	Endpoint string // /websocket/url/endpoint
	Header   http.Header
	Dialer   func(context.Context, 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, header http.Header, 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) 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) 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.

type WSEvents

type WSEvents struct {
	service.BaseService
	// contains filtered or unexported fields
}

WSEvents is a wrapper around WSClient, which implements EventsClient.

func (*WSEvents) OnStart

func (w *WSEvents) OnStart() error

OnStart implements service.Service by starting WSClient and event loop.

func (*WSEvents) OnStop

func (w *WSEvents) OnStop()

OnStop implements service.Service by stopping WSClient.

func (*WSEvents) Subscribe

func (w *WSEvents) Subscribe(ctx context.Context, subscriber, query string,
	outCapacity ...int) (out <-chan ctypes.ResultEvent, err error)

Subscribe implements EventsClient by using WSClient to subscribe given subscriber to query. By default, returns a channel with cap=1. Error is returned if it fails to subscribe.

Channel is never closed to prevent clients from seeing an erroneous event.

It returns an error if WSEvents is not running.

func (*WSEvents) Unsubscribe

func (w *WSEvents) Unsubscribe(ctx context.Context, subscriber, query string) error

Unsubscribe implements EventsClient by using WSClient to unsubscribe given subscriber from query.

It returns an error if WSEvents is not running.

func (*WSEvents) UnsubscribeAll

func (w *WSEvents) UnsubscribeAll(ctx context.Context, subscriber string) error

UnsubscribeAll implements EventsClient by using WSClient to unsubscribe given subscriber from all the queries.

It returns an error if WSEvents is not running.

Jump to

Keyboard shortcuts

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