rpcbackend

package
v0.9.20 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	CallRPC(ctx context.Context, result interface{}, method string, params ...interface{}) error
	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

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{}) error

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 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"`
}

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"`
}

func RPCErrorResponse

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

func (*RPCResponse) Message

func (r *RPCResponse) Message() string

Jump to

Keyboard shortcuts

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