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

Function invoice_payment

plugins/fetchinvoice.c:1327–1368  ·  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

1325 * because we don't have libplugin infra to cancel a pending req (and I
1326 * want to rewrite our wait* API anyway) */
1327struct 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
1370static struct command_result *createinvoice_done(struct command *cmd,
1371 const char *method,

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected