Documentation ¶
Overview ¶
Provides a general JSON-RPC client, decodes Diem extension fields.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Call with requests. When given multiple requests Call(...*Request) (map[RequestID]*Response, error) }
Client is interface of the JSON-RPC client
func NewClient ¶
NewClient creates a new JSON-RPC Client. Creates http.Transport with 3 max idle connections and 30 seconds idle timeout, and 30 seconds connection timeout NewClientWithHTTPClient can be used to override the connection timeout NewClientWithTransport can be used to override the underlying transport
func NewClientWithHTTPClient ¶
NewClientWithHTTPClient creates a new JSON-RPC Client with given URL and `*http.Client`
type ErrorType ¶
type ErrorType string
ErrorType is type of the `Error`, which maybe caused by different underlining errors
const ( SerializeRequestJsonError ErrorType = "serialize request json failed" HttpCallError ErrorType = "http call failed" ReadHttpResponseBodyError ErrorType = "read http response body failed" ParseResponseJsonError ErrorType = "parse response json failed" ParseResponseResultJsonError ErrorType = "parse response result json failed" InvalidJsonRpcResponseError ErrorType = "invalid JSON-RPC response: missing result / error field" )
type Request ¶
type Request struct { Method Method `json:"method"` Params []Param `json:"params"` ID RequestID `json:"id"` JsonRpc string `json:"jsonrpc"` }
Request is type of JSON-RPC request struct
func NewRequest ¶
NewRequest creates `Request` with default `JsonRpc` = "2.0" and ID = 1
func NewRequestWithID ¶
NewRequestWithID creates `Request` with default `JsonRpc` = "2.0"
type Response ¶
type Response struct { JsonRpc string `json:"jsonrpc"` ID *RequestID `json:"id"` Result *json.RawMessage `json:"result"` Error *ResponseError `json:"error"` DiemChainID byte `json:"diem_chain_id"` DiemLedgerTimestampusec uint64 `json:"diem_ledger_timestampusec"` DiemLedgerVersion uint64 `json:"diem_ledger_version"` }
Response is type of JSON-RPC response struct
func (*Response) UnmarshalResult ¶
UnmarshalResult unmarshals result json into given struct. Returns true, nil for success unmarshal, otherwise first bool will always be false. Returns false, nil if `Result` is nil.
type ResponseError ¶
type ResponseError struct { Code int32 `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` }
ResponseError is type of JSON-RPC response error, it implements error interface.
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
Error implements error interface, returns `Code` + `Message`
Directories ¶
Path | Synopsis |
---|---|
Provides a simple json-rpc client stub for testing client without connecting to remote server.
|
Provides a simple json-rpc client stub for testing client without connecting to remote server. |