jsonrpc

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JSONRPCAppError indicates an application error
	JSONRPCAppError = -32001

	// JSONRPCParseError indicates an unparseable request
	JSONRPCParseError = -32700

	// JSONRPCInvalidReq indicates an invalid request
	JSONRPCInvalidReq = -32600

	// JSONRPCMethodNotFound indicates the requested method is unknown
	JSONRPCMethodNotFound = -32601

	// JSONRPCInvalidParams indicates the provided params are not valid
	JSONRPCInvalidParams = -32602

	// JSONRPCInternalError indicates an internal server error
	JSONRPCInternalError = -32603
)
View Source
const (
	// MethodSeparator is used to in the method name to split the microservice name and desired method to run
	MethodSeparator = "."

	// MethodSections defines the number of sections in the JSON RPC method
	MethodSections = 2

	// MaxMethodNamespaces defines the maximum allowed number of qualified namespaces
	MaxMethodNamespaces = 3

	// MaxMessageSize defines the maximum amount of bytes an AMQP message can be
	MaxMessageSize = 536870912

	// QualifiedNamePrefix is the prefix of all fully qualified rpc methods
	QualifiedNamePrefix = "koinos.rpc."
)

Variables

View Source
var (
	// ErrMalformedMethod indicates the method was not properly formed
	ErrMalformedMethod = errors.New("methods should be in the format service_name.method_name")

	// ErrInvalidService indicates the correct ServiceName was not supplied
	ErrInvalidService = errors.New("invalid service name provided")

	// ErrUnknownMethod indicates the method is not known
	ErrUnknownMethod = errors.New("unknown method")

	// ErrInvalidParams indicates the parameters could not be parsed
	ErrInvalidParams = errors.New("parameters could not be parsed")

	// ErrInvalidJSONRPCVersion indicates an improper JSON RPC version was specified
	ErrInvalidJSONRPCVersion = errors.New("invalid or missing JSON RPC version was specified")

	// ErrInvalidJSONRPCID indicates an invalid JSON RPC ID was provided
	ErrInvalidJSONRPCID = errors.New("invalid ID was specified")

	// ErrMissingJSONRPCID indicates the ID does not exist
	ErrMissingJSONRPCID = errors.New("missing ID")

	// ErrFractionalJSONRPCID indicates a fractional number was identified as the ID
	ErrFractionalJSONRPCID = errors.New("ID must not contain fractional parts")

	// ErrUnsupportedJSONRPCIDType indicates an ID type that is unsupported
	ErrUnsupportedJSONRPCIDType = errors.New("an ID must be a Number (non-fractional), String, or Null")

	// ErrUnexpectedResponse indicates a malformed RPC response
	ErrUnexpectedResponse = errors.New("unexpected RPC response from microservice")

	// ErrMethodNotWhitelisted indicates the requested method is not on the whitelist
	ErrMethodNotWhitelisted = errors.New("method not whitelisted")

	// ErrMethodBlacklisted indicates the requested method is on the blacklist
	ErrMethodBlacklisted = errors.New("method blacklisted")
)

Functions

This section is empty.

Types

type RPCError

type RPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

RPCError represents a JSON RPC error

type RPCRequest added in v0.2.0

type RPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	ID      json.RawMessage `json:"id"`
	Params  json.RawMessage `json:"params"`
}

The RPCRequest allows for parsing incoming JSON RPC while deferring the parsing of the params

type RPCResponse

type RPCResponse struct {
	JSONRPC string          `json:"jsonrpc"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   interface{}     `json:"error,omitempty"`
	ID      interface{}     `json:"id"`
}

RPCResponse represents a JSON RPC response

type RequestHandler added in v0.2.0

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

RequestHandler handles jsonrpc requests

func NewRequestHandler added in v0.2.0

func NewRequestHandler(client *koinosmq.Client, timeout uint, whitelist []string, blacklist []string) *RequestHandler

NewRequestHandler returns a new RequestHandler

func (*RequestHandler) HandleRequest added in v0.2.0

func (h *RequestHandler) HandleRequest(reqBytes []byte) ([]byte, bool)

HandleRequest handles a jsonrpc request, returning the results as a byte string Any error that occurs will be returned in an error response instead of propagating to the caller If ok = false is retured, it means the client cannot recover from this error and the caller should close the connection

func (*RequestHandler) RegisterService added in v0.2.0

func (h *RequestHandler) RegisterService(fd protoreflect.FileDescriptor)

RegisterService from a FileDescriptor

Jump to

Keyboard shortcuts

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