Skip to content

Commit 78d17b9

Browse files
Fix CI
1 parent e66d6ea commit 78d17b9

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

lightning-liquidity/src/lsps5/client.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ use core::ops::Deref;
2828
use crate::prelude::{new_hash_map, HashMap, String};
2929

3030
use super::msgs::{Lsps5AppName, Lsps5WebhookUrl};
31-
use super::service::{from_rfc3339, DefaultTimeProvider, TimeProvider};
31+
#[cfg(feature = "std")]
32+
use super::service::DefaultTimeProvider;
33+
use super::service::{from_rfc3339, TimeProvider};
3234
use super::url_utils::Url;
3335
use core::time::Duration;
3436
use lightning::sign::EntropySource;
@@ -43,22 +45,25 @@ pub struct LSPS5ClientConfig {
4345
/// Maximum age in seconds for cached responses (default: 3600 - 1 hour)
4446
pub response_max_age_secs: u64,
4547
/// Time provider for LSPS5 service
46-
pub time_provider: Arc<dyn TimeProvider>,
48+
pub time_provider: Option<Arc<dyn TimeProvider>>,
4749
}
4850

4951
impl Default for LSPS5ClientConfig {
5052
fn default() -> Self {
5153
Self {
5254
response_max_age_secs: DEFAULT_RESPONSE_MAX_AGE_SECS,
53-
time_provider: Arc::new(DefaultTimeProvider),
55+
#[cfg(feature = "std")]
56+
time_provider: Some(Arc::new(DefaultTimeProvider)),
57+
#[cfg(not(feature = "std"))]
58+
time_provider: None,
5459
}
5560
}
5661
}
5762

5863
impl LSPS5ClientConfig {
5964
/// Set a custom time provider for the LSPS5 service
6065
pub fn with_time_provider(mut self, time_provider: impl TimeProvider + 'static) -> Self {
61-
self.time_provider = Arc::new(time_provider);
66+
self.time_provider = Some(Arc::new(time_provider));
6267
self
6368
}
6469
}
@@ -136,9 +141,9 @@ where
136141
/// event queue, and LSPS5ClientConfig
137142
pub(crate) fn new(
138143
entropy_source: ES, pending_messages: Arc<MessageQueue>, pending_events: Arc<EventQueue>,
139-
config: LSPS5ClientConfig,
144+
mut config: LSPS5ClientConfig,
140145
) -> Self {
141-
let time_provider = config.time_provider.clone();
146+
let time_provider = config.time_provider.take().expect("Time provider should be present");
142147
Self {
143148
pending_messages,
144149
pending_events,
@@ -525,12 +530,12 @@ where
525530
Ok(timestamp_dt) => {
526531
// Check timestamp is within 10 minutes of current time
527532
let now = time_provider.now();
528-
let diff;
529-
if now > timestamp_dt {
530-
diff = now.checked_sub(timestamp_dt).unwrap();
533+
534+
let diff = if now > timestamp_dt {
535+
now.checked_sub(timestamp_dt).unwrap()
531536
} else {
532-
diff = timestamp_dt.checked_sub(now).unwrap();
533-
}
537+
timestamp_dt.checked_sub(now).unwrap()
538+
};
534539
if diff > Duration::from_secs(600) {
535540
// 10 minutes
536541
return Err(LightningError {

lightning-liquidity/src/lsps5/service.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub struct LSPS5ServiceConfig {
192192
/// Configuration for signature storage
193193
pub signature_config: SignatureStorageConfig,
194194
/// Time provider for LSPS5 service
195-
pub time_provider: Arc<dyn TimeProvider>,
195+
pub time_provider: Option<Arc<dyn TimeProvider>>,
196196
/// HTTP client for webhook delivery
197197
#[doc(hidden)] // Hide from docs since it uses Arc and can't be directly created
198198
pub(crate) http_client: Option<Arc<dyn HttpClient>>,
@@ -206,7 +206,10 @@ impl Default for LSPS5ServiceConfig {
206206
notification_cooldown_hours: 24,
207207
signature_config: SignatureStorageConfig::default(),
208208
http_client: None,
209-
time_provider: Arc::new(DefaultTimeProvider),
209+
#[cfg(feature = "std")]
210+
time_provider: Some(Arc::new(DefaultTimeProvider)),
211+
#[cfg(not(feature = "std"))]
212+
time_provider: None,
210213
}
211214
}
212215
}
@@ -220,7 +223,7 @@ impl LSPS5ServiceConfig {
220223

221224
/// Set a custom time provider for the LSPS5 service
222225
pub fn with_time_provider(mut self, time_provider: impl TimeProvider + 'static) -> Self {
223-
self.time_provider = Arc::new(time_provider);
226+
self.time_provider = Some(Arc::new(time_provider));
224227
self
225228
}
226229
}
@@ -268,7 +271,7 @@ impl LSPS5ServiceHandler {
268271
let http_client: Arc<dyn HttpClient> =
269272
config.http_client.take().expect("HTTP client should be present");
270273
let max_signatures = config.signature_config.max_signatures.clone();
271-
let time_provider = config.time_provider.clone();
274+
let time_provider = config.time_provider.take().expect("Time provider should be present");
272275
Self {
273276
config,
274277
webhooks: Arc::new(Mutex::new(new_hash_map())),

0 commit comments

Comments
 (0)