MCPcopy Create free account
hub / github.com/ElementsProject/lightning / invoice_payment

Function invoice_payment

plugins/fetchinvoice.c:1321–1362  ·  view source on GitHub ↗

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) */

Source from the content-addressed store, hash-verified

1319 * because we don't have libplugin infra to cancel a pending req (and I
1320 * want to rewrite our wait* API anyway) */
1321static struct command_result *invoice_payment(struct command *cmd,
1322 const char *buf,
1323 const jsmntok_t *params)
1324{
1325 struct sent *i;
1326 const jsmntok_t *ptok, *preimagetok, *msattok;
1327 struct preimage preimage;
1328 struct amount_msat msat;
1329
1330 ptok = json_get_member(buf, params, "payment");
1331 preimagetok = json_get_member(buf, ptok, "preimage");
1332 msattok = json_get_member(buf, ptok, "msat");
1333 if (!preimagetok || !msattok)
1334 plugin_err(cmd->plugin,
1335 "Invalid invoice_payment %.*s",
1336 json_tok_full_len(params),
1337 json_tok_full(buf, params));
1338
1339 hex_decode(buf + preimagetok->start,
1340 preimagetok->end - preimagetok->start,
1341 &preimage, sizeof(preimage));
1342 json_to_msat(buf, msattok, &msat);
1343
1344 list_for_each(&sent_list, i, list) {
1345 struct out_req *req;
1346
1347 if (!i->inv)
1348 continue;
1349 if (!preimage_eq(&preimage, &i->inv_preimage))
1350 continue;
1351
1352 /* It was paid! Success. Return as per waitinvoice. */
1353 req = jsonrpc_request_start(cmd->plugin, i->cmd, "waitinvoice",
1354 &forward_result,
1355 &forward_error,
1356 i);
1357 json_add_escaped_string(req->js, "label", i->inv_label);
1358 discard_result(send_outreq(cmd->plugin, req));
1359 break;
1360 }
1361 return command_hook_success(cmd);
1362}
1363
1364/* We've connected (if we tried), so send the invoice. */
1365static struct command_result *

Callers

nothing calls this directly

Calls 10

hex_decodeFunction · 0.85
discard_resultFunction · 0.85
command_hook_successFunction · 0.85
plugin_errFunction · 0.70
send_outreqFunction · 0.70
json_get_memberFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50
json_to_msatFunction · 0.50
json_add_escaped_stringFunction · 0.50

Tested by

no test coverage detected