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

Function xpay_core

plugins/xpay/xpay.c:2675–2951  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2673}
2674
2675static struct command_result *xpay_core(struct command *cmd,
2676 const char *invstring TAKES,
2677 const struct amount_msat *msat,
2678 const struct amount_msat *maxfee,
2679 const char **layers,
2680 u32 retryfor,
2681 const struct amount_msat *partial,
2682 u32 maxdelay,
2683 const struct json_escape *label,
2684 const struct sha256 *localinvreqid,
2685 bool use_shadow,
2686 bool as_pay,
2687 const struct amount_msat *includefees_msat)
2688{
2689 struct payment *payment;
2690 struct xpay *xpay = xpay_of(cmd->plugin);
2691 struct gossmap *gossmap = get_gossmap(xpay);
2692 struct node_id dstid;
2693 bool disable_mpp;
2694 u64 now, invexpiry;
2695 struct out_req *req;
2696 const char *err;
2697 /* Invoice amount for fee-cap calculation when includefees_msat is set */
2698 struct amount_msat invoice_msat = AMOUNT_MSAT(0);
2699
2700 /* Make our own copy here, in case we exit early. */
2701 invstring = tal_strdup(tmpctx, invstring);
2702
2703 if (bolt12_has_prefix(invstring)) {
2704 struct tlv_invoice *b12inv
2705 = invoice_decode(tmpctx, invstring,
2706 strlen(invstring),
2707 plugin_feature_set(cmd->plugin),
2708 chainparams, &err);
2709 if (!b12inv)
2710 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2711 "Invalid bolt12 invoice: %s", err);
2712
2713 if (includefees_msat) {
2714 /* msat is the expected invoice amount for validation */
2715 if (msat && !amount_msat_eq(*msat, amount_msat(*b12inv->invoice_amount)))
2716 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2717 "Expecting a bolt12 invoice with amount %s, got %s instead",
2718 fmt_amount_msat(tmpctx, *msat),
2719 fmt_amount_msat(tmpctx, amount_msat(*b12inv->invoice_amount)));
2720 } else {
2721 if (msat)
2722 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2723 "Cannot override amount for bolt12 invoices");
2724 }
2725 /* FIXME: This is actually spec legal, since invoice_amount is
2726 * the *minumum* it will accept. We could change this to
2727 * 1msat if required. */
2728 if (amount_msat_is_zero(amount_msat(*b12inv->invoice_amount)))
2729 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2730 "Invalid bolt12 invoice with zero amount");
2731 /* BOLT #12:
2732 * - 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