server

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultErrorCode default error code
	DefaultErrorCode = -32000
	// InvalidRequestErrorCode error code for invalid requests
	InvalidRequestErrorCode = -32600
	// NotFoundErrorCode error code for not found objects
	NotFoundErrorCode = -32601
	// InvalidParamsErrorCode error code for invalid parameters
	InvalidParamsErrorCode = -32602
	// ParserErrorCode error code for parsing errors
	ParserErrorCode = -32700
)

Variables

View Source
var (
	// ErrBatchRequestsDisabled returned by the pool mananger server when a batch request is detected and the batch requests are disabled via configuration
	ErrBatchRequestsDisabled = fmt.Errorf("batch requests are disabled")
	// ErrBatchRequestsLimitExceeded returned by the server when a batch request is detected and the number of requests are greater than the configured limit
	ErrBatchRequestsLimitExceeded = fmt.Errorf("batch requests limit exceeded")
)

Functions

func GetSender

func GetSender(tx ethTypes.Transaction) (common.Address, error)

GetSender gets the sender from the transaction's signature

Types

type ArgBytes

type ArgBytes []byte

ArgBytes helps to marshal byte array values provided in the RPC requests

func ArgBytesPtr

func ArgBytesPtr(b []byte) *ArgBytes

ArgBytesPtr helps to marshal byte array values provided in the RPC requests

type Config

type Config struct {
	// Host defines the network adapter that will be used to serve the HTTP requests
	Host string `mapstructure:"Host"`

	// Port defines the port to serve the endpoints via HTTP
	Port int `mapstructure:"Port"`

	// ReadTimeout is the HTTP server read timeout. Check net/http.server.ReadTimeout and net/http.server.ReadHeaderTimeout
	ReadTimeout types.Duration `mapstructure:"ReadTimeout"`

	// WriteTimeout is the HTTP server write timeout. Check net/http.server.WriteTimeout
	WriteTimeout types.Duration `mapstructure:"WriteTimeout"`

	// MaxRequestsPerIPAndSecond defines how much requests a single IP can send within a single second
	MaxRequestsPerIPAndSecond float64 `mapstructure:"MaxRequestsPerIPAndSecond"`

	// EnableHttpLog allows the user to enable or disable the logs related to the HTTP requests to be captured by the server.
	EnableHttpLog bool `mapstructure:"EnableHttpLog"`

	// BatchRequestsEnabled defines if the batch requests are enabled or disabled
	BatchRequestsEnabled bool `mapstructure:"BatchRequestsEnabled"`

	// BatchRequestsLimit defines the limit of requests that can be incorporated into each batch request
	BatchRequestsLimit uint `mapstructure:"BatchRequestsLimit"`
}

Config for pool-manager JSON-RPC server

type Endpoints

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

Endpoints contains implementations for the pool-manager JSON-RPC endpoints

func NewEndpoints

func NewEndpoints(cfg Config, poolDB poolDBInterface, sender senderInterface) *Endpoints

NewEndpoints creates an new instance of pool-manager JSON-RPC endpoints

func (*Endpoints) SendRawTransaction

func (e *Endpoints) SendRawTransaction(httpRequest *http.Request, input string) (interface{}, Error)

type Error

type Error interface {
	Error() string
	ErrorCode() int
	ErrorData() []byte
}

Error interface

func RPCErrorResponse

func RPCErrorResponse(code int, message string, err error, logError bool) (interface{}, Error)

RPCErrorResponse formats error to be returned through RPC

func RPCErrorResponseWithData

func RPCErrorResponseWithData(code int, message string, data []byte, err error, logError bool) (interface{}, Error)

RPCErrorResponseWithData formats error to be returned through RPC

type ErrorObject

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

ErrorObject is a jsonrpc error

type Handler

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

Handler manage services to handle pool-manager RPC requests

func (*Handler) Handle

func (h *Handler) Handle(req handleRequest) Response

Handle is the function that knows which and how a function should be executed when a pool-manager RPC request is received

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request is a jsonrpc Request

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	Id      interface{}     `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *ErrorObject    `json:"error,omitempty"`
}

Response is a jsonrpc success/error response

func NewResponse

func NewResponse(req Request, reply []byte, err Error) Response

NewResponse returns Success/Error response object

type Server

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

Server represents a JSON-RPC server to handle pool-manager requests

func NewServer

func NewServer(cfg Config, poolDB *db.PoolDB, sender senderInterface) *Server

NewServer returns a JSON-RPC server to handle pool-manager requests

func (*Server) Start

func (s *Server) Start()

Start initializes pool-manager JSON-RPC server to listen for requests

func (*Server) Stop

func (s *Server) Stop() error

Stop shutdown the JSON-RPC server

type ServerError

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

ServerError represents an error returned by a pool manager endpoint

func NewServerError

func NewServerError(code int, err string, args ...interface{}) *ServerError

NewServerError creates a new error instance to be returned by the pool manager endpoints

func NewServerErrorWithData

func NewServerErrorWithData(code int, err string, data []byte, args ...interface{}) *ServerError

NewServerErrorWithData creates a new error instance with data to be returned by the pool manager endpoints

func (ServerError) Error

func (e ServerError) Error() string

Error returns the error message

func (*ServerError) ErrorCode

func (e *ServerError) ErrorCode() int

ErrorCode returns the error code

func (*ServerError) ErrorData

func (e *ServerError) ErrorData() []byte

ErrorData returns the error data

Jump to

Keyboard shortcuts

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