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

Function on_htlc_accepted

plugins/lsps-plugin/src/client.rs:543–659  ·  view source on GitHub ↗
(
    p: cln_plugin::Plugin<State>,
    v: serde_json::Value,
)

Source from the content-addressed store, hash-verified

541}
542
543async fn on_htlc_accepted(
544 p: cln_plugin::Plugin<State>,
545 v: serde_json::Value,
546) -> Result<serde_json::Value, anyhow::Error> {
547 let req: HtlcAcceptedRequest = ok_or_continue!(
548 serde_json::from_value(v).context("failed to deserialize htlc_accepted request JSON")
549 );
550
551 let htlc_amt = req.htlc.amount_msat;
552 let onion_amt = some_or_continue!(
553 req.onion.forward_msat,
554 "missing forward_msat in onion, continue"
555 );
556
557 let payment_data = some_or_continue!(
558 req.onion.payload.get(TLV_PAYMENT_SECRET),
559 "htlc is a forward, continue"
560 );
561
562 // Check that the htlc belongs to a jit-channel request.
563 let dir = p.configuration().lightning_dir;
564 let rpc_path = Path::new(&dir).join(&p.configuration().rpc_file);
565 let mut cln_client = ok_or_continue!(
566 cln_rpc::ClnRpc::new(rpc_path.clone())
567 .await
568 .context("failed to connect to core-lightning")
569 );
570
571 let lsp_data = ok_or_continue!(
572 cln_client
573 .call_typed(&ListdatastoreRequest {
574 key: Some(vec![
575 "lsps".to_string(),
576 "invoice".to_string(),
577 hex::encode(&req.htlc.payment_hash),
578 ]),
579 })
580 .await
581 .context("failed to fetch datastore record")
582 );
583
584 // If we don't know about this payment it's not an LSP payment, continue.
585 some_or_continue!(lsp_data.datastore.first());
586
587 let extra_fee_msat = req
588 .htlc
589 .extra_tlvs
590 .as_ref()
591 .map(|tlvs| tlvs.get_u64(65537))
592 .transpose()?
593 .flatten()
594 .unwrap_or_default();
595
596 debug!(
597 "incoming jit-channel htlc with htlc_amt={}, onion_amt={} and extra_fee={}",
598 htlc_amt.msat(),
599 onion_amt.msat(),
600 extra_fee_msat

Callers

nothing calls this directly

Calls 8

encode_tu64Function · 0.85
configurationMethod · 0.80
joinMethod · 0.80
mapMethod · 0.80
get_u64Method · 0.80
set_tu64Method · 0.80
msatMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected