rpc

package
v0.0.0-...-6d4bf48 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package rpc implements Chain Core's RPC client.

Index

Constants

View Source
const (
	HeaderBlockchainID = "Blockchain-ID"
	HeaderCoreID       = "Chain-Core-ID"
	HeaderTimeout      = "RPC-Timeout"
)

Chain-specific header fields

Variables

View Source
var ErrWrongNetwork = errors.New("connected to a peer on a different network")

ErrWrongNetwork is returned when a peer's blockchain ID differs from the RPC client's blockchain ID.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL      string
	AccessToken  string
	ProcessID    string
	Version      string
	BlockchainID string
	CoreID       string

	// If set, Client is used for outgoing requests.
	// TODO(kr): make this required (crash on nil)
	Client *http.Client
}

A Client is a Chain RPC client. It performs RPCs over HTTP using JSON request and responses. A Client must be configured with a secret token to authenticate with other Cores on the network.

func (*Client) Call

func (c *Client) Call(ctx context.Context, path string, request, response interface{}) error

Call calls a remote procedure on another node, specified by the path.

func (*Client) CallRaw

func (c *Client) CallRaw(ctx context.Context, path string, request interface{}) (io.ReadCloser, error)

CallRaw calls a remote procedure on another node, specified by the path. It returns a io.ReadCloser of the raw response body.

type ErrStatusCode

type ErrStatusCode struct {
	URL        string
	StatusCode int
	ErrorData  *httperror.Response
}

ErrStatusCode is an error returned when an rpc fails with a non-200 response code.

func (ErrStatusCode) Error

func (e ErrStatusCode) Error() string

Jump to

Keyboard shortcuts

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