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

Function json_xkeysend

plugins/xpay/xpay.c:3286–3381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3284}
3285
3286static struct command_result *json_xkeysend(struct command *cmd,
3287 const char *buf,
3288 const jsmntok_t *params)
3289{
3290 struct xpay *xpay = xpay_of(cmd->plugin);
3291 struct amount_msat *msat, *maxfee;
3292 struct pubkey *dst;
3293 u32 *maxdelay;
3294 unsigned int *retryfor;
3295 struct payment *payment;
3296 struct json_escape *label;
3297 const char *err;
3298 struct preimage preimage;
3299 struct sha256 payment_hash;
3300 const char **layers;
3301 struct tlv_field *extra_fields;
3302 u8 *tlvs;
3303 struct out_req *req;
3304
3305 if (!param_check(cmd, buf, params,
3306 p_req("destination", param_pubkey, &dst),
3307 p_req("amount_msat", param_msat, &msat),
3308 p_opt("label", param_label, &label),
3309 p_opt("maxfee", param_msat, &maxfee),
3310 p_opt("layers", param_string_array, &layers),
3311 p_opt_def("retry_for", param_number, &retryfor, 60),
3312 p_opt_def("maxdelay", param_number, &maxdelay, 2016),
3313 p_opt("extratlvs", param_extra_tlvs, &extra_fields),
3314 NULL))
3315 return command_param_failed();
3316
3317 randbytes(&preimage, sizeof(preimage));
3318 sha256(&payment_hash, &preimage, sizeof(preimage));
3319
3320 /* We explicitly prohibit self-keysends */
3321 if (pubkey_eq(&xpay->local_id, dst)) {
3322 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
3323 "We are the destination. Keysend cannot be used to send funds to yourself");
3324 }
3325
3326 payment = new_payment(cmd, cmd,
3327 *retryfor,
3328 *maxdelay,
3329 layers,
3330 NULL, /* NULL invstring is the marker of a keysend vs pay */
3331 dst,
3332 &payment_hash,
3333 *msat,
3334 NULL,
3335 maxfee,
3336 NULL, NULL,
3337 // 22 is the Rust-Lightning default and the
3338 // highest minimum CLTV we know of.
3339 22,
3340 label,
3341 NULL,
3342 false,
3343 false,

Callers

nothing calls this directly

Calls 14

xpay_ofFunction · 0.85
param_checkFunction · 0.85
new_paymentFunction · 0.85
tlvstream_set_rawFunction · 0.85
towire_tlvstream_rawFunction · 0.85
json_add_pubkeyFunction · 0.85
json_add_sha256Function · 0.85
json_add_amount_msatFunction · 0.85
sha256Class · 0.70
command_param_failedFunction · 0.50
command_failFunction · 0.50
command_check_onlyFunction · 0.50

Tested by

no test coverage detected