Documentation ¶
Overview ¶
Package rpc - JSON-RPC client with custom routing.
Package rpc implements status-go JSON-RPC client and handles requests to different endpoints: upstream or local node.
Every JSON-RPC request coming from either JS code or any other part of status-go should use this package to be handled and routed properly.
Routing rules are following:
- if Upstream is disabled, everything is routed to local ethereum-go node - otherwise, some requests (from the list, see below) are routed to upstream, others - locally.
List of methods to be routed is currently available here: https://docs.google.com/spreadsheets/d/1N1nuzVN5tXoDmzkBLeC9_mwIlVH8DGF7YD2XwxA8BAE/edit#gid=0
Note, upon creation of a new client, it ok to be offline - client will keep trying to reconnect in background.
Index ¶
- Variables
- type Call
- func (c Call) ParseData() hexutil.Bytes
- func (c Call) ParseFromAddress() (gethcommon.Address, error)
- func (c Call) ParseGas() *hexutil.Uint64
- func (c Call) ParseGasPrice() *hexutil.Big
- func (c Call) ParseInput() hexutil.Bytes
- func (c Call) ParseToAddress() (gethcommon.Address, error)
- func (c Call) ParseValue() *hexutil.Big
- type Client
- func (c *Client) Call(result interface{}, method string, args ...interface{}) error
- func (c *Client) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
- func (c *Client) CallRaw(body string) string
- func (c *Client) RegisterHandler(method string, handler Handler)
- type Handler
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidFromAddress = errors.New("Failed to parse From Address") ErrInvalidToAddress = errors.New("Failed to parse To Address") )
contains series of errors for parsing operations.
Functions ¶
This section is empty.
Types ¶
type Call ¶
Call represents a unit of a rpc request which is to be executed.
func (Call) ParseData ¶
ParseData returns the bytes associated with the call in the deprecated "data" field.
func (Call) ParseFromAddress ¶
func (c Call) ParseFromAddress() (gethcommon.Address, error)
ParseFromAddress returns the address associated with the Call.
func (Call) ParseGasPrice ¶
ParseGasPrice returns the hex big associated with the call. nolint: dupl
func (Call) ParseInput ¶
ParseInput returns the bytes associated with the call.
func (Call) ParseToAddress ¶
func (c Call) ParseToAddress() (gethcommon.Address, error)
ParseToAddress returns the gethcommon.Address associated with the call.
func (Call) ParseValue ¶
ParseValue returns the hex big associated with the call. nolint: dupl
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents RPC client with custom routing scheme. It automatically decides where RPC call goes - Upstream or Local node.
func NewClient ¶
NewClient initializes Client and tries to connect to both, upstream and local node.
Client is safe for concurrent use and will automatically reconnect to the server if connection is lost.
func (*Client) Call ¶
Call performs a JSON-RPC call with the given arguments and unmarshals into result if no error occurred.
The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.
It uses custom routing scheme for calls.
func (*Client) CallContext ¶
func (c *Client) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
CallContext performs a JSON-RPC call with the given arguments. If the context is canceled before the call has successfully returned, CallContext returns immediately.
The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.
It uses custom routing scheme for calls.
func (*Client) CallRaw ¶
CallRaw performs a JSON-RPC call with already crafted JSON-RPC body. It returns string in JSON format with response (successul or error).
func (*Client) RegisterHandler ¶
RegisterHandler registers local handler for specific RPC method.
If method is registered, it will be executed with given handler and never routed to the upstream or local servers.