Check response for error (fatal if found) and return result token (fatal if not found). */
| 114 | |
| 115 | /* Check response for error (fatal if found) and return result token (fatal if not found). */ |
| 116 | static const jsmntok_t *get_bitcoin_result(struct bitcoind *bitcoind, |
| 117 | const char *buf, |
| 118 | const jsmntok_t *toks, |
| 119 | const char *method) |
| 120 | { |
| 121 | const jsmntok_t *err_tok, *msg_tok, *result_tok; |
| 122 | |
| 123 | err_tok = json_get_member(buf, toks, "error"); |
| 124 | if (err_tok) { |
| 125 | msg_tok = json_get_member(buf, err_tok, "message"); |
| 126 | if (msg_tok) |
| 127 | bitcoin_plugin_error(bitcoind, buf, toks, method, |
| 128 | "%.*s", json_tok_full_len(msg_tok), |
| 129 | json_tok_full(buf, msg_tok)); |
| 130 | else |
| 131 | bitcoin_plugin_error(bitcoind, buf, toks, method, |
| 132 | "%.*s", json_tok_full_len(err_tok), |
| 133 | json_tok_full(buf, err_tok)); |
| 134 | } |
| 135 | |
| 136 | result_tok = json_get_member(buf, toks, "result"); |
| 137 | if (!result_tok) |
| 138 | bitcoin_plugin_error(bitcoind, buf, toks, method, |
| 139 | "missing 'result' field"); |
| 140 | |
| 141 | return result_tok; |
| 142 | } |
| 143 | |
| 144 | /* Send a request to the Bitcoin plugin which registered that method, |
| 145 | * if it's still alive. */ |
no test coverage detected