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

Function json_sendamount

plugins/xpay/xpay.c:2815–2903  ·  view source on GitHub ↗

When to use this? * If we want to be specific about the amount we send and not about the amount * the other end receives. * Same pattern as json_xpay. */

Source from the content-addressed store, hash-verified

2813 * the other end receives.
2814 * Same pattern as json_xpay. */
2815static struct command_result *json_sendamount(struct command *cmd,
2816 const char *buffer,
2817 const jsmntok_t *params)
2818{
2819 struct amount_msat *send_msat, *maxfee;
2820 struct amount_msat invoice_msat;
2821 const char *invstring;
2822 const char **layers;
2823 u32 *maxdelay;
2824 const char *payer_note;
2825 unsigned int *retryfor;
2826 struct json_escape *label;
2827 struct xpay_params *xparams;
2828 struct out_req *req;
2829
2830 if (!param_check(cmd, buffer, params,
2831 p_req("invstring", param_invstring, &invstring),
2832 p_req("amount_msat", param_msat, &send_msat),
2833 p_opt("maxfee", param_msat, &maxfee),
2834 p_opt("layers", param_string_array, &layers),
2835 p_opt_def("retry_for", param_number, &retryfor, 60),
2836 p_opt_def("maxdelay", param_u32, &maxdelay, 2016),
2837 p_opt("payer_note", param_string, &payer_note),
2838 p_opt("label", param_label, &label),
2839 NULL))
2840 return command_param_failed();
2841
2842 // FIXME: why does xpay returns this only after
2843 // preapproveinvoice_succeed?
2844 if (command_check_only(cmd))
2845 return command_check_done(cmd);
2846
2847 /* We need the recepient to generate an invoice for send_msat/2
2848 * so that we can deliver any value from send_msat/2 up to
2849 * send_msat. We don't know the fees in advance. We could use
2850 * getroutes to estimate some fees though, but the use of
2851 * blinded paths already invalidates this procedure: we can't
2852 * use getroutes until we have an invoice. */
2853 invoice_msat = amount_msat_div_ceil(*send_msat, 2);
2854 // FIXME: could this work with invoice_msat = 0?
2855
2856 /* Bolt12 offer */
2857 if (bolt12_has_prefix(invstring)) {
2858 struct command_result *ret;
2859 ret = check_offer_sendamount_payable(cmd, invstring);
2860 if (ret)
2861 return ret;
2862 xparams = tal(cmd, struct xpay_params);
2863 xparams->msat =
2864 tal_dup(xparams, struct amount_msat, &invoice_msat);
2865 xparams->maxfee = maxfee;
2866 xparams->partial = NULL;
2867 xparams->includefees_msat = send_msat;
2868 xparams->layers = layers;
2869 xparams->retryfor = *retryfor;
2870 xparams->maxdelay = *maxdelay;
2871 xparams->bip353 = NULL;
2872 xparams->payer_note = payer_note;

Callers

nothing calls this directly

Calls 11

param_checkFunction · 0.85
amount_msat_div_ceilFunction · 0.85
bolt12_has_prefixFunction · 0.85
do_fetchinvoiceFunction · 0.85
xpay_coreFunction · 0.85
command_param_failedFunction · 0.50
command_check_onlyFunction · 0.50
command_check_doneFunction · 0.50
json_add_stringFunction · 0.50
send_outreqFunction · 0.50

Tested by

no test coverage detected