@@ -1654,6 +1654,140 @@ fn calculate_amount_to_forward_per_htlc(
16541654 per_htlc_forwards
16551655}
16561656
1657+ /// A synchroneous wrapper around [`LSPS2ServiceHandler`] to be used in contexts where async is not
1658+ /// available.
1659+ pub struct LSPS2ServiceHandlerSync < ' a , CM : Deref , K : Deref + Clone >
1660+ where
1661+ CM :: Target : AChannelManager ,
1662+ K :: Target : KVStore ,
1663+ {
1664+ inner : & ' a LSPS2ServiceHandler < CM , K > ,
1665+ }
1666+
1667+ impl < ' a , CM : Deref , K : Deref + Clone > LSPS2ServiceHandlerSync < ' a , CM , K >
1668+ where
1669+ CM :: Target : AChannelManager ,
1670+ K :: Target : KVStore ,
1671+ {
1672+ pub ( crate ) fn from_inner ( inner : & ' a LSPS2ServiceHandler < CM , K > ) -> Self {
1673+ Self { inner }
1674+ }
1675+
1676+ /// Returns a reference to the used config.
1677+ ///
1678+ /// Wraps [`LSPS2ServiceHandler::config`].
1679+ pub fn config ( & self ) -> & LSPS2ServiceConfig {
1680+ & self . inner . config
1681+ }
1682+
1683+ /// Used by LSP to inform a client requesting a JIT Channel the token they used is invalid.
1684+ ///
1685+ /// Wraps [`LSPS2ServiceHandler::invalid_token_provided`].
1686+ pub fn invalid_token_provided (
1687+ & self , counterparty_node_id : & PublicKey , request_id : LSPSRequestId ,
1688+ ) -> Result < ( ) , APIError > {
1689+ self . inner . invalid_token_provided ( counterparty_node_id, request_id)
1690+ }
1691+
1692+ /// Used by LSP to provide fee parameters to a client requesting a JIT Channel.
1693+ ///
1694+ /// Wraps [`LSPS2ServiceHandler::opening_fee_params_generated`].
1695+ pub fn opening_fee_params_generated (
1696+ & self , counterparty_node_id : & PublicKey , request_id : LSPSRequestId ,
1697+ opening_fee_params_menu : Vec < LSPS2RawOpeningFeeParams > ,
1698+ ) -> Result < ( ) , APIError > {
1699+ self . inner . opening_fee_params_generated (
1700+ counterparty_node_id,
1701+ request_id,
1702+ opening_fee_params_menu,
1703+ )
1704+ }
1705+
1706+ /// Used by LSP to provide the client with the intercept scid and
1707+ /// `cltv_expiry_delta` to include in their invoice.
1708+ ///
1709+ /// Wraps [`LSPS2ServiceHandler::invoice_parameters_generated`].
1710+ pub fn invoice_parameters_generated (
1711+ & self , counterparty_node_id : & PublicKey , request_id : LSPSRequestId , intercept_scid : u64 ,
1712+ cltv_expiry_delta : u32 , client_trusts_lsp : bool , user_channel_id : u128 ,
1713+ ) -> Result < ( ) , APIError > {
1714+ self . inner . invoice_parameters_generated (
1715+ counterparty_node_id,
1716+ request_id,
1717+ intercept_scid,
1718+ cltv_expiry_delta,
1719+ client_trusts_lsp,
1720+ user_channel_id,
1721+ )
1722+ }
1723+
1724+ /// Forward [`Event::HTLCIntercepted`] event parameters into this function.
1725+ ///
1726+ /// Wraps [`LSPS2ServiceHandler::htlc_intercepted`].
1727+ ///
1728+ /// [`Event::HTLCIntercepted`]: lightning::events::Event::HTLCIntercepted
1729+ pub fn htlc_intercepted (
1730+ & self , intercept_scid : u64 , intercept_id : InterceptId , expected_outbound_amount_msat : u64 ,
1731+ payment_hash : PaymentHash ,
1732+ ) -> Result < ( ) , APIError > {
1733+ self . inner . htlc_intercepted (
1734+ intercept_scid,
1735+ intercept_id,
1736+ expected_outbound_amount_msat,
1737+ payment_hash,
1738+ )
1739+ }
1740+
1741+ /// Forward [`Event::HTLCHandlingFailed`] event parameter into this function.
1742+ ///
1743+ /// Wraps [`LSPS2ServiceHandler::htlc_handling_failed`].
1744+ ///
1745+ /// [`Event::HTLCHandlingFailed`]: lightning::events::Event::HTLCHandlingFailed
1746+ pub fn htlc_handling_failed (
1747+ & self , failure_type : HTLCHandlingFailureType ,
1748+ ) -> Result < ( ) , APIError > {
1749+ self . inner . htlc_handling_failed ( failure_type)
1750+ }
1751+
1752+ /// Forward [`Event::PaymentForwarded`] event parameter into this function.
1753+ ///
1754+ /// Wraps [`LSPS2ServiceHandler::payment_forwarded`].
1755+ ///
1756+ /// [`Event::PaymentForwarded`]: lightning::events::Event::PaymentForwarded
1757+ pub fn payment_forwarded ( & self , next_channel_id : ChannelId ) -> Result < ( ) , APIError > {
1758+ self . inner . payment_forwarded ( next_channel_id)
1759+ }
1760+
1761+ /// Abandons a pending JIT‐open flow for `user_channel_id`, removing all local state.
1762+ ///
1763+ /// Wraps [`LSPS2ServiceHandler::channel_open_abandoned`].
1764+ pub fn channel_open_abandoned (
1765+ & self , counterparty_node_id : & PublicKey , user_channel_id : u128 ,
1766+ ) -> Result < ( ) , APIError > {
1767+ self . inner . channel_open_abandoned ( counterparty_node_id, user_channel_id)
1768+ }
1769+
1770+ /// Used to fail intercepted HTLCs backwards when a channel open attempt ultimately fails.
1771+ ///
1772+ /// Wraps [`LSPS2ServiceHandler::channel_open_failed`].
1773+ pub fn channel_open_failed (
1774+ & self , counterparty_node_id : & PublicKey , user_channel_id : u128 ,
1775+ ) -> Result < ( ) , APIError > {
1776+ self . inner . channel_open_failed ( counterparty_node_id, user_channel_id)
1777+ }
1778+
1779+ /// Forward [`Event::ChannelReady`] event parameters into this function.
1780+ ///
1781+ /// Wraps [`LSPS2ServiceHandler::channel_ready`].
1782+ ///
1783+ /// [`Event::ChannelReady`]: lightning::events::Event::ChannelReady
1784+ pub fn channel_ready (
1785+ & self , user_channel_id : u128 , channel_id : & ChannelId , counterparty_node_id : & PublicKey ,
1786+ ) -> Result < ( ) , APIError > {
1787+ self . inner . channel_ready ( user_channel_id, channel_id, counterparty_node_id)
1788+ }
1789+ }
1790+
16571791#[ cfg( test) ]
16581792mod tests {
16591793 use super :: * ;
0 commit comments