Documentation
¶
Index ¶
- Constants
- type RPCError
- type RPCRequest
- type RPCRequests
- type RPCResponse
- type Request
- func (r *Request) RPCBatchCall(requests RPCRequests) ([]RPCResponse, error)
- func (r *Request) RPCBatchCallWithContext(ctx context.Context, requests RPCRequests) ([]RPCResponse, error)
- func (r *Request) RPCCall(result interface{}, method string, params interface{}) error
- func (r *Request) RPCCallWithContext(ctx context.Context, result interface{}, method string, params interface{}) error
Constants ¶
const (
// Version default JSON-RPC version.
Version = "2.0"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RPCRequest ¶
type RPCRequest struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
ID int64 `json:"id,omitempty"`
}
RPCRequest represents the JSON-RPC request object.
type RPCRequests ¶
type RPCRequests []*RPCRequest
RPCRequests represents a list of JSON-RPC requests.
type RPCResponse ¶
type RPCResponse struct {
JSONRPC string `json:"jsonrpc"`
Error *RPCError `json:"error,omitempty"`
Result interface{} `json:"result,omitempty"`
ID int64 `json:"id,omitempty"`
}
RPCResponse represents the JSON-RPC response object.
func (*RPCResponse) GetObject ¶
func (r *RPCResponse) GetObject(toType interface{}) error
GetObject bind the request result into the struct. It returns an error if occurs.
type Request ¶
Request represents a client request wrapper.
func InitRPCClient ¶
InitRPCClient initialize the rpc client. It returns the rpc request object.
func (*Request) RPCBatchCall ¶
func (r *Request) RPCBatchCall(requests RPCRequests) ([]RPCResponse, error)
RPCBatchCall make a batch of JSON-RPC requests. E.g.:
var requests RpcRequests
for _, hash := range hashes {
requests = append(requests, &RpcRequest{
Method: "GetTransaction",
Params: []string{hash},
})
}
responses, err := c.RpcBatchCall(requests)
It returns the result and an error if occurs.
func (*Request) RPCBatchCallWithContext ¶
func (r *Request) RPCBatchCallWithContext(ctx context.Context, requests RPCRequests) ([]RPCResponse, error)
RPCBatchCallWithContext make a batch of JSON-RPC requests with context. E.g.:
var requests RpcRequests
for _, hash := range hashes {
requests = append(requests, &RpcRequest{
Method: "GetTransaction",
Params: []string{hash},
})
}
responses, err := c.RpcBatchCall(context.Background(), requests)
It returns the result and an error if occurs.
func (*Request) RPCCall ¶
RPCCall make a JSON-RPC request and bind the result into the generic interface. E.g.:
var tx []Tx
err = c.RpcCall(&tx, "getTransactionsByAddress", []string{address, "25"})
It returns an error if occurs.
func (*Request) RPCCallWithContext ¶
func (r *Request) RPCCallWithContext(ctx context.Context, result interface{}, method string, params interface{}) error
RPCCallWithContext make a JSON-RPC request and bind the result into the generic interface passing the context. E.g.:
var tx []Tx
err = c.RpcCall(context.Background(), &tx, "getTransactionsByAddress", []string{address, "25"})
It returns an error if occurs.