@@ -12,6 +12,8 @@ use crate::lsps0::ser::{
12
12
use crate :: lsps0:: service:: LSPS0ServiceHandler ;
13
13
use crate :: lsps5:: client:: { LSPS5ClientConfig , LSPS5ClientHandler } ;
14
14
use crate :: lsps5:: msgs:: LSPS5Message ;
15
+ #[ cfg( feature = "time" ) ]
16
+ use crate :: lsps5:: service:: DefaultTimeProvider ;
15
17
use crate :: lsps5:: service:: { LSPS5ServiceConfig , LSPS5ServiceHandler , TimeProvider } ;
16
18
use crate :: message_queue:: MessageQueue ;
17
19
@@ -169,10 +171,34 @@ where
169
171
///
170
172
/// Sets up the required protocol message handlers based on the given
171
173
/// [`LiquidityClientConfig`] and [`LiquidityServiceConfig`].
174
+ #[ cfg( feature = "time" ) ]
172
175
pub fn new (
173
176
entropy_source : ES , channel_manager : CM , chain_source : Option < C > ,
174
177
chain_params : Option < ChainParameters > , service_config : Option < LiquidityServiceConfig > ,
175
- client_config : Option < LiquidityClientConfig > , time_provider : Option < Arc < dyn TimeProvider > > ,
178
+ client_config : Option < LiquidityClientConfig > ,
179
+ ) -> Self {
180
+ let time_provider = Arc :: new ( DefaultTimeProvider ) ;
181
+ Self :: new_with_custom_time_provider (
182
+ entropy_source,
183
+ channel_manager,
184
+ chain_source,
185
+ chain_params,
186
+ service_config,
187
+ client_config,
188
+ time_provider,
189
+ )
190
+ }
191
+
192
+ /// Constructor for the [`LiquidityManager`] with a custom time provider.
193
+ ///
194
+ /// This should be used on non-std platforms where access to the system time is not
195
+ /// available.
196
+ /// Sets up the required protocol message handlers based on the given
197
+ /// [`LiquidityClientConfig`] and [`LiquidityServiceConfig`].
198
+ pub fn new_with_custom_time_provider (
199
+ entropy_source : ES , channel_manager : CM , chain_source : Option < C > ,
200
+ chain_params : Option < ChainParameters > , service_config : Option < LiquidityServiceConfig > ,
201
+ client_config : Option < LiquidityClientConfig > , time_provider : Arc < dyn TimeProvider > ,
176
202
) -> Self
177
203
where {
178
204
let pending_messages = Arc :: new ( MessageQueue :: new ( ) ) ;
@@ -182,7 +208,7 @@ where {
182
208
let mut supported_protocols = Vec :: new ( ) ;
183
209
184
210
let lsps2_client_handler = client_config. as_ref ( ) . and_then ( |config| {
185
- config. lsps2_client_config . as_ref ( ) . map ( |config| {
211
+ config. lsps2_client_config . map ( |config| {
186
212
LSPS2ClientHandler :: new (
187
213
entropy_source. clone ( ) ,
188
214
Arc :: clone ( & pending_messages) ,
@@ -209,29 +235,13 @@ where {
209
235
210
236
let lsps5_client_handler = client_config. as_ref ( ) . and_then ( |config| {
211
237
config. lsps5_client_config . as_ref ( ) . map ( |config| {
212
- if time_provider. is_some ( ) {
213
- LSPS5ClientHandler :: new_with_custom_time_provider (
214
- entropy_source. clone ( ) ,
215
- Arc :: clone ( & pending_messages) ,
216
- Arc :: clone ( & pending_events) ,
217
- config. clone ( ) ,
218
- time_provider. clone ( ) . unwrap ( ) ,
219
- )
220
- } else {
221
- #[ cfg( feature = "time" ) ]
222
- {
223
- LSPS5ClientHandler :: new (
224
- entropy_source. clone ( ) ,
225
- Arc :: clone ( & pending_messages) ,
226
- Arc :: clone ( & pending_events) ,
227
- config. clone ( ) ,
228
- )
229
- }
230
- #[ cfg( not( feature = "time" ) ) ]
231
- {
232
- panic ! ( "A custom time_provider must be provided if the 'time' feature is not enabled." ) ;
233
- }
234
- }
238
+ LSPS5ClientHandler :: new (
239
+ entropy_source. clone ( ) ,
240
+ Arc :: clone ( & pending_messages) ,
241
+ Arc :: clone ( & pending_events) ,
242
+ config. clone ( ) ,
243
+ time_provider. clone ( ) ,
244
+ )
235
245
} )
236
246
} ) ;
237
247
@@ -243,29 +253,13 @@ where {
243
253
supported_protocols. push ( number) ;
244
254
}
245
255
246
- if time_provider. is_some ( ) {
247
- return LSPS5ServiceHandler :: new_with_custom_time_provider (
248
- Arc :: clone ( & pending_events) ,
249
- Arc :: clone ( & pending_messages) ,
250
- channel_manager. clone ( ) ,
251
- config. clone ( ) ,
252
- time_provider. unwrap ( ) ,
253
- ) ;
254
- } else {
255
- #[ cfg( feature = "time" ) ]
256
- {
257
- return LSPS5ServiceHandler :: new (
258
- Arc :: clone ( & pending_events) ,
259
- Arc :: clone ( & pending_messages) ,
260
- channel_manager. clone ( ) ,
261
- config. clone ( ) ,
262
- ) ;
263
- }
264
- #[ cfg( not( feature = "time" ) ) ]
265
- {
266
- panic ! ( "A custom time_provider must be provided if the 'time' feature is not enabled." ) ;
267
- }
268
- }
256
+ return LSPS5ServiceHandler :: new (
257
+ Arc :: clone ( & pending_events) ,
258
+ Arc :: clone ( & pending_messages) ,
259
+ channel_manager. clone ( ) ,
260
+ config. clone ( ) ,
261
+ time_provider,
262
+ ) ;
269
263
} )
270
264
} ) ;
271
265
0 commit comments