| 156 | } |
| 157 | |
| 158 | static struct command_result *handle_invreq_response(struct command *cmd, |
| 159 | struct sent *sent, |
| 160 | const char *buf, |
| 161 | const jsmntok_t *om) |
| 162 | { |
| 163 | const u8 *invbin; |
| 164 | const jsmntok_t *invtok; |
| 165 | size_t len; |
| 166 | struct tlv_invoice *inv; |
| 167 | struct sha256 merkle, sighash; |
| 168 | struct json_stream *out; |
| 169 | const char *badfield; |
| 170 | u64 *expected_amount; |
| 171 | |
| 172 | invtok = json_get_member(buf, om, "invoice"); |
| 173 | if (!invtok) { |
| 174 | plugin_log(cmd->plugin, LOG_UNUSUAL, |
| 175 | "Neither invoice nor invoice_request_failed in reply %.*s", |
| 176 | json_tok_full_len(om), |
| 177 | json_tok_full(buf, om)); |
| 178 | discard_result(command_fail(sent->cmd, |
| 179 | OFFER_BAD_INVREQ_REPLY, |
| 180 | "Neither invoice nor invoice_request_failed in reply %.*s", |
| 181 | json_tok_full_len(om), |
| 182 | json_tok_full(buf, om))); |
| 183 | return command_hook_success(cmd); |
| 184 | } |
| 185 | |
| 186 | invbin = json_tok_bin_from_hex(cmd, buf, invtok); |
| 187 | len = tal_bytelen(invbin); |
| 188 | inv = fromwire_tlv_invoice(cmd, &invbin, &len); |
| 189 | if (!inv) { |
| 190 | badfield = "invoice"; |
| 191 | goto badinv; |
| 192 | } |
| 193 | |
| 194 | #if DEVELOPER |
| 195 | /* Raw send? Just fwd reply. */ |
| 196 | if (!sent->offer) { |
| 197 | out = jsonrpc_stream_success(sent->cmd); |
| 198 | json_add_string(out, "invoice", invoice_encode(tmpctx, inv)); |
| 199 | discard_result(command_finished(sent->cmd, out)); |
| 200 | return command_hook_success(cmd); |
| 201 | } |
| 202 | #endif /* DEVELOPER */ |
| 203 | |
| 204 | /* BOLT-offers #12: |
| 205 | * - MUST reject the invoice unless `node_id` is equal to the offer. |
| 206 | */ |
| 207 | if (!point32_eq(sent->offer->node_id, inv->node_id)) { |
| 208 | badfield = "node_id"; |
| 209 | goto badinv; |
| 210 | } |
| 211 | |
| 212 | /* BOLT-offers #12: |
| 213 | * - MUST reject the invoice if `signature` is not a valid signature |
| 214 | * using `node_id` as described in [Signature Calculation] |
| 215 | */ |
no test coverage detected