Reads rpc reply and returns result tokens */
| 743 | |
| 744 | /* Reads rpc reply and returns result tokens */ |
| 745 | static const jsmntok_t *read_sync_rpc_reply(const tal_t *ctx, |
| 746 | struct plugin *plugin, |
| 747 | const char *method, |
| 748 | const char **final_buffer) |
| 749 | { |
| 750 | const jsmntok_t *errtok, *resulttok, *toks; |
| 751 | const char *buffer; |
| 752 | |
| 753 | for (;;) { |
| 754 | buffer = read_one_json_sync(plugin, &toks); |
| 755 | /* FIXME: Don't simply ignore notifications here! */ |
| 756 | if (json_get_member(buffer, toks, "id")) |
| 757 | break; |
| 758 | jsonrpc_io_parse_done(plugin->sync_io); |
| 759 | } |
| 760 | |
| 761 | errtok = json_get_member(buffer, toks, "error"); |
| 762 | if (errtok) { |
| 763 | plugin_err(plugin, "Got error result to %s: '%.*s'", |
| 764 | method, |
| 765 | json_tok_full_len(toks), |
| 766 | json_tok_full(buffer, toks)); |
| 767 | } |
| 768 | resulttok = json_get_member(buffer, toks, "result"); |
| 769 | if (!resulttok) { |
| 770 | plugin_err(plugin, "JSON reply with no 'result' nor 'error'? '%.*s'", |
| 771 | json_tok_full_len(toks), |
| 772 | json_tok_full(buffer, toks)); |
| 773 | } |
| 774 | |
| 775 | /* Make the returned pointers valid tal object */ |
| 776 | json_dup_contents(ctx, buffer, resulttok, final_buffer, &toks); |
| 777 | jsonrpc_io_parse_done(plugin->sync_io); |
| 778 | |
| 779 | return toks; |
| 780 | } |
| 781 | |
| 782 | /* Send request, return response, set resp/len to reponse */ |
| 783 | static const jsmntok_t *sync_req(const tal_t *ctx, |
no test coverage detected