Documentation ¶
Index ¶
- Constants
- func BuildJsonHTTPRequest(ctx context.Context, url, method string, parameters ...interface{}) (*http.Request, error)
- func BuildJsonHttpRequestWithBody(ctx context.Context, url string, reqBody []byte) (*http.Request, error)
- type Config
- type Error
- type ErrorObject
- type Handler
- type RPCError
- type Request
- type Response
- type Server
- type Service
Constants ¶
const ( // DefaultErrorCode rpc default error code DefaultErrorCode = -32000 // RevertedErrorCode error code for reverted txs RevertedErrorCode = 3 // 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 // AccessDeniedCode error code when requests are denied AccessDeniedCode = -32800 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
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"` }
Config represents the configuration of the json rpc
type ErrorObject ¶
type ErrorObject struct { Code int `json:"code"` Message string `json:"message"` Data *types.ArgBytes `json:"data,omitempty"` }
ErrorObject is a jsonrpc error
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manage services to handle jsonrpc requests
Services are public structures containing public methods matching the name of the jsonrpc method.
Services must be registered with a prefix to identify the service and its methods, for example a service registered with a prefix `eth` will have all the public methods exposed as eth_<methodName> through the json rpc server.
Go public methods requires the first char of its name to be in uppercase, but the exposition of the method will consider it to lower case, for example a method `func MyMethod()` provided by the service registered with `eth` prefix will be triggered when the method eth_myMethod is specified
the public methods must follow the conventions: - return interface{}, rpcError - if the method depend on a Web Socket connection, it must be the first parameters as f(*websocket.Conn) - parameter types must match the type of the data provided for the method
check the `eth.go` file for more example on how the methods are implemented
type RPCError ¶
type RPCError struct {
// contains filtered or unexported fields
}
RPCError represents an error returned by a JSON RPC endpoint.
func NewRPCError ¶
NewRPCError creates a new error instance to be returned by the RPC endpoints
func NewRPCErrorWithData ¶
NewRPCErrorWithData creates a new error instance with data to be returned by the RPC endpoints
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 response
func JSONRPCCall ¶
JSONRPCCall calls JSONRPCCallWithContext with the default context
func JSONRPCCallWithContext ¶ added in v0.0.4
func JSONRPCCallWithContext(ctx context.Context, url, method string, parameters ...interface{}) (Response, error)
JSONRPCCallWithContext executes a 2.0 JSON RPC HTTP Post Request to the provided URL with the provided method and parameters, which is compatible with the Ethereum JSON RPC Server.
func NewResponse ¶
NewResponse returns Success/Error response object