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

Method handleResponse

api/rpc/client.go:647–671  ·  view source on GitHub ↗
(msg *jsonrpcMessage)

Source from the content-addressed store, hash-verified

645}
646
647func (c *Client) handleResponse(msg *jsonrpcMessage) {
648 op := c.respWait[string(msg.ID)]
649 if op == nil {
650 log.Debug("unsolicited response", "msg", msg)
651 return
652 }
653 delete(c.respWait, string(msg.ID))
654 // For normal responses, just forward the reply to Call/BatchCall.
655 if op.sub == nil {
656 op.resp <- msg
657 return
658 }
659 // For subscription responses, start the subscription if the server
660 // indicates success. EthSubscribe gets unblocked in either case through
661 // the op.resp channel.
662 defer close(op.resp)
663 if msg.Error != nil {
664 op.err = msg.Error
665 return
666 }
667 if op.err = json.Unmarshal(msg.Result, &op.sub.subid); op.err == nil {
668 go op.sub.start()
669 c.subs[op.sub.subid] = op.sub
670 }
671}
672
673// Reading happens on a dedicated goroutine.
674

Callers 1

dispatchMethod · 0.95

Calls 2

DebugMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected