http

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: Apache-2.0, Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchHTTP

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

BatchHTTP provides the same interface as `HTTP`, but allows for batching of requests (as per https://www.jsonrpc.org/specification#batch). Do not instantiate directly - rather use the HTTP.NewBatch() method to create an instance of this struct.

Batching of HTTP requests is thread-safe in the sense that multiple goroutines can each create their own batches and send them using the same HTTP client. Multiple goroutines could also enqueue transactions in a single batch, but ordering of transactions in the batch cannot be guaranteed in such an example.

func (BatchHTTP) ABCIInfo

func (c BatchHTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error)

func (BatchHTTP) ABCIQuery

func (c BatchHTTP) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error)

func (BatchHTTP) ABCIQueryWithOptions

func (c BatchHTTP) ABCIQueryWithOptions(
	path string,
	data bytes.HexBytes,
	opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)

func (BatchHTTP) Block

func (c BatchHTTP) Block(height *int64) (*ctypes.ResultBlock, error)

func (BatchHTTP) BlockResults

func (c BatchHTTP) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)

func (BatchHTTP) BlockchainInfo

func (c BatchHTTP) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)

func (BatchHTTP) BroadcastEvidence

func (c BatchHTTP) BroadcastEvidence(ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error)

func (BatchHTTP) BroadcastTxAsync

func (c BatchHTTP) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)

func (BatchHTTP) BroadcastTxCommit

func (c BatchHTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)

func (BatchHTTP) BroadcastTxSync

func (c BatchHTTP) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)

func (*BatchHTTP) Clear

func (b *BatchHTTP) Clear() int

Clear will empty out this batch of requests and return the number of requests that were cleared out.

func (BatchHTTP) Commit

func (c BatchHTTP) Commit(height *int64) (*ctypes.ResultCommit, error)

func (BatchHTTP) ConsensusParams

func (c BatchHTTP) ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error)

func (BatchHTTP) ConsensusState

func (c BatchHTTP) ConsensusState() (*ctypes.ResultConsensusState, error)

func (*BatchHTTP) Count

func (b *BatchHTTP) Count() int

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

func (BatchHTTP) DumpConsensusState

func (c BatchHTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)

func (BatchHTTP) Genesis

func (c BatchHTTP) Genesis() (*ctypes.ResultGenesis, error)

func (BatchHTTP) GetAddressList

func (c BatchHTTP) GetAddressList() (*ctypes.ResultUnconfirmedAddresses, error)

func (BatchHTTP) Health

func (c BatchHTTP) Health() (*ctypes.ResultHealth, error)

func (BatchHTTP) NetInfo

func (c BatchHTTP) NetInfo() (*ctypes.ResultNetInfo, error)

func (BatchHTTP) NumUnconfirmedTxs

func (c BatchHTTP) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)

func (*BatchHTTP) Send

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

Send is a convenience function for an HTTP batch that will trigger the compilation of the batched requests and send them off using the client as a single request. On success, this returns a list of the deserialized results from each request in the sent batch.

func (BatchHTTP) Status

func (c BatchHTTP) Status() (*ctypes.ResultStatus, error)

func (BatchHTTP) Tx

func (c BatchHTTP) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)

func (BatchHTTP) TxSearch

func (c BatchHTTP) TxSearch(query string, prove bool, page, perPage int, orderBy string) (
	*ctypes.ResultTxSearch, error)

func (BatchHTTP) UnconfirmedTxs

func (c BatchHTTP) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)

func (BatchHTTP) UserNumUnconfirmedTxs

func (c BatchHTTP) UserNumUnconfirmedTxs(address string) (*ctypes.ResultUserUnconfirmedTxs, error)

func (BatchHTTP) UserUnconfirmedTxs

func (c BatchHTTP) UserUnconfirmedTxs(address string, limit int) (*ctypes.ResultUserUnconfirmedTxs, error)

func (BatchHTTP) Validators

func (c BatchHTTP) Validators(height *int64, page, perPage int) (*ctypes.ResultValidators, error)

type HTTP

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

HTTP is a Client implementation that communicates with a Tendermint node over JSON RPC and WebSockets.

This is the main implementation you probably want to use in production code. There are other implementations when calling the Tendermint node in-process (Local), or when you want to mock out the server for test code (mock).

You can subscribe for any event published by Tendermint using Subscribe method. Note delivery is best-effort. If you don't read events fast enough or network is slow, Tendermint might cancel the subscription. The client will attempt to resubscribe (you don't need to do anything). It will keep trying every second indefinitely until successful.

Request batching is available for JSON RPC requests over HTTP, which conforms to the JSON RPC specification (https://www.jsonrpc.org/specification#batch). See the example for more details.

Example:

c, err := New("http://192.168.1.10:26657", "/websocket")
if err != nil {
	// handle error
}

// call Start/Stop if you're subscribing to events
err = c.Start()
if err != nil {
	// handle error
}
defer c.Stop()

res, err := c.Status()
if err != nil {
	// handle error
}

// handle result

func New

func New(remote, wsEndpoint string) (*HTTP, error)

New takes a remote endpoint in the form <protocol>://<host>:<port> and the websocket path (which always seems to be "/websocket") An error is returned on invalid remote. The function panics when remote is nil.

func NewWithClient

func NewWithClient(remote, wsEndpoint string, client *http.Client) (*HTTP, error)

NewWithClient allows for setting a custom http client (See New). An error is returned on invalid remote. The function panics when remote is nil.

func NewWithTimeout

func NewWithTimeout(remote, wsEndpoint string, timeout uint) (*HTTP, error)

Create timeout enabled http client

func (HTTP) ABCIInfo

func (c HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error)

func (HTTP) ABCIQuery

func (c HTTP) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error)

func (HTTP) ABCIQueryWithOptions

func (c HTTP) ABCIQueryWithOptions(
	path string,
	data bytes.HexBytes,
	opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)

func (HTTP) Block

func (c HTTP) Block(height *int64) (*ctypes.ResultBlock, error)

func (HTTP) BlockResults

func (c HTTP) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)

func (HTTP) BlockchainInfo

func (c HTTP) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)

func (HTTP) BroadcastEvidence

func (c HTTP) BroadcastEvidence(ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error)

func (HTTP) BroadcastTxAsync

func (c HTTP) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)

func (HTTP) BroadcastTxCommit

func (c HTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)

func (HTTP) BroadcastTxSync

func (c HTTP) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)

func (HTTP) Commit

func (c HTTP) Commit(height *int64) (*ctypes.ResultCommit, error)

func (HTTP) ConsensusParams

func (c HTTP) ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error)

func (HTTP) ConsensusState

func (c HTTP) ConsensusState() (*ctypes.ResultConsensusState, error)

func (HTTP) DumpConsensusState

func (c HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)

func (HTTP) Genesis

func (c HTTP) Genesis() (*ctypes.ResultGenesis, error)

func (HTTP) GetAddressList

func (c HTTP) GetAddressList() (*ctypes.ResultUnconfirmedAddresses, error)

func (*HTTP) GetUnconfirmedTxByHash

func (c *HTTP) GetUnconfirmedTxByHash(hash [sha256.Size]byte) (types.Tx, error)

func (HTTP) Health

func (c HTTP) Health() (*ctypes.ResultHealth, error)

func (HTTP) NetInfo

func (c HTTP) NetInfo() (*ctypes.ResultNetInfo, error)

func (*HTTP) NewBatch

func (c *HTTP) NewBatch() *BatchHTTP

NewBatch creates a new batch client for this HTTP client.

func (HTTP) NumUnconfirmedTxs

func (c HTTP) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)

func (*HTTP) Remote

func (c *HTTP) Remote() string

Remote returns the remote network address in a string form.

func (*HTTP) SetLogger

func (c *HTTP) SetLogger(l log.Logger)

SetLogger sets a logger.

func (HTTP) Status

func (c HTTP) Status() (*ctypes.ResultStatus, error)

func (HTTP) Tx

func (c HTTP) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)

func (HTTP) TxSearch

func (c HTTP) TxSearch(query string, prove bool, page, perPage int, orderBy string) (
	*ctypes.ResultTxSearch, error)

func (HTTP) UnconfirmedTxs

func (c HTTP) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)

func (HTTP) UserNumUnconfirmedTxs

func (c HTTP) UserNumUnconfirmedTxs(address string) (*ctypes.ResultUserUnconfirmedTxs, error)

func (HTTP) UserUnconfirmedTxs

func (c HTTP) UserUnconfirmedTxs(address string, limit int) (*ctypes.ResultUserUnconfirmedTxs, error)

func (HTTP) Validators

func (c HTTP) Validators(height *int64, page, perPage int) (*ctypes.ResultValidators, error)

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