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