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

Function xpay_core

plugins/xpay/xpay.c:2611–2887  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2609}
2610
2611static struct command_result *xpay_core(struct command *cmd,
2612 const char *invstring TAKES,
2613 const struct amount_msat *msat,
2614 const struct amount_msat *maxfee,
2615 const char **layers,
2616 u32 retryfor,
2617 const struct amount_msat *partial,
2618 u32 maxdelay,
2619 const struct json_escape *label,
2620 const struct sha256 *localinvreqid,
2621 bool use_shadow,
2622 bool as_pay,
2623 const struct amount_msat *includefees_msat)
2624{
2625 struct payment *payment;
2626 struct xpay *xpay = xpay_of(cmd->plugin);
2627 struct gossmap *gossmap = get_gossmap(xpay);
2628 struct node_id dstid;
2629 bool disable_mpp;
2630 u64 now, invexpiry;
2631 struct out_req *req;
2632 const char *err;
2633 /* Invoice amount for fee-cap calculation when includefees_msat is set */
2634 struct amount_msat invoice_msat = AMOUNT_MSAT(0);
2635
2636 /* Make our own copy here, in case we exit early. */
2637 invstring = tal_strdup(tmpctx, invstring);
2638
2639 if (bolt12_has_prefix(invstring)) {
2640 struct tlv_invoice *b12inv
2641 = invoice_decode(tmpctx, invstring,
2642 strlen(invstring),
2643 plugin_feature_set(cmd->plugin),
2644 chainparams, &err);
2645 if (!b12inv)
2646 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2647 "Invalid bolt12 invoice: %s", err);
2648
2649 if (includefees_msat) {
2650 /* msat is the expected invoice amount for validation */
2651 if (msat && !amount_msat_eq(*msat, amount_msat(*b12inv->invoice_amount)))
2652 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2653 "Expecting a bolt12 invoice with amount %s, got %s instead",
2654 fmt_amount_msat(tmpctx, *msat),
2655 fmt_amount_msat(tmpctx, amount_msat(*b12inv->invoice_amount)));
2656 } else {
2657 if (msat)
2658 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2659 "Cannot override amount for bolt12 invoices");
2660 }
2661 /* FIXME: This is actually spec legal, since invoice_amount is
2662 * the *minumum* it will accept. We could change this to
2663 * 1msat if required. */
2664 if (amount_msat_is_zero(amount_msat(*b12inv->invoice_amount)))
2665 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2666 "Invalid bolt12 invoice with zero amount");
2667 /* BOLT #12:
2668 * - if `invoice_relative_expiry` is present:

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
bolt11_decodeFunction · 0.85
fmt_node_idFunction · 0.85
clock_timeFunction · 0.85

Tested by

no test coverage detected