Documentation ¶
Index ¶
- func DefaultHTTPClient(remoteAddr string) (*http.Client, error)
- func MaxReconnectAttempts(max int) func(*WSClient)
- func OnReconnect(cb func()) func(*WSClient)
- func PingPeriod(pingPeriod time.Duration) func(*WSClient)
- func ReadWait(readWait time.Duration) func(*WSClient)
- func WriteWait(writeWait time.Duration) func(*WSClient)
- type JSONRpcClient
- func (c JSONRpcClient) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error)
- func (c JSONRpcClient) ABCIQuery(ctx context.Context, path string, data tmbytes.HexBytes) (*ctypes.ResultABCIQuery, error)
- func (c JSONRpcClient) ABCIQueryWithOptions(ctx context.Context, path string, data tmbytes.HexBytes, ...) (*ctypes.ResultABCIQuery, error)
- func (c JSONRpcClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error)
- func (c JSONRpcClient) BlockByHash(ctx context.Context, hash []byte) (*ctypes.ResultBlock, error)
- func (c JSONRpcClient) BlockResults(ctx context.Context, height *int64) (*ctypes.ResultBlockResults, error)
- func (c JSONRpcClient) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
- func (c JSONRpcClient) BroadcastEvidence(ctx context.Context, ev tmtypes.Evidence) (*ctypes.ResultBroadcastEvidence, error)
- func (c JSONRpcClient) BroadcastTxAsync(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultBroadcastTx, error)
- func (c JSONRpcClient) BroadcastTxCommit(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultBroadcastTxCommit, error)
- func (c JSONRpcClient) BroadcastTxSync(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultBroadcastTx, error)
- func (c *JSONRpcClient) Call(ctx context.Context, method string, params map[string]interface{}, ...) (interface{}, error)
- func (c JSONRpcClient) CheckTx(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultCheckTx, error)
- func (c JSONRpcClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error)
- func (c JSONRpcClient) ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error)
- func (c JSONRpcClient) ConsensusState(ctx context.Context) (*ctypes.ResultConsensusState, error)
- func (c *JSONRpcClient) Do(req *http.Request) (*http.Response, error)
- func (c JSONRpcClient) DumpConsensusState(ctx context.Context) (*ctypes.ResultDumpConsensusState, error)
- func (c JSONRpcClient) Genesis(ctx context.Context) (*ctypes.ResultGenesis, error)
- func (c JSONRpcClient) Health(ctx context.Context) (*ctypes.ResultHealth, error)
- func (c JSONRpcClient) NetInfo(ctx context.Context) (*ctypes.ResultNetInfo, error)
- func (c JSONRpcClient) NumUnconfirmedTxs(ctx context.Context) (*ctypes.ResultUnconfirmedTxs, error)
- func (c JSONRpcClient) Quit() <-chan struct{}
- func (c JSONRpcClient) SetLogger(logger log.Logger)
- func (c JSONRpcClient) Status(ctx context.Context) (*ctypes.ResultStatus, error)
- func (c JSONRpcClient) String() string
- func (c JSONRpcClient) Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.ResultTx, error)
- func (c JSONRpcClient) TxSearch(ctx context.Context, query string, prove bool, page, perPage *int, ...) (*ctypes.ResultTxSearch, error)
- func (c JSONRpcClient) UnconfirmedTxs(ctx context.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error)
- func (c JSONRpcClient) Validators(ctx context.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error)
- type WSClient
- func (c *WSClient) Call(ctx context.Context, method string, params map[string]interface{}) error
- func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error
- func (c *WSClient) IsActive() bool
- func (c *WSClient) IsReconnecting() bool
- func (c *WSClient) OnStart() error
- func (c *WSClient) Send(ctx context.Context, request types.RPCRequest) error
- func (c *WSClient) Stop() error
- func (c *WSClient) String() string
- func (c *WSClient) Subscribe(ctx context.Context, query string) error
- func (c *WSClient) Unsubscribe(ctx context.Context, query string) error
- func (c *WSClient) UnsubscribeAll(ctx context.Context) error
- type WSEvents
- func (w *WSEvents) OnStart() error
- func (w *WSEvents) OnStop()
- func (w *WSEvents) Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan ctypes.ResultEvent, err error)
- func (w *WSEvents) Unsubscribe(ctx context.Context, subscriber, query string) error
- func (w *WSEvents) UnsubscribeAll(ctx context.Context, subscriber string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultHTTPClient ¶
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 ¶
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 ¶
PingPeriod sets the duration for sending websocket pings. It should only be used in the constructor - not Goroutine-safe.
Types ¶
type JSONRpcClient ¶
type JSONRpcClient struct { *WSEvents // contains filtered or unexported fields }
func NewJSONRpcClient ¶
func (JSONRpcClient) ABCIInfo ¶
func (c JSONRpcClient) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error)
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 (c JSONRpcClient) BroadcastEvidence(ctx context.Context, ev tmtypes.Evidence) (*ctypes.ResultBroadcastEvidence, error)
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) CheckTx ¶
func (c JSONRpcClient) CheckTx(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultCheckTx, error)
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) DumpConsensusState ¶
func (c JSONRpcClient) DumpConsensusState(ctx context.Context) (*ctypes.ResultDumpConsensusState, error)
func (JSONRpcClient) Genesis ¶
func (c JSONRpcClient) Genesis(ctx context.Context) (*ctypes.ResultGenesis, error)
func (JSONRpcClient) Health ¶
func (c JSONRpcClient) Health(ctx context.Context) (*ctypes.ResultHealth, error)
func (JSONRpcClient) NetInfo ¶
func (c JSONRpcClient) NetInfo(ctx context.Context) (*ctypes.ResultNetInfo, error)
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 (c JSONRpcClient) Status(ctx context.Context) (*ctypes.ResultStatus, error)
func (JSONRpcClient) String ¶
func (c JSONRpcClient) String() string
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 ¶
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) IsReconnecting ¶
IsReconnecting returns true if the client is reconnecting right now.
func (*WSClient) OnStart ¶
OnStart implements service.Service by dialing a server and creating read and write routines.
func (*WSClient) Send ¶
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 ¶
Stop overrides service.Service#Stop. There is no other way to wait until Quit channel is closed.
func (*WSClient) Subscribe ¶
Subscribe to a query. Note the server must have a "subscribe" route defined.
func (*WSClient) Unsubscribe ¶
Unsubscribe from a query. Note the server must have a "unsubscribe" 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) 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 ¶
Unsubscribe implements EventsClient by using WSClient to unsubscribe given subscriber from query.
It returns an error if WSEvents is not running.