jsonrpcserver

package
v0.0.0-...-d1bef67 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package jsonrpcserver allows exposing functions like: func Foo(context, int) (int, error) as a JSON RPC methods

This implementation is similar to the one in go-ethereum, but the idea is to eventually replace it as a default JSON RPC server implementation in Flasbhots projects and for this we need to reimplement some of the quirks of existing API.

Index

Constants

This section is empty.

Variables

View Source
var (
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603
	CodeCustomError    = -32000
)
View Source
var (
	ErrNotFunction         = errors.New("not a function")
	ErrMustReturnError     = errors.New("function must return error as a last return value")
	ErrMustHaveContext     = errors.New("function must have context.Context as a first argument")
	ErrTooManyReturnValues = errors.New("too many return values")

	ErrTooMuchArguments = errors.New("too much arguments")
)

Functions

func GetOrigin

func GetOrigin(ctx context.Context) string

func GetPriority

func GetPriority(ctx context.Context) bool

func GetSigner

func GetSigner(ctx context.Context) common.Address

Types

type Handler

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

func NewHandler

func NewHandler(methods Methods) (*Handler, error)

NewHandler creates JSONRPC http.Handler from the map that maps method names to method functions each method function must: - have context as a first argument - return error as a last argument - have argument types that can be unmarshalled from JSON - have return types that can be marshalled to JSON

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type JSONRPCError

type JSONRPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    *any   `json:"data,omitempty"`
}

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string            `json:"jsonrpc"`
	ID      any               `json:"id"`
	Method  string            `json:"method"`
	Params  []json.RawMessage `json:"params"`
}

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string           `json:"jsonrpc"`
	ID      any              `json:"id"`
	Result  *json.RawMessage `json:"result,omitempty"`
	Error   *JSONRPCError    `json:"error,omitempty"`
}

type Methods

type Methods map[string]interface{}

Jump to

Keyboard shortcuts

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