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

Function json_sendamount

plugins/xpay/xpay.c:2971–3063  ·  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

2969 * the other end receives.
2970 * Same pattern as json_xpay. */
2971static struct command_result *json_sendamount(struct command *cmd,
2972 const char *buffer,
2973 const jsmntok_t *params)
2974{
2975 struct amount_msat *send_msat, *maxfee;
2976 struct amount_msat invoice_msat;
2977 const char *invstring;
2978 const char **layers;
2979 u32 *maxdelay;
2980 const char *payer_note;
2981 unsigned int *retryfor;
2982 struct json_escape *label;
2983 struct xpay_params *xparams;
2984 struct out_req *req;
2985
2986 if (!param_check(cmd, buffer, params,
2987 p_req("invstring", param_invstring, &invstring),
2988 p_req("amount_msat", param_msat, &send_msat),
2989 p_opt("maxfee", param_msat, &maxfee),
2990 p_opt("layers", param_string_array, &layers),
2991 p_opt_def("retry_for", param_number, &retryfor, 60),
2992 p_opt_def("maxdelay", param_u32, &maxdelay, 2016),
2993 p_opt("payer_note", param_string, &payer_note),
2994 p_opt("label", param_label, &label),
2995 NULL))
2996 return command_param_failed();
2997
2998 // FIXME: why does xpay returns this only after
2999 // preapproveinvoice_succeed?
3000 if (command_check_only(cmd))
3001 return command_check_done(cmd);
3002
3003 /* We need the recepient to generate an invoice for send_msat/2
3004 * so that we can deliver any value from send_msat/2 up to
3005 * send_msat. We don't know the fees in advance. We could use
3006 * getroutes to estimate some fees though, but the use of
3007 * blinded paths already invalidates this procedure: we can't
3008 * use getroutes until we have an invoice. */
3009 invoice_msat = amount_msat_div_ceil(*send_msat, 2);
3010 // FIXME: could this work with invoice_msat = 0?
3011
3012 /* Bolt12 offer */
3013 if (bolt12_has_prefix(invstring)) {
3014 struct command_result *ret;
3015 ret = check_offer_sendamount_payable(cmd, invstring);
3016 if (ret)
3017 return ret;
3018 xparams = tal(cmd, struct xpay_params);
3019 xparams->msat =
3020 tal_dup(xparams, struct amount_msat, &invoice_msat);
3021 xparams->maxfee = maxfee;
3022 xparams->partial = NULL;
3023 xparams->includefees_msat = send_msat;
3024 xparams->layers = layers;
3025 xparams->retryfor = *retryfor;
3026 xparams->maxdelay = *maxdelay;
3027 xparams->bip353 = NULL;
3028 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