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

Function xpay_core

plugins/xpay/xpay.c:2526–2795  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2524}
2525
2526static struct command_result *xpay_core(struct command *cmd,
2527 const char *invstring TAKES,
2528 const struct amount_msat *msat,
2529 const struct amount_msat *maxfee,
2530 const char **layers,
2531 u32 retryfor,
2532 const struct amount_msat *partial,
2533 u32 maxdelay,
2534 const struct json_escape *label,
2535 const struct sha256 *localinvreqid,
2536 bool use_shadow,
2537 bool as_pay,
2538 const struct amount_msat *includefees_msat)
2539{
2540 struct payment *payment;
2541 struct xpay *xpay = xpay_of(cmd->plugin);
2542 struct gossmap *gossmap = get_gossmap(xpay);
2543 struct node_id dstid;
2544 bool disable_mpp;
2545 u64 now, invexpiry;
2546 struct out_req *req;
2547 const char *err;
2548 /* Invoice amount for fee-cap calculation when includefees_msat is set */
2549 struct amount_msat invoice_msat = AMOUNT_MSAT(0);
2550
2551 /* Make our own copy here, in case we exit early. */
2552 invstring = tal_strdup(tmpctx, invstring);
2553
2554 if (bolt12_has_prefix(invstring)) {
2555 struct tlv_invoice *b12inv
2556 = invoice_decode(tmpctx, invstring,
2557 strlen(invstring),
2558 plugin_feature_set(cmd->plugin),
2559 chainparams, &err);
2560 if (!b12inv)
2561 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2562 "Invalid bolt12 invoice: %s", err);
2563
2564 if (includefees_msat) {
2565 /* msat is the expected invoice amount for validation */
2566 if (msat && !amount_msat_eq(*msat, amount_msat(*b12inv->invoice_amount)))
2567 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2568 "Expecting a bolt12 invoice with amount %s, got %s instead",
2569 fmt_amount_msat(tmpctx, *msat),
2570 fmt_amount_msat(tmpctx, amount_msat(*b12inv->invoice_amount)));
2571 } else {
2572 if (msat)
2573 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2574 "Cannot override amount for bolt12 invoices");
2575 }
2576 /* FIXME: This is actually spec legal, since invoice_amount is
2577 * the *minumum* it will accept. We could change this to
2578 * 1msat if required. */
2579 if (amount_msat_is_zero(amount_msat(*b12inv->invoice_amount)))
2580 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2581 "Invalid bolt12 invoice with zero amount");
2582 invexpiry = invoice_expiry(b12inv);
2583 invoice_msat = amount_msat(*b12inv->invoice_amount);

Callers 3

invoice_fetchedFunction · 0.85
json_xpay_paramsFunction · 0.85
json_sendamountFunction · 0.85

Calls 15

xpay_ofFunction · 0.85
bolt12_has_prefixFunction · 0.85
invoice_decodeFunction · 0.85
amount_msat_is_zeroFunction · 0.85
invoice_expiryFunction · 0.85
new_paymentFunction · 0.85
gossmap_scidd_pubkeyFunction · 0.85
payment_logFunction · 0.85
fmt_sciddir_or_pubkeyFunction · 0.85
feature_offeredFunction · 0.85
bolt11_decodeFunction · 0.85
fmt_node_idFunction · 0.85

Tested by

no test coverage detected