| 2609 | } |
| 2610 | |
| 2611 | static 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: |
no test coverage detected