FIXME: Using a hook here is not ideal: technically it doesn't mean * it's actually hit the db! But using waitinvoice is also suboptimal * because we don't have libplugin infra to cancel a pending req (and I * want to rewrite our wait* API anyway) */
| 1325 | * because we don't have libplugin infra to cancel a pending req (and I |
| 1326 | * want to rewrite our wait* API anyway) */ |
| 1327 | struct command_result *invoice_payment(struct command *cmd, |
| 1328 | const char *buf, |
| 1329 | const jsmntok_t *params) |
| 1330 | { |
| 1331 | struct sent *i; |
| 1332 | const jsmntok_t *ptok, *preimagetok, *msattok; |
| 1333 | struct preimage preimage; |
| 1334 | struct amount_msat msat; |
| 1335 | |
| 1336 | ptok = json_get_member(buf, params, "payment"); |
| 1337 | preimagetok = json_get_member(buf, ptok, "preimage"); |
| 1338 | msattok = json_get_member(buf, ptok, "msat"); |
| 1339 | if (!preimagetok || !msattok) |
| 1340 | plugin_err(cmd->plugin, |
| 1341 | "Invalid invoice_payment %.*s", |
| 1342 | json_tok_full_len(params), |
| 1343 | json_tok_full(buf, params)); |
| 1344 | |
| 1345 | hex_decode(buf + preimagetok->start, |
| 1346 | preimagetok->end - preimagetok->start, |
| 1347 | &preimage, sizeof(preimage)); |
| 1348 | json_to_msat(buf, msattok, &msat); |
| 1349 | |
| 1350 | list_for_each(&sent_list, i, list) { |
| 1351 | struct out_req *req; |
| 1352 | |
| 1353 | if (!i->inv) |
| 1354 | continue; |
| 1355 | if (!preimage_eq(&preimage, &i->inv_preimage)) |
| 1356 | continue; |
| 1357 | |
| 1358 | /* It was paid! Success. Return as per waitinvoice. */ |
| 1359 | req = jsonrpc_request_start(i->cmd, "waitinvoice", |
| 1360 | &forward_result, |
| 1361 | &forward_error, |
| 1362 | i); |
| 1363 | json_add_escaped_string(req->js, "label", i->inv_label); |
| 1364 | discard_result(send_outreq(req)); |
| 1365 | break; |
| 1366 | } |
| 1367 | return command_hook_success(cmd); |
| 1368 | } |
| 1369 | |
| 1370 | static struct command_result *createinvoice_done(struct command *cmd, |
| 1371 | const char *method, |
nothing calls this directly
no test coverage detected