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

Function json_sendamount

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

2905 * the other end receives.
2906 * Same pattern as json_xpay. */
2907static struct command_result *json_sendamount(struct command *cmd,
2908 const char *buffer,
2909 const jsmntok_t *params)
2910{
2911 struct amount_msat *send_msat, *maxfee;
2912 struct amount_msat invoice_msat;
2913 const char *invstring;
2914 const char **layers;
2915 u32 *maxdelay;
2916 const char *payer_note;
2917 unsigned int *retryfor;
2918 struct json_escape *label;
2919 struct xpay_params *xparams;
2920 struct out_req *req;
2921
2922 if (!param_check(cmd, buffer, params,
2923 p_req("invstring", param_invstring, &invstring),
2924 p_req("amount_msat", param_msat, &send_msat),
2925 p_opt("maxfee", param_msat, &maxfee),
2926 p_opt("layers", param_string_array, &layers),
2927 p_opt_def("retry_for", param_number, &retryfor, 60),
2928 p_opt_def("maxdelay", param_u32, &maxdelay, 2016),
2929 p_opt("payer_note", param_string, &payer_note),
2930 p_opt("label", param_label, &label),
2931 NULL))
2932 return command_param_failed();
2933
2934 // FIXME: why does xpay returns this only after
2935 // preapproveinvoice_succeed?
2936 if (command_check_only(cmd))
2937 return command_check_done(cmd);
2938
2939 /* We need the recepient to generate an invoice for send_msat/2
2940 * so that we can deliver any value from send_msat/2 up to
2941 * send_msat. We don't know the fees in advance. We could use
2942 * getroutes to estimate some fees though, but the use of
2943 * blinded paths already invalidates this procedure: we can't
2944 * use getroutes until we have an invoice. */
2945 invoice_msat = amount_msat_div_ceil(*send_msat, 2);
2946 // FIXME: could this work with invoice_msat = 0?
2947
2948 /* Bolt12 offer */
2949 if (bolt12_has_prefix(invstring)) {
2950 struct command_result *ret;
2951 ret = check_offer_sendamount_payable(cmd, invstring);
2952 if (ret)
2953 return ret;
2954 xparams = tal(cmd, struct xpay_params);
2955 xparams->msat =
2956 tal_dup(xparams, struct amount_msat, &invoice_msat);
2957 xparams->maxfee = maxfee;
2958 xparams->partial = NULL;
2959 xparams->includefees_msat = send_msat;
2960 xparams->layers = layers;
2961 xparams->retryfor = *retryfor;
2962 xparams->maxdelay = *maxdelay;
2963 xparams->bip353 = NULL;
2964 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