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) */
| 1416 | * because we don't have libplugin infra to cancel a pending req (and I |
| 1417 | * want to rewrite our wait* API anyway) */ |
| 1418 | struct command_result *invoice_payment(struct command *cmd, |
| 1419 | const char *buf, |
| 1420 | const jsmntok_t *params) |
| 1421 | { |
| 1422 | struct sent *i; |
| 1423 | const jsmntok_t *ptok, *preimagetok, *msattok; |
| 1424 | struct preimage preimage; |
| 1425 | struct amount_msat msat; |
| 1426 | |
| 1427 | ptok = json_get_member(buf, params, "payment"); |
| 1428 | preimagetok = json_get_member(buf, ptok, "preimage"); |
| 1429 | msattok = json_get_member(buf, ptok, "msat"); |
| 1430 | if (!preimagetok || !msattok) |
| 1431 | plugin_err(cmd->plugin, |
| 1432 | "Invalid invoice_payment %.*s", |
| 1433 | json_tok_full_len(params), |
| 1434 | json_tok_full(buf, params)); |
| 1435 | |
| 1436 | hex_decode(buf + preimagetok->start, |
| 1437 | preimagetok->end - preimagetok->start, |
| 1438 | &preimage, sizeof(preimage)); |
| 1439 | json_to_msat(buf, msattok, &msat); |
| 1440 | |
| 1441 | list_for_each(&sent_list, i, list) { |
| 1442 | struct out_req *req; |
| 1443 | |
| 1444 | if (!i->inv) |
| 1445 | continue; |
| 1446 | if (!preimage_eq(&preimage, &i->inv_preimage)) |
| 1447 | continue; |
| 1448 | |
| 1449 | /* It was paid! Success. Return as per waitinvoice. */ |
| 1450 | req = jsonrpc_request_start(i->cmd, "waitinvoice", |
| 1451 | &forward_result, |
| 1452 | &forward_error, |
| 1453 | i); |
| 1454 | json_add_escaped_string(req->js, "label", i->inv_label); |
| 1455 | discard_result(send_outreq(req)); |
| 1456 | break; |
| 1457 | } |
| 1458 | return command_hook_success(cmd); |
| 1459 | } |
| 1460 | |
| 1461 | static struct command_result *createinvoice_done(struct command *cmd, |
| 1462 | const char *method, |
nothing calls this directly
no test coverage detected