| 645 | } |
| 646 | |
| 647 | func (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 | |