jsonrpc2

package
v0.7.1-ccip Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: MIT Imports: 3 Imported by: 25

Documentation

Index

Constants

View Source
const (
	JsonRpcVersion = "2.0"

	// ErrUnknown should be used for all non-coded errors.
	ErrUnknown int64 = -32001

	// ErrParse is used when invalid JSON was received by the server.
	ErrParse int64 = -32700

	//ErrInvalidRequest is used when the JSON sent is not a valid Request object.
	ErrInvalidRequest int64 = -32600

	// ErrMethodNotFound should be returned by the handler when the method does
	// not exist / is not available.
	ErrMethodNotFound int64 = -32601

	// ErrInvalidParams should be returned by the handler when method
	// parameter(s) were invalid.
	ErrInvalidParams int64 = -32602

	// ErrInternal is not currently returned but defined for completeness.
	ErrInternal int64 = -32603

	//ErrServerOverloaded is returned when a message was refused due to a
	//server being temporarily unable to accept any new messages.
	ErrServerOverloaded int64 = -32000
)

Variables

This section is empty.

Functions

func EncodeErrorReponse

func EncodeErrorReponse(id string, err *WireError) ([]byte, error)

func EncodeRequest

func EncodeRequest(request *Request) ([]byte, error)

func EncodeResponse

func EncodeResponse(response *Response) ([]byte, error)

Types

type Request

type Request struct {
	Version string          `json:"jsonrpc"`
	ID      string          `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
	// Auth is used to store the JWT token for the request. It is not part of the JSON RPC specification.
	// JWT token can be part of the request payload or attached to the request header.
	Auth string `json:"auth,omitempty"`
}

Wrapping/unwrapping Message objects into JSON RPC ones folllowing https://www.jsonrpc.org/specification

func DecodeRequest

func DecodeRequest(requestBytes []byte, jwtTokenFromHeader string) (Request, error)

func (*Request) ServiceName

func (r *Request) ServiceName() string

type Response

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

func DecodeResponse

func DecodeResponse(responseBytes []byte) (Response, error)

type WireError

type WireError struct {
	// Code is an error code indicating the type of failure.
	Code int64 `json:"code"`
	// The Message is a short description of the error.
	Message string `json:"message"`
	// Data is optional structured data containing additional information about the error.
	Data *json.RawMessage `json:"data,omitempty"`
}

WireError represents a structured error in a Response.

func (*WireError) Error

func (w *WireError) Error() string

Jump to

Keyboard shortcuts

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