@@ -7,8 +7,8 @@ use crate::lsps0::client::LSPS0ClientHandler;
7
7
use crate :: lsps0:: msgs:: LSPS0Message ;
8
8
use crate :: lsps0:: ser:: {
9
9
LSPSMessage , LSPSMethod , LSPSProtocolMessageHandler , LSPSRequestId , LSPSResponseError ,
10
- RawLSPSMessage , JSONRPC_INVALID_MESSAGE_ERROR_CODE , JSONRPC_INVALID_MESSAGE_ERROR_MESSAGE ,
11
- LSPS_MESSAGE_TYPE_ID ,
10
+ RawLSPSMessage , TimeProvider , JSONRPC_INVALID_MESSAGE_ERROR_CODE ,
11
+ JSONRPC_INVALID_MESSAGE_ERROR_MESSAGE , LSPS_MESSAGE_TYPE_ID ,
12
12
} ;
13
13
use crate :: lsps0:: service:: LSPS0ServiceHandler ;
14
14
use crate :: message_queue:: { MessageQueue , ProcessMessagesCallback } ;
@@ -128,7 +128,7 @@ where
128
128
pub fn new (
129
129
entropy_source : ES , channel_manager : CM , chain_source : Option < C > ,
130
130
chain_params : Option < ChainParameters > , service_config : Option < LiquidityServiceConfig > ,
131
- client_config : Option < LiquidityClientConfig > ,
131
+ client_config : Option < LiquidityClientConfig > , time_provider : Option < Arc < dyn TimeProvider > > ,
132
132
) -> Self
133
133
where {
134
134
let pending_messages = Arc :: new ( MessageQueue :: new ( ) ) ;
@@ -154,12 +154,32 @@ where {
154
154
{
155
155
supported_protocols. push ( number) ;
156
156
}
157
- LSPS2ServiceHandler :: new (
158
- Arc :: clone ( & pending_messages) ,
159
- Arc :: clone ( & pending_events) ,
160
- channel_manager. clone ( ) ,
161
- config. clone ( ) ,
162
- )
157
+ if time_provider. is_some ( ) {
158
+ // Always use custom time provider if provided
159
+ LSPS2ServiceHandler :: new_with_custom_time_provider (
160
+ Arc :: clone ( & pending_messages) ,
161
+ Arc :: clone ( & pending_events) ,
162
+ channel_manager. clone ( ) ,
163
+ config. clone ( ) ,
164
+ time_provider. unwrap ( ) ,
165
+ )
166
+ } else {
167
+ #[ cfg( feature = "time" ) ]
168
+ {
169
+ // Use default new if time feature is enabled and no custom provider
170
+ LSPS2ServiceHandler :: new (
171
+ Arc :: clone ( & pending_messages) ,
172
+ Arc :: clone ( & pending_events) ,
173
+ channel_manager. clone ( ) ,
174
+ config. clone ( ) ,
175
+ )
176
+ }
177
+ #[ cfg( not( feature = "time" ) ) ]
178
+ {
179
+ // Panic if no time provider and time feature is not enabled
180
+ panic ! ( "A custom time_provider must be provided if the 'time' feature is not enabled." ) ;
181
+ }
182
+ }
163
183
} )
164
184
} ) ;
165
185
0 commit comments