Documentation
¶
Index ¶
- type Backend
- type BatchRPC
- type RPC
- type RPCBatchOp
- type RPCBatchOpTyped
- type RPCClient
- func (rc *RPCClient) CallRPC(ctx context.Context, result interface{}, method string, params ...interface{}) *RPCError
- func (rc *RPCClient) CallRPCBatch(ctx context.Context, ops ...*RPCBatchOp) []*RPCError
- func (rc *RPCClient) SyncRequest(ctx context.Context, rpcReq *RPCRequest) (*RPCResponse, error)
- type RPCClientOptions
- type RPCCode
- type RPCError
- func CallRPCBatchTyped[T any](ctx context.Context, rc *RPCClient, ops ...*RPCBatchOpTyped[T]) []*RPCError
- func CallRPCTyped[T any](ctx context.Context, rc *RPCClient, result *T, method string, ...) *RPCError
- func NewRPCError(ctx context.Context, code RPCCode, msg i18n.ErrorMessageKey, ...) *RPCError
- type RPCRequest
- type RPCResponse
- type RPCResponseTyped
- type RPCSubscriptionNotification
- type Subscription
- type WebSocketRPCClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
BatchRPC
SyncRequest(ctx context.Context, rpcReq *RPCRequest) (rpcRes *RPCResponse, err error)
}
Backend performs communication with a backend
func NewRPCClientWithOption ¶
func NewRPCClientWithOption(client *resty.Client, options RPCClientOptions) Backend
NewRPCClientWithOption Constructor
type BatchRPC ¶
type BatchRPC interface {
RPC
CallRPCBatch(ctx context.Context, ops ...*RPCBatchOp) []*RPCError
}
type RPCBatchOp ¶
type RPCBatchOp struct {
Result interface{}
Method string
Params []interface{}
}
RPCBatchOp holds the method, params, and result destination for one call within a batch.
type RPCBatchOpTyped ¶
RPCBatchOpTyped is the typed equivalent of RPCBatchOp for use with CallRPCBatchTyped. All ops in a typed batch must share the same result type T.
type RPCClient ¶
type RPCClient struct {
// contains filtered or unexported fields
}
func (*RPCClient) CallRPCBatch ¶
func (rc *RPCClient) CallRPCBatch(ctx context.Context, ops ...*RPCBatchOp) []*RPCError
func (*RPCClient) SyncRequest ¶
func (rc *RPCClient) SyncRequest(ctx context.Context, rpcReq *RPCRequest) (*RPCResponse, 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 ¶
type RPCClientOptions struct {
MaxConcurrentRequest int64
}
type RPCError ¶
type RPCError struct {
Code int64 `json:"code"`
Message string `json:"message"`
Data fftypes.JSONAny `json:"data,omitempty"`
}
func CallRPCBatchTyped ¶
func CallRPCBatchTyped[T any](ctx context.Context, rc *RPCClient, ops ...*RPCBatchOpTyped[T]) []*RPCError
CallRPCBatchTyped sends a JSON-RPC batch where every operation decodes its result directly into T, bypassing the fftypes.JSONAny intermediate used by CallRPCBatch. All ops in the batch must share the same result type.
func CallRPCTyped ¶
func CallRPCTyped[T any](ctx context.Context, rc *RPCClient, result *T, method string, params ...interface{}) *RPCError
CallRPCTyped performs a single JSON-RPC call and decodes the result directly into T. More efficient than parsing into generic JSON bytes result structure first.
func NewRPCError ¶
type RPCRequest ¶
type RPCResponse ¶
type RPCResponse = RPCResponseTyped[*fftypes.JSONAny]
RPCResponse is the standard JSON-RPC response type, where Result is captured as raw bytes in a fftypes.JSONAny for a second json.Unmarshal by the caller.
func RPCErrorResponse ¶
func RPCErrorResponse(err error, id *fftypes.JSONAny, code RPCCode) *RPCResponse
type RPCResponseTyped ¶
type RPCResponseTyped[T any] struct { JSONRpc string `json:"jsonrpc"` ID *fftypes.JSONAny `json:"id"` Result T `json:"result,omitempty"` Error *RPCError `json:"error,omitempty"` // Only for subscription notifications Method string `json:"method,omitempty"` Params *fftypes.JSONAny `json:"params,omitempty"` }
RPCResponseTyped is a JSON-RPC response envelope that decodes Result directly into T, bypassing the fftypes.JSONAny intermediate used by RPCResponse.
func (*RPCResponseTyped[T]) Message ¶
func (r *RPCResponseTyped[T]) Message() string
type Subscription ¶
type WebSocketRPCClient ¶
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 ¶
func NewWSRPCClient(wsConf *wsclient.WSConfig) WebSocketRPCClient
NewRPCClient Constructor