Documentation ¶
Overview ¶
Package rpcserver 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 DefaultMaxRequestBodySizeBytes = 30 * 1024 * 1024 // 30mb )
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 GetHighPriority ¶
Types ¶
type JSONRPCHandler ¶
type JSONRPCHandler struct { JSONRPCHandlerOpts // contains filtered or unexported fields }
func NewJSONRPCHandler ¶
func NewJSONRPCHandler(methods Methods, opts JSONRPCHandlerOpts) (*JSONRPCHandler, error)
NewJSONRPCHandler 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 (*JSONRPCHandler) ServeHTTP ¶
func (h *JSONRPCHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type JSONRPCHandlerOpts ¶
type JSONRPCHandlerOpts struct { // Logger, can be nil Log *slog.Logger // Server name. Used to separate logs and metrics when having multiple servers in one binary. ServerName string // Max size of the request payload MaxRequestBodySizeBytes int64 // If true payload signature from X-Flashbots-Signature will be verified // Result can be extracted from the context using GetSigner VerifyRequestSignatureFromHeader bool // If true signer from X-Flashbots-Signature will be extracted without verifying signature // Result can be extracted from the context using GetSigner ExtractUnverifiedRequestSignatureFromHeader bool // If true high_prio header value will be extracted (true or false) // Result can be extracted from the context using GetHighPriority ExtractPriorityFromHeader bool // If true extract value from x-flashbots-origin header // Result can be extracted from the context using GetOrigin ExtractOriginFromHeader bool // GET response content GetResponseContent []byte }
Click to show internal directories.
Click to hide internal directories.