MCPcopy Create free account
hub / github.com/CPChain/chain / CallContext

Method CallContext

api/rpc/client.go:291–318  ·  view source on GitHub ↗

CallContext performs a JSON-RPC call with the given arguments. If the context is canceled before the call has successfully returned, CallContext returns immediately. The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.

(ctx context.Context, result interface{}, method string, args ...interface{})

Source from the content-addressed store, hash-verified

289// The result must be a pointer so that package json can unmarshal into it. You
290// can also pass nil, in which case the result is ignored.
291func (c *Client) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
292 msg, err := c.newMessage(method, args...)
293 if err != nil {
294 return err
295 }
296 op := &requestOp{ids: []json.RawMessage{msg.ID}, resp: make(chan *jsonrpcMessage, 1)}
297
298 if c.isHTTP {
299 err = c.sendHTTP(ctx, op, msg)
300 } else {
301 err = c.send(ctx, op, msg)
302 }
303 if err != nil {
304 return err
305 }
306
307 // dispatch has accepted the request and will close the channel it when it quits.
308 switch resp, err := op.wait(ctx); {
309 case err != nil:
310 return err
311 case resp.Error != nil:
312 return resp.Error
313 case len(resp.Result) == 0:
314 return ErrNoResult
315 default:
316 return json.Unmarshal(resp.Result, &result)
317 }
318}
319
320// BatchCall sends all given requests as a single batch and waits for the server
321// to return a response for all of them.

Callers 15

testClientCancelFunction · 0.95
SupportedModulesMethod · 0.95
CallMethod · 0.95
TestStatusFunction · 0.80
TestMiningFunction · 0.80
isMiningMethod · 0.80
StartMiningMethod · 0.80
StopMiningMethod · 0.80
getBlockMethod · 0.80
HeaderByHashMethod · 0.80
HeaderByNumberMethod · 0.80
GetBlockNumberMethod · 0.80

Calls 4

newMessageMethod · 0.95
sendHTTPMethod · 0.95
sendMethod · 0.95
waitMethod · 0.95

Tested by 6

testClientCancelFunction · 0.76
TestStatusFunction · 0.64
TestMiningFunction · 0.64
subscribeBlocksFunction · 0.64
TestClientReconnectFunction · 0.64