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

Function json_xkeysend

plugins/xpay/xpay.c:3003–3098  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3001}
3002
3003static struct command_result *json_xkeysend(struct command *cmd,
3004 const char *buf,
3005 const jsmntok_t *params)
3006{
3007 struct xpay *xpay = xpay_of(cmd->plugin);
3008 struct amount_msat *msat, *maxfee;
3009 struct pubkey *dst;
3010 u32 *maxdelay;
3011 unsigned int *retryfor;
3012 struct payment *payment;
3013 struct json_escape *label;
3014 const char *err;
3015 struct preimage preimage;
3016 struct sha256 payment_hash;
3017 const char **layers;
3018 struct tlv_field *extra_fields;
3019 u8 *tlvs;
3020 struct out_req *req;
3021
3022 if (!param_check(cmd, buf, params,
3023 p_req("destination", param_pubkey, &dst),
3024 p_req("amount_msat", param_msat, &msat),
3025 p_opt("label", param_label, &label),
3026 p_opt("maxfee", param_msat, &maxfee),
3027 p_opt("layers", param_string_array, &layers),
3028 p_opt_def("retry_for", param_number, &retryfor, 60),
3029 p_opt_def("maxdelay", param_number, &maxdelay, 2016),
3030 p_opt("extratlvs", param_extra_tlvs, &extra_fields),
3031 NULL))
3032 return command_param_failed();
3033
3034 randbytes(&preimage, sizeof(preimage));
3035 sha256(&payment_hash, &preimage, sizeof(preimage));
3036
3037 /* We explicitly prohibit self-keysends */
3038 if (pubkey_eq(&xpay->local_id, dst)) {
3039 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
3040 "We are the destination. Keysend cannot be used to send funds to yourself");
3041 }
3042
3043 payment = new_payment(cmd, cmd,
3044 *retryfor,
3045 *maxdelay,
3046 layers,
3047 NULL, /* NULL invstring is the marker of a keysend vs pay */
3048 dst,
3049 &payment_hash,
3050 *msat,
3051 NULL,
3052 maxfee,
3053 NULL, NULL,
3054 // 22 is the Rust-Lightning default and the
3055 // highest minimum CLTV we know of.
3056 22,
3057 label,
3058 NULL,
3059 false,
3060 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