Documentation ¶
Index ¶
- Constants
- func HexEncodeBig(bigint *big.Int) string
- func HexIsValid(s string) bool
- type ArgBig
- type ArgBytes
- type ArgHash
- type ArgUint64
- type Config
- type DBTxManager
- type DBTxScopedFn
- type DBTxer
- 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 ¶
func HexEncodeBig ¶
HexEncodeBig encodes bigint as a hex string with 0x prefix. The sign of the integer is ignored.
func HexIsValid ¶
HexIsValid checks if the provided string is a valid hexadecimal value
Types ¶
type ArgBig ¶ added in v0.0.3
ArgBig helps to marshal big number values provided in the RPC requests
func (ArgBig) MarshalText ¶ added in v0.0.3
MarshalText marshals an array of bytes into an instance of ArgBig
func (*ArgBig) UnmarshalText ¶ added in v0.0.3
UnmarshalText unmarshals an instance of ArgBig into an array of bytes
type ArgBytes ¶
type ArgBytes []byte
ArgBytes helps to marshal byte array values provided in the RPC requests
func ArgBytesPtr ¶
ArgBytesPtr helps to marshal byte array values provided in the RPC requests
func (ArgBytes) MarshalText ¶
MarshalText marshals into text
func (*ArgBytes) UnmarshalText ¶
UnmarshalText unmarshals from text
type ArgHash ¶
ArgHash represents a common.Hash that accepts strings shorter than 64 bytes, like 0x00
func (*ArgHash) UnmarshalText ¶
UnmarshalText unmarshals from text
type ArgUint64 ¶
type ArgUint64 uint64
ArgUint64 helps to marshal uint64 values provided in the RPC requests
func ArgUint64Ptr ¶
ArgUint64Ptr returns the pointer of the provided ArgUint64
func (ArgUint64) MarshalText ¶
MarshalText marshals into text
func (*ArgUint64) UnmarshalText ¶
UnmarshalText unmarshals from text
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 DBTxManager ¶
type DBTxManager struct{}
DBTxManager allows to do scopped DB txs
func (*DBTxManager) NewDbTxScope ¶
func (f *DBTxManager) NewDbTxScope(db DBTxer, scopedFn DBTxScopedFn) (interface{}, Error)
NewDbTxScope function to initiate DB scopped txs
type DBTxScopedFn ¶
DBTxScopedFn function to do scopped DB txs
type Error ¶
Error interface
func RPCErrorResponse ¶
RPCErrorResponse 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 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 ID interface{} Result json.RawMessage Error *ErrorObject }
Response is a jsonrpc success response
func JSONRPCCall ¶
JSONRPCCall 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