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