Documentation ¶
Index ¶
- func SocketType(listenAddr string) string
- type Context
- type JSONRPCIntID
- type JSONRPCStringID
- type RPCError
- type RPCRequest
- func ArrayToRequest(cdc *amino.Codec, id jsonrpcid, method string, params []interface{}) (RPCRequest, error)
- func MapToRequest(cdc *amino.Codec, id jsonrpcid, method string, params map[string]interface{}) (RPCRequest, error)
- func NewRPCRequest(id jsonrpcid, method string, params json.RawMessage) RPCRequest
- type RPCResponse
- func NewRPCErrorResponse(id jsonrpcid, code int, msg string, data string) RPCResponse
- func NewRPCSuccessResponse(cdc *amino.Codec, id jsonrpcid, res interface{}) RPCResponse
- func RPCInternalError(id jsonrpcid, err error) RPCResponse
- func RPCInvalidParamsError(id jsonrpcid, err error) RPCResponse
- func RPCInvalidRequestError(id jsonrpcid, err error) RPCResponse
- func RPCMethodNotFoundError(id jsonrpcid) RPCResponse
- func RPCParseError(err error) RPCResponse
- func RPCServerError(id jsonrpcid, err error) RPCResponse
- type WSRPCConnection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SocketType ¶
Determine if its a unix or tcp socket. If tcp, must specify the port; `0.0.0.0` will return incorrectly as "unix" since there's no port TODO: deprecate
Types ¶
type Context ¶
type Context struct { // json-rpc request JSONReq *RPCRequest // websocket connection WSConn WSRPCConnection // http request HTTPReq *http.Request }
Context is the first parameter for all functions. It carries a json-rpc request, http request and websocket connection.
- JSONReq is non-nil when JSONRPC is called over websocket or HTTP. - WSConn is non-nil when we're connected via a websocket. - HTTPReq is non-nil when URI or JSONRPC is called over HTTP.
func (*Context) Context ¶
Context returns the request's context. The returned context is always non-nil; it defaults to the background context. HTTP:
The context is canceled when the client's connection closes, the request is canceled (with HTTP/2), or when the ServeHTTP method returns.
WS:
The context is canceled when the client's connections closes.
func (*Context) RemoteAddr ¶
RemoteAddr returns the remote address (usually a string "IP:port"). If neither HTTPReq nor WSConn is set, an empty string is returned. HTTP:
http.Request#RemoteAddr
WS:
result of GetRemoteAddr
type JSONRPCIntID ¶
type JSONRPCIntID int
JSONRPCIntID a wrapper for JSON-RPC integer IDs
func (JSONRPCIntID) String ¶ added in v0.33.0
func (id JSONRPCIntID) String() string
type JSONRPCStringID ¶
type JSONRPCStringID string
JSONRPCStringID a wrapper for JSON-RPC string IDs
func (JSONRPCStringID) String ¶ added in v0.33.0
func (id JSONRPCStringID) String() string
type RPCError ¶
type RPCRequest ¶
type RPCRequest struct { JSONRPC string `json:"jsonrpc"` ID jsonrpcid `json:"id,omitempty"` Method string `json:"method"` Params json.RawMessage `json:"params"` // must be map[string]interface{} or []interface{} }
func ArrayToRequest ¶
func ArrayToRequest(cdc *amino.Codec, id jsonrpcid, method string, params []interface{}) (RPCRequest, error)
func MapToRequest ¶
func NewRPCRequest ¶
func NewRPCRequest(id jsonrpcid, method string, params json.RawMessage) RPCRequest
func (RPCRequest) String ¶
func (req RPCRequest) String() string
func (*RPCRequest) UnmarshalJSON ¶
func (req *RPCRequest) UnmarshalJSON(data []byte) error
UnmarshalJSON custom JSON unmarshalling due to jsonrpcid being string or int
type RPCResponse ¶
type RPCResponse struct { JSONRPC string `json:"jsonrpc"` ID jsonrpcid `json:"id,omitempty"` Result json.RawMessage `json:"result,omitempty"` Error *RPCError `json:"error,omitempty"` }
func NewRPCErrorResponse ¶
func NewRPCErrorResponse(id jsonrpcid, code int, msg string, data string) RPCResponse
func NewRPCSuccessResponse ¶
func NewRPCSuccessResponse(cdc *amino.Codec, id jsonrpcid, res interface{}) RPCResponse
func RPCInternalError ¶
func RPCInternalError(id jsonrpcid, err error) RPCResponse
func RPCInvalidParamsError ¶
func RPCInvalidParamsError(id jsonrpcid, err error) RPCResponse
func RPCInvalidRequestError ¶
func RPCInvalidRequestError(id jsonrpcid, err error) RPCResponse
From the JSON-RPC 2.0 spec:
If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.
func RPCMethodNotFoundError ¶
func RPCMethodNotFoundError(id jsonrpcid) RPCResponse
func RPCParseError ¶
func RPCParseError(err error) RPCResponse
From the JSON-RPC 2.0 spec:
If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.
func RPCServerError ¶
func RPCServerError(id jsonrpcid, err error) RPCResponse
func (RPCResponse) String ¶
func (resp RPCResponse) String() string
func (*RPCResponse) UnmarshalJSON ¶
func (resp *RPCResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON custom JSON unmarshalling due to jsonrpcid being string or int
type WSRPCConnection ¶
type WSRPCConnection interface { // GetRemoteAddr returns a remote address of the connection. GetRemoteAddr() string // WriteRPCResponse writes the resp onto connection (BLOCKING). WriteRPCResponse(resp RPCResponse) // TryWriteRPCResponse tries to write the resp onto connection (NON-BLOCKING). TryWriteRPCResponse(resp RPCResponse) bool // Codec returns an Amino codec used. Codec() *amino.Codec // Context returns the connection's context. Context() context.Context }
WSRPCConnection represents a websocket connection.