Skip to content

Commit 55d089e

Browse files
committed
f - Use u64 instead of Duration for Payee::expiry_time
1 parent 1d3edeb commit 55d089e

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

lightning-invoice/src/payment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ where
226226
hash_map::Entry::Vacant(entry) => {
227227
let payer = self.payer.node_id();
228228
let mut payee = Payee::new(invoice.recover_payee_pub_key())
229-
.with_expiry_time(expiry_time_from_unix_epoch(&invoice))
229+
.with_expiry_time(expiry_time_from_unix_epoch(&invoice).as_secs())
230230
.with_route_hints(invoice.route_hints());
231231
if let Some(features) = invoice.features() {
232232
payee = payee.with_features(features.clone());
@@ -279,7 +279,8 @@ fn expiry_time_from_unix_epoch(invoice: &Invoice) -> Duration {
279279
}
280280

281281
fn has_expired(params: &RouteParameters) -> bool {
282-
Invoice::is_expired_from_epoch(&SystemTime::UNIX_EPOCH, params.payee.expiry_time.unwrap())
282+
let expiry_time = Duration::from_secs(params.payee.expiry_time.unwrap());
283+
Invoice::is_expired_from_epoch(&SystemTime::UNIX_EPOCH, expiry_time)
283284
}
284285

285286
impl<P: Deref, R, L: Deref, E> EventHandler for InvoicePayer<P, R, L, E>
@@ -857,7 +858,7 @@ mod tests {
857858

858859
fn retry_for_invoice(invoice: &Invoice) -> RouteParameters {
859860
let mut payee = Payee::new(invoice.recover_payee_pub_key())
860-
.with_expiry_time(expiry_time_from_unix_epoch(invoice))
861+
.with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
861862
.with_route_hints(invoice.route_hints());
862863
if let Some(features) = invoice.features() {
863864
payee = payee.with_features(features.clone());

lightning/src/routing/router.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use prelude::*;
2727
use alloc::collections::BinaryHeap;
2828
use core::cmp;
2929
use core::ops::Deref;
30-
use core::time::Duration;
3130

3231
/// A hop in a route
3332
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
@@ -182,8 +181,8 @@ pub struct Payee {
182181
/// Hints for routing to the payee, containing channels connecting the payee to public nodes.
183182
pub route_hints: Vec<RouteHint>,
184183

185-
/// Expiration of a payment to the payee, relative to a user-defined epoch.
186-
pub expiry_time: Option<Duration>,
184+
/// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
185+
pub expiry_time: Option<u64>,
187186
}
188187

189188
impl_writeable_tlv_based!(Payee, {
@@ -223,8 +222,8 @@ impl Payee {
223222
Self { route_hints, ..self }
224223
}
225224

226-
/// Includes a payment expiration relative to a user-defined epoch.
227-
pub fn with_expiry_time(self, expiry_time: Duration) -> Self {
225+
/// Includes a payment expiration in seconds relative to the UNIX epoch.
226+
pub fn with_expiry_time(self, expiry_time: u64) -> Self {
228227
Self { expiry_time: Some(expiry_time), ..self }
229228
}
230229
}

lightning/src/util/ser.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use bitcoin::consensus::Encodable;
2727
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
2828
use bitcoin::hash_types::{Txid, BlockHash};
2929
use core::marker::Sized;
30-
use core::time::Duration;
3130
use ln::msgs::DecodeError;
3231
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
3332

@@ -912,16 +911,3 @@ impl Readable for String {
912911
Ok(ret)
913912
}
914913
}
915-
916-
impl Writeable for Duration {
917-
#[inline]
918-
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
919-
self.as_secs().write(w)
920-
}
921-
}
922-
impl Readable for Duration {
923-
#[inline]
924-
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
925-
Ok(Duration::from_secs(Readable::read(r)?))
926-
}
927-
}

0 commit comments

Comments
 (0)