http

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

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) 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) Count

func (b *BatchHTTP) Count() int

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

func (BatchHTTP) GenesisChunked

func (c BatchHTTP) GenesisChunked(ctx context.Context, id uint) (*ctypes.ResultGenesisChunk, error)

func (BatchHTTP) Health

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

func (BatchHTTP) NetInfo

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

func (BatchHTTP) QueryRequest

func (c BatchHTTP) QueryRequest(ctx context.Context, hash string) (*ctypes.ResultDvsRequest, error)

func (BatchHTTP) RequestDVS

func (c BatchHTTP) RequestDVS(
	ctx context.Context,
	data []byte,
	height int64,
	chainid int64,
	groupNumbers []uint32,
	groupThresholdPercentages []uint32,
) (*ctypes.ResultRequest, error)

func (BatchHTTP) RequestDVSAsync

func (c BatchHTTP) RequestDVSAsync(
	ctx context.Context,
	data []byte,
	height int64,
	chainid int64,
	groupNumbers []uint32,
	groupThresholdPercentages []uint32,
) (*ctypes.ResultRequestDvsAsync, error)

func (BatchHTTP) SearchRequest added in v0.3.0

func (c BatchHTTP) SearchRequest(ctx context.Context, query string, pagePtr, perPagePtr *int) (*ctypes.ResultDvsRequestSearch, error)

func (*BatchHTTP) Send

func (b *BatchHTTP) Send(ctx context.Context) ([]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.

type HTTP

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

HTTP is a Client implementation that communicates with a PellDVS 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 PellDVS 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 PellDVS using Subscribe method. Note delivery is best-effort. If you don't read events fast enough or network is slow, PellDVS 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) GenesisChunked

func (c HTTP) GenesisChunked(ctx context.Context, id uint) (*ctypes.ResultGenesisChunk, error)

func (HTTP) Health

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

func (HTTP) NetInfo

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

func (*HTTP) NewBatch

func (c *HTTP) NewBatch() *BatchHTTP

NewBatch creates a new batch client for this HTTP client.

func (HTTP) QueryRequest

func (c HTTP) QueryRequest(ctx context.Context, hash string) (*ctypes.ResultDvsRequest, error)

func (*HTTP) Remote

func (c *HTTP) Remote() string

Remote returns the remote network address in a string form.

func (HTTP) RequestDVS

func (c HTTP) RequestDVS(
	ctx context.Context,
	data []byte,
	height int64,
	chainid int64,
	groupNumbers []uint32,
	groupThresholdPercentages []uint32,
) (*ctypes.ResultRequest, error)

func (HTTP) RequestDVSAsync

func (c HTTP) RequestDVSAsync(
	ctx context.Context,
	data []byte,
	height int64,
	chainid int64,
	groupNumbers []uint32,
	groupThresholdPercentages []uint32,
) (*ctypes.ResultRequestDvsAsync, error)

func (HTTP) SearchRequest added in v0.3.0

func (c HTTP) SearchRequest(ctx context.Context, query string, pagePtr, perPagePtr *int) (*ctypes.ResultDvsRequestSearch, error)

Jump to

Keyboard shortcuts

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