@@ -94,24 +94,31 @@ pub trait ALiquidityManager {
94
94
type Filter : Filter + ?Sized ;
95
95
/// A type that may be dereferenced to [`Self::Filter`].
96
96
type C : Deref < Target = Self :: Filter > + Clone ;
97
+ /// A type implementing [`TimeProvider`].
98
+ type TimeProvider : TimeProvider + ?Sized ;
99
+ /// A type that may be dereferenced to [`Self::TimeProvider`].
100
+ type TP : Deref < Target = Self :: TimeProvider > + Clone ;
97
101
/// Returns a reference to the actual [`LiquidityManager`] object.
98
- fn get_lm ( & self ) -> & LiquidityManager < Self :: ES , Self :: CM , Self :: C > ;
102
+ fn get_lm ( & self ) -> & LiquidityManager < Self :: ES , Self :: CM , Self :: C , Self :: TP > ;
99
103
}
100
104
101
- impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone > ALiquidityManager
102
- for LiquidityManager < ES , CM , C >
105
+ impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone , TP : Deref + Clone > ALiquidityManager
106
+ for LiquidityManager < ES , CM , C , TP >
103
107
where
104
108
ES :: Target : EntropySource ,
105
109
CM :: Target : AChannelManager ,
106
110
C :: Target : Filter ,
111
+ TP :: Target : TimeProvider ,
107
112
{
108
113
type EntropySource = ES :: Target ;
109
114
type ES = ES ;
110
115
type AChannelManager = CM :: Target ;
111
116
type CM = CM ;
112
117
type Filter = C :: Target ;
113
118
type C = C ;
114
- fn get_lm ( & self ) -> & LiquidityManager < ES , CM , C > {
119
+ type TimeProvider = TP :: Target ;
120
+ type TP = TP ;
121
+ fn get_lm ( & self ) -> & LiquidityManager < ES , CM , C , TP > {
115
122
self
116
123
}
117
124
}
@@ -135,11 +142,16 @@ where
135
142
/// [`Event::ChannelReady`]: lightning::events::Event::ChannelReady
136
143
/// [`Event::HTLCHandlingFailed`]: lightning::events::Event::HTLCHandlingFailed
137
144
/// [`Event::PaymentForwarded`]: lightning::events::Event::PaymentForwarded
138
- pub struct LiquidityManager < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone >
139
- where
145
+ pub struct LiquidityManager <
146
+ ES : Deref + Clone ,
147
+ CM : Deref + Clone ,
148
+ C : Deref + Clone ,
149
+ TP : Deref + Clone ,
150
+ > where
140
151
ES :: Target : EntropySource ,
141
152
CM :: Target : AChannelManager ,
142
153
C :: Target : Filter ,
154
+ TP :: Target : TimeProvider ,
143
155
{
144
156
pending_messages : Arc < MessageQueue > ,
145
157
pending_events : Arc < EventQueue > ,
@@ -153,25 +165,23 @@ where
153
165
lsps1_client_handler : Option < LSPS1ClientHandler < ES > > ,
154
166
lsps2_service_handler : Option < LSPS2ServiceHandler < CM > > ,
155
167
lsps2_client_handler : Option < LSPS2ClientHandler < ES > > ,
156
- lsps5_service_handler : Option < LSPS5ServiceHandler < CM > > ,
157
- lsps5_client_handler : Option < LSPS5ClientHandler < ES > > ,
168
+ lsps5_service_handler : Option < LSPS5ServiceHandler < CM , TP > > ,
169
+ lsps5_client_handler : Option < LSPS5ClientHandler < ES , TP > > ,
158
170
service_config : Option < LiquidityServiceConfig > ,
159
171
_client_config : Option < LiquidityClientConfig > ,
160
172
best_block : RwLock < Option < BestBlock > > ,
161
173
_chain_source : Option < C > ,
162
174
}
163
175
164
- impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone > LiquidityManager < ES , CM , C >
176
+ #[ cfg( feature = "time" ) ]
177
+ impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone >
178
+ LiquidityManager < ES , CM , C , Arc < DefaultTimeProvider > >
165
179
where
166
180
ES :: Target : EntropySource ,
167
181
CM :: Target : AChannelManager ,
168
182
C :: Target : Filter ,
169
183
{
170
- /// Constructor for the [`LiquidityManager`].
171
- ///
172
- /// Sets up the required protocol message handlers based on the given
173
- /// [`LiquidityClientConfig`] and [`LiquidityServiceConfig`].
174
- #[ cfg( feature = "time" ) ]
184
+ /// Constructor for the [`LiquidityManager`] using the default system clock
175
185
pub fn new (
176
186
entropy_source : ES , channel_manager : CM , chain_source : Option < C > ,
177
187
chain_params : Option < ChainParameters > , service_config : Option < LiquidityServiceConfig > ,
@@ -188,7 +198,16 @@ where
188
198
time_provider,
189
199
)
190
200
}
201
+ }
191
202
203
+ impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone , TP : Deref + Clone >
204
+ LiquidityManager < ES , CM , C , TP >
205
+ where
206
+ ES :: Target : EntropySource ,
207
+ CM :: Target : AChannelManager ,
208
+ C :: Target : Filter ,
209
+ TP :: Target : TimeProvider ,
210
+ {
192
211
/// Constructor for the [`LiquidityManager`] with a custom time provider.
193
212
///
194
213
/// This should be used on non-std platforms where access to the system time is not
@@ -198,9 +217,8 @@ where
198
217
pub fn new_with_custom_time_provider (
199
218
entropy_source : ES , channel_manager : CM , chain_source : Option < C > ,
200
219
chain_params : Option < ChainParameters > , service_config : Option < LiquidityServiceConfig > ,
201
- client_config : Option < LiquidityClientConfig > , time_provider : Arc < dyn TimeProvider > ,
202
- ) -> Self
203
- where {
220
+ client_config : Option < LiquidityClientConfig > , time_provider : TP ,
221
+ ) -> Self {
204
222
let pending_messages = Arc :: new ( MessageQueue :: new ( ) ) ;
205
223
let pending_events = Arc :: new ( EventQueue :: new ( ) ) ;
206
224
let ignored_peers = RwLock :: new ( new_hash_set ( ) ) ;
@@ -248,7 +266,7 @@ where {
248
266
let lsps5_service_handler = service_config. as_ref ( ) . and_then ( |config| {
249
267
config. lsps5_service_config . as_ref ( ) . map ( |config| {
250
268
if let Some ( number) =
251
- <LSPS5ServiceHandler < CM > as LSPSProtocolMessageHandler >:: PROTOCOL_NUMBER
269
+ <LSPS5ServiceHandler < CM , TP > as LSPSProtocolMessageHandler >:: PROTOCOL_NUMBER
252
270
{
253
271
supported_protocols. push ( number) ;
254
272
}
@@ -369,14 +387,14 @@ where {
369
387
/// Returns a reference to the LSPS5 client-side handler.
370
388
///
371
389
/// The returned hendler allows to initiate the LSPS5 client-side flow. That is, it allows to
372
- pub fn lsps5_client_handler ( & self ) -> Option < & LSPS5ClientHandler < ES > > {
390
+ pub fn lsps5_client_handler ( & self ) -> Option < & LSPS5ClientHandler < ES , TP > > {
373
391
self . lsps5_client_handler . as_ref ( )
374
392
}
375
393
376
394
/// Returns a reference to the LSPS5 server-side handler.
377
395
///
378
396
/// The returned hendler allows to initiate the LSPS5 service-side flow.
379
- pub fn lsps5_service_handler ( & self ) -> Option < & LSPS5ServiceHandler < CM > > {
397
+ pub fn lsps5_service_handler ( & self ) -> Option < & LSPS5ServiceHandler < CM , TP > > {
380
398
self . lsps5_service_handler . as_ref ( )
381
399
}
382
400
@@ -530,12 +548,13 @@ where {
530
548
}
531
549
}
532
550
533
- impl < ES : Deref + Clone + Clone , CM : Deref + Clone , C : Deref + Clone > CustomMessageReader
534
- for LiquidityManager < ES , CM , C >
551
+ impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone , TP : Deref + Clone > CustomMessageReader
552
+ for LiquidityManager < ES , CM , C , TP >
535
553
where
536
554
ES :: Target : EntropySource ,
537
555
CM :: Target : AChannelManager ,
538
556
C :: Target : Filter ,
557
+ TP :: Target : TimeProvider ,
539
558
{
540
559
type CustomMessage = RawLSPSMessage ;
541
560
@@ -551,12 +570,13 @@ where
551
570
}
552
571
}
553
572
554
- impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone > CustomMessageHandler
555
- for LiquidityManager < ES , CM , C >
573
+ impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone , TP : Deref + Clone > CustomMessageHandler
574
+ for LiquidityManager < ES , CM , C , TP >
556
575
where
557
576
ES :: Target : EntropySource ,
558
577
CM :: Target : AChannelManager ,
559
578
C :: Target : Filter ,
579
+ TP :: Target : TimeProvider ,
560
580
{
561
581
fn handle_custom_message (
562
582
& self , msg : Self :: CustomMessage , sender_node_id : PublicKey ,
@@ -663,11 +683,13 @@ where
663
683
}
664
684
}
665
685
666
- impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone > Listen for LiquidityManager < ES , CM , C >
686
+ impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone , TP : Deref + Clone > Listen
687
+ for LiquidityManager < ES , CM , C , TP >
667
688
where
668
689
ES :: Target : EntropySource ,
669
690
CM :: Target : AChannelManager ,
670
691
C :: Target : Filter ,
692
+ TP :: Target : TimeProvider ,
671
693
{
672
694
fn filtered_block_connected (
673
695
& self , header : & bitcoin:: block:: Header , txdata : & chain:: transaction:: TransactionData ,
@@ -700,11 +722,13 @@ where
700
722
}
701
723
}
702
724
703
- impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone > Confirm for LiquidityManager < ES , CM , C >
725
+ impl < ES : Deref + Clone , CM : Deref + Clone , C : Deref + Clone , TP : Deref + Clone > Confirm
726
+ for LiquidityManager < ES , CM , C , TP >
704
727
where
705
728
ES :: Target : EntropySource ,
706
729
CM :: Target : AChannelManager ,
707
730
C :: Target : Filter ,
731
+ TP :: Target : TimeProvider ,
708
732
{
709
733
fn transactions_confirmed (
710
734
& self , _header : & bitcoin:: block:: Header , _txdata : & chain:: transaction:: TransactionData ,
0 commit comments