rpc

package
v0.16.3-9-g27700aa2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2018 License: MPL-2.0 Imports: 10 Imported by: 30

README

rpc GoDoc

Package rpc - JSON-RPC client with custom routing.

Download:

go get github.com/status-im/status-go/rpc

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.


Automatically generated by autoreadme on 2017.09.18

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

Constants

View Source
const (
	// DefaultCallTimeout is a default timeout for an RPC call
	DefaultCallTimeout = time.Minute
)

Variables

View Source
var (
	ErrMethodNotFound = fmt.Errorf("The method does not exist/is not available")
)

List of RPC client errors.

Functions

func BlockedMethods

func BlockedMethods() []string

BlockedMethods returns a list of methods that are not allowed to be called. A copy of a slice is returned in order to prevent from changing it from outside.

Types

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

func NewClient(client *gethrpc.Client, upstream params.UpstreamRPCConfig) (*Client, error)

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

func (c *Client) Call(result interface{}, method string, args ...interface{}) error

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. If there are any local handlers registered for this call, they will handle it.

func (*Client) CallContextIgnoringLocalHandlers

func (c *Client) CallContextIgnoringLocalHandlers(ctx context.Context, result interface{}, method string, args ...interface{}) error

CallContextIgnoringLocalHandlers performs a JSON-RPC call with the given arguments.

If there are local handlers registered for this call, they would be ignored. It is useful if the call is happening from within a local handler itself. Upstream calls routing will be used anyway.

func (*Client) CallRaw

func (c *Client) CallRaw(body string) string

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

func (c *Client) RegisterHandler(method string, handler Handler)

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.

type Handler

type Handler func(context.Context, ...interface{}) (interface{}, error)

Handler defines handler for RPC methods.

Jump to

Keyboard shortcuts

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