Skip to content

Commit c2e2aa6

Browse files
committed
f - Use u64 instead of Duration for Payee::expiry_time
1 parent 177e0f1 commit c2e2aa6

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

lightning-invoice/src/payment.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ where
227227
hash_map::Entry::Vacant(entry) => {
228228
let payer = self.payer.node_id();
229229
let mut payee = Payee::new(invoice.recover_payee_pub_key())
230-
.with_expiry_time(expiry_time_from_unix_epoch(&invoice))
230+
.with_expiry_time(expiry_time_from_unix_epoch(&invoice).as_secs())
231231
.with_route_hints(invoice.route_hints());
232232
if let Some(features) = invoice.features() {
233233
payee = payee.with_features(features.clone());
@@ -280,7 +280,8 @@ fn expiry_time_from_unix_epoch(invoice: &Invoice) -> Duration {
280280
}
281281

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

286287
impl<P: Deref, R, L: Deref, E> EventHandler for InvoicePayer<P, R, L, E>
@@ -858,7 +859,7 @@ mod tests {
858859

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

lightning/src/routing/router.rs

+4-5
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

-14
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)