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

Function do_inject

plugins/xpay/xpay.c:1456–1515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1454}
1455
1456static struct command_result *do_inject(struct command *aux_cmd,
1457 struct attempt *attempt)
1458{
1459 struct out_req *req;
1460 const struct xpay_onion *xpay_onion;
1461 struct xpay *xpay = xpay_of(attempt->payment->plugin);
1462 /* In case a block comes in, we give CLTVs an extra 1. */
1463 u32 effective_bheight = xpay->blockheight + 1;
1464
1465 xpay_onion = create_onion(tmpctx, attempt, effective_bheight);
1466 if (!xpay_onion->raw_onion) {
1467 char *error;
1468 size_t total =
1469 xpay_onion->forward_bytes + xpay_onion->tail_bytes;
1470 if (total > ROUTING_INFO_SIZE)
1471 error = tal_fmt(
1472 tmpctx,
1473 "%zu bytes needed (%" PRIu32
1474 " hops using %zu bytes, plus %zu bytes for the "
1475 "final payload or blinded path)",
1476 total, xpay_onion->num_forwards,
1477 xpay_onion->forward_bytes, xpay_onion->tail_bytes);
1478 else
1479 error = tal_fmt(tmpctx, "failed to derive shared secrets");
1480
1481 payment_log(attempt->payment, LOG_BROKEN,
1482 "create_onion failed: %s", error);
1483 payment_give_up(aux_cmd, attempt->payment,
1484 PAY_UNSPECIFIED_ERROR,
1485 "Could not create payment onion: %s", error);
1486 return command_still_pending(aux_cmd);
1487 }
1488
1489 outgoing_notify_start(attempt);
1490 attempt->start_time = time_mono();
1491
1492 req = jsonrpc_request_start(aux_cmd,
1493 "injectpaymentonion",
1494 injectpaymentonion_succeeded,
1495 injectpaymentonion_failed,
1496 attempt);
1497 json_add_hex_talarr(req->js, "onion", xpay_onion->raw_onion);
1498 json_add_sha256(req->js, "payment_hash", &attempt->payment->payment_hash);
1499 /* If no route, its the same as delivery (self-pay) */
1500 json_add_amount_msat(req->js, "amount_msat", inject_amount(attempt));
1501 json_add_u32(req->js, "cltv_expiry", initial_cltv_delta(attempt) + effective_bheight);
1502 json_add_u64(req->js, "partid", attempt->partid);
1503 json_add_u64(req->js, "groupid", attempt->payment->group_id);
1504 /* Use invstring for payments, destination directly for keysend */
1505 if (attempt->payment->invstring)
1506 json_add_string(req->js, "invstring", attempt->payment->invstring);
1507 else
1508 json_add_pubkey(req->js, "destination", &attempt->payment->destination);
1509 json_add_amount_msat(req->js, "destination_msat", attempt_deliver(attempt));
1510 if (attempt->payment->localinvreqid)
1511 json_add_sha256(req->js, "localinvreqid", attempt->payment->localinvreqid);
1512 if (attempt->payment->label)
1513 json_add_escaped_string(req->js, "label", attempt->payment->label);

Callers 2

reserve_doneFunction · 0.85
getroutes_forFunction · 0.85

Calls 15

xpay_ofFunction · 0.85
payment_logFunction · 0.85
payment_give_upFunction · 0.85
outgoing_notify_startFunction · 0.85
time_monoFunction · 0.85
json_add_hex_talarrFunction · 0.85
json_add_sha256Function · 0.85
json_add_amount_msatFunction · 0.85
inject_amountFunction · 0.85
json_add_u32Function · 0.85
json_add_u64Function · 0.85
json_add_pubkeyFunction · 0.85

Tested by

no test coverage detected