rpcbackend

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	RPC
	SyncRequest(ctx context.Context, rpcReq *RPCRequest) (rpcRes *RPCResponse, err error)
}

Backend performs communication with a backend

func NewRPCClient

func NewRPCClient(client *resty.Client) Backend

NewRPCClient Constructor

func NewRPCClientWithOption added in v1.1.8

func NewRPCClientWithOption(client *resty.Client, options RPCClientOptions) Backend

NewRPCClientWithOption Constructor

type RPC added in v1.1.11

type RPC interface {
	CallRPC(ctx context.Context, result interface{}, method string, params ...interface{}) *RPCError
}

type RPCClient

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

func (*RPCClient) CallRPC

func (rc *RPCClient) CallRPC(ctx context.Context, result interface{}, method string, params ...interface{}) *RPCError

func (*RPCClient) SyncRequest

func (rc *RPCClient) SyncRequest(ctx context.Context, rpcReq *RPCRequest) (rpcRes *RPCResponse, err error)

SyncRequest sends an individual RPC request to the backend (always over HTTP currently), and waits synchronously for the response, or an error.

In all return paths *including error paths* the RPCResponse is populated so the caller has an RPC structure to send back to the front-end caller.

type RPCClientOptions added in v1.1.8

type RPCClientOptions struct {
	MaxConcurrentRequest int64
}

type RPCCode

type RPCCode int64
const (
	RPCCodeParseError     RPCCode = -32700
	RPCCodeInvalidRequest RPCCode = -32600
	RPCCodeInternalError  RPCCode = -32603
)

type RPCError

type RPCError struct {
	Code    int64           `json:"code"`
	Message string          `json:"message"`
	Data    fftypes.JSONAny `json:"data,omitempty"`
}

func NewRPCError added in v1.1.11

func NewRPCError(ctx context.Context, code RPCCode, msg i18n.ErrorMessageKey, inserts ...interface{}) *RPCError

func (*RPCError) Error added in v1.1.4

func (e *RPCError) Error() error

func (*RPCError) String added in v1.1.11

func (e *RPCError) String() string

type RPCRequest

type RPCRequest struct {
	JSONRpc string             `json:"jsonrpc"`
	ID      *fftypes.JSONAny   `json:"id"`
	Method  string             `json:"method"`
	Params  []*fftypes.JSONAny `json:"params,omitempty"`
}

type RPCResponse

type RPCResponse struct {
	JSONRpc string           `json:"jsonrpc"`
	ID      *fftypes.JSONAny `json:"id"`
	Result  *fftypes.JSONAny `json:"result,omitempty"`
	Error   *RPCError        `json:"error,omitempty"`
	// Only for subscription notifications
	Method string           `json:"method,omitempty"`
	Params *fftypes.JSONAny `json:"params,omitempty"`
}

func RPCErrorResponse

func RPCErrorResponse(err error, id *fftypes.JSONAny, code RPCCode) *RPCResponse

func (*RPCResponse) Message

func (r *RPCResponse) Message() string

type RPCSubscriptionNotification added in v1.1.11

type RPCSubscriptionNotification struct {
	CurrentSubID string // will change on each reconnect
	Result       *fftypes.JSONAny
}

type Subscription added in v1.1.11

type Subscription interface {
	LocalID() *fftypes.UUID // does not change through reconnects
	Notifications() chan *RPCSubscriptionNotification
	Unsubscribe(ctx context.Context) *RPCError
}

type WebSocketRPCClient added in v1.1.11

type WebSocketRPCClient interface {
	RPC
	Subscribe(ctx context.Context, params ...interface{}) (sub Subscription, error *RPCError)
	Subscriptions() []Subscription
	UnsubscribeAll(ctx context.Context) (error *RPCError)
	Connect(ctx context.Context) error
	Close()
}

WebSocketRPCClient performs communication over a websocket with an Ethereum JSON/RPC endpoint

- Manages websocket connect/reconnect with keepalive etc. - Manages subscriptions with a local ID, so they re-established automatically after reconnect - Allows synchronous exchange over the WebSocket so you don't have to maintain a separate HTTP connection too

func NewWSRPCClient added in v1.1.11

func NewWSRPCClient(wsConf *wsclient.WSConfig) WebSocketRPCClient

NewRPCClient Constructor

Jump to

Keyboard shortcuts

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