Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions lightning-liquidity/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::lsps0::client::LSPS0ClientHandler;
use crate::lsps0::msgs::LSPS0Message;
use crate::lsps0::ser::{
LSPSMessage, LSPSMethod, LSPSProtocolMessageHandler, LSPSRequestId, LSPSResponseError,
RawLSPSMessage, JSONRPC_INVALID_MESSAGE_ERROR_CODE, JSONRPC_INVALID_MESSAGE_ERROR_MESSAGE,
LSPS_MESSAGE_TYPE_ID,
RawLSPSMessage, TimeProvider, JSONRPC_INVALID_MESSAGE_ERROR_CODE,
JSONRPC_INVALID_MESSAGE_ERROR_MESSAGE, LSPS_MESSAGE_TYPE_ID,
};
use crate::lsps0::service::LSPS0ServiceHandler;
use crate::message_queue::{MessageQueue, ProcessMessagesCallback};
Expand Down Expand Up @@ -128,7 +128,7 @@ where
pub fn new(
entropy_source: ES, channel_manager: CM, chain_source: Option<C>,
chain_params: Option<ChainParameters>, service_config: Option<LiquidityServiceConfig>,
client_config: Option<LiquidityClientConfig>,
client_config: Option<LiquidityClientConfig>, time_provider: Option<Arc<dyn TimeProvider>>,
) -> Self
where {
let pending_messages = Arc::new(MessageQueue::new());
Expand All @@ -154,12 +154,32 @@ where {
{
supported_protocols.push(number);
}
LSPS2ServiceHandler::new(
Arc::clone(&pending_messages),
Arc::clone(&pending_events),
channel_manager.clone(),
config.clone(),
)
if time_provider.is_some() {
// Always use custom time provider if provided
LSPS2ServiceHandler::new_with_custom_time_provider(
Arc::clone(&pending_messages),
Arc::clone(&pending_events),
channel_manager.clone(),
config.clone(),
time_provider.unwrap(),
)
} else {
#[cfg(feature = "time")]
{
// Use default new if time feature is enabled and no custom provider
LSPS2ServiceHandler::new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't TimeProvider be simply required here (no option), and then instantiate or panic higher up in the call stack? Also no need for two new variants then.

Arc::clone(&pending_messages),
Arc::clone(&pending_events),
channel_manager.clone(),
config.clone(),
)
}
#[cfg(not(feature = "time"))]
{
// Panic if no time provider and time feature is not enabled
panic!("A custom time_provider must be provided if the 'time' feature is not enabled.");
}
}
})
});

Expand Down
1 change: 1 addition & 0 deletions lightning-liquidity/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ pub(crate) fn create_liquidity_node(
Some(chain_params),
service_config,
client_config,
None,
));
let msg_handler = MessageHandler {
chan_handler: Arc::new(test_utils::TestChannelMessageHandler::new(
Expand Down
Loading