@@ -7,8 +7,8 @@ use crate::lsps0::client::LSPS0ClientHandler;
77use crate :: lsps0:: msgs:: LSPS0Message ;
88use crate :: lsps0:: ser:: {
99 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 ,
1212} ;
1313use crate :: lsps0:: service:: LSPS0ServiceHandler ;
1414use crate :: message_queue:: { MessageQueue , ProcessMessagesCallback } ;
@@ -128,7 +128,7 @@ where
128128 pub fn new (
129129 entropy_source : ES , channel_manager : CM , chain_source : Option < C > ,
130130 chain_params : Option < ChainParameters > , service_config : Option < LiquidityServiceConfig > ,
131- client_config : Option < LiquidityClientConfig > ,
131+ client_config : Option < LiquidityClientConfig > , time_provider : Option < Arc < dyn TimeProvider > > ,
132132 ) -> Self
133133where {
134134 let pending_messages = Arc :: new ( MessageQueue :: new ( ) ) ;
@@ -154,12 +154,32 @@ where {
154154 {
155155 supported_protocols. push ( number) ;
156156 }
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+ }
163183 } )
164184 } ) ;
165185
0 commit comments