rpc

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: AGPL-3.0 Imports: 12 Imported by: 8

Documentation

Index

Constants

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

Bytom-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
	Username     string
	BuildTag     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 Bytom 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