| 157 | } |
| 158 | |
| 159 | static struct command_result *handle_invreq_response(struct command *cmd, |
| 160 | struct sent *sent, |
| 161 | const char *buf, |
| 162 | const jsmntok_t *om) |
| 163 | { |
| 164 | const u8 *invbin, *cursor; |
| 165 | const jsmntok_t *invtok; |
| 166 | size_t len; |
| 167 | struct tlv_invoice *inv; |
| 168 | struct sha256 merkle, sighash; |
| 169 | struct json_stream *out; |
| 170 | const char *badfield; |
| 171 | u64 *expected_amount; |
| 172 | const struct recurrence *recurrence; |
| 173 | u64 starttime, endtime; |
| 174 | u64 next_counter, next_period_idx; |
| 175 | u64 paywindow_start, paywindow_end; |
| 176 | bool have_next_period = false; |
| 177 | char *error; |
| 178 | |
| 179 | invtok = json_get_member(buf, om, "invoice"); |
| 180 | if (!invtok) { |
| 181 | plugin_log(cmd->plugin, LOG_UNUSUAL, |
| 182 | "Neither invoice nor invoice_request_failed in reply %.*s", |
| 183 | json_tok_full_len(om), |
| 184 | json_tok_full(buf, om)); |
| 185 | discard_result(command_fail(sent->cmd, |
| 186 | OFFER_BAD_INVREQ_REPLY, |
| 187 | "Neither invoice nor invoice_request_failed in reply %.*s", |
| 188 | json_tok_full_len(om), |
| 189 | json_tok_full(buf, om))); |
| 190 | return command_hook_success(cmd); |
| 191 | } |
| 192 | |
| 193 | invbin = json_tok_bin_from_hex(cmd, buf, invtok); |
| 194 | cursor = invbin; |
| 195 | len = tal_bytelen(invbin); |
| 196 | inv = fromwire_tlv_invoice(cmd, &cursor, &len); |
| 197 | if (!inv) { |
| 198 | badfield = "invoice"; |
| 199 | goto badinv; |
| 200 | } |
| 201 | |
| 202 | /* Raw send? Just fwd reply. */ |
| 203 | if (plugin_developer_mode(cmd->plugin) && !sent->offer) { |
| 204 | out = jsonrpc_stream_success(sent->cmd); |
| 205 | json_add_string(out, "invoice", invoice_encode(tmpctx, inv)); |
| 206 | discard_result(command_finished(sent->cmd, out)); |
| 207 | return command_hook_success(cmd); |
| 208 | } |
| 209 | |
| 210 | /* BOLT #12: |
| 211 | * - if the invoice is a response to an `invoice_request`: |
| 212 | * - MUST reject the invoice if all fields in ranges 0 to 159 and |
| 213 | * 1000000000 to 2999999999 (inclusive) do not exactly match the |
| 214 | * invoice request. |
| 215 | */ |
| 216 | if (!invoice_matches_request(cmd, invbin, sent->invreq)) { |
no test coverage detected