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 ¶
- Variables
- func GetBuilderNetSentAt(ctx context.Context) time.Time
- func GetHighPriority(ctx context.Context) bool
- func GetOrigin(ctx context.Context) string
- func GetRequestSize(ctx context.Context) int
- func GetSigner(ctx context.Context) common.Address
- type JSONRPCError
- type JSONRPCHandler
- type JSONRPCHandlerOpts
- type JSONRPCResponse
- type Methods
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") ErrVariadicArgument = errors.New("unsupported function signature: functions with variadic arguments support one and only variadic argument") ErrTooMuchArguments = errors.New("too much arguments") )
Functions ¶
func GetHighPriority ¶
func GetRequestSize ¶ added in v0.13.2
Types ¶
type JSONRPCError ¶ added in v0.15.0
type JSONRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data *any `json:"data,omitempty"`
}
func (*JSONRPCError) Error ¶ added in v0.15.0
func (e *JSONRPCError) Error() string
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, extracts the `X-BuilderNet-SentAtUs` header value and sets it in the context.
ExtractBuilderNetSentAtFromHeader 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
// Custom handler for /readyz endpoint. If not nil then it is expected to write the response to the provided ResponseWriter.
// If the custom handler returns an error, the error message is written to the ResponseWriter with a 500 status code.
ReadyHandler func(w http.ResponseWriter, r *http.Request) error
ForbidEmptySigner bool
}
type JSONRPCResponse ¶ added in v0.15.0
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID any `json:"id"`
Result *json.RawMessage `json:"result,omitempty"`
Error *JSONRPCError `json:"error,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.