jsonrpc

package
v0.0.0-...-ae8e89f Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Options(
	fx.Provide(New),
)

Functions

func IsNullOrEmpty

func IsNullOrEmpty(r json.RawMessage) bool

Types

type Client

type Client interface {
	Call(ctx context.Context, method *RequestMethod, params Params, opts ...Option) (*Response, error)
	BatchCall(ctx context.Context, method *RequestMethod, batchParams []Params, opts ...Option) ([]*Response, error)
}

type ClientParams

type ClientParams struct {
	fx.In
	fxparams.Params
	Master     endpoints.EndpointProvider `name:"master"`
	Slave      endpoints.EndpointProvider `name:"slave"`
	Validator  endpoints.EndpointProvider `name:"validator"`
	Consensus  endpoints.EndpointProvider `name:"consensus"`
	HTTPClient HTTPClient                 `optional:"true"` // Injected by unit test.
}

type ClientResult

type ClientResult struct {
	fx.Out
	Master    Client `name:"master"`
	Slave     Client `name:"slave"`
	Validator Client `name:"validator"`
	Consensus Client `name:"consensus"`
}

func New

func New(params ClientParams) (ClientResult, error)

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type HTTPError

type HTTPError struct {
	Code     int
	Response string
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Option

type Option func(opts *options)

func WithAllowsRPCError

func WithAllowsRPCError() Option

type Params

type Params []any

type RPCError

type RPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data"`
}

func (*RPCError) Error

func (e *RPCError) Error() string

type Request

type Request struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	Params  any    `json:"params,omitempty"`
	ID      uint   `json:"id"`
}

type RequestMethod

type RequestMethod struct {
	Name    string
	Timeout time.Duration
}

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RPCError       `json:"error,omitempty"`
	ID      uint            `json:"id"`
}

func (*Response) Unmarshal

func (r *Response) Unmarshal(out any) error

Directories

Path Synopsis
Package jsonrpcmocks is a generated GoMock package.
Package jsonrpcmocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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