Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit b89b583

Browse files
committed
Fixup of previous commit (forgotten changes in build_raw)
1 parent ab629bb commit b89b583

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,11 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
375375
}
376376
self
377377
}
378+
}
378379

380+
impl<D: tb::Bool, H: tb::Bool> InvoiceBuilder<D, H, tb::True> {
379381
/// Builds a `RawInvoice` if no `CreationError` occurred while construction any of the fields.
380382
pub fn build_raw(self) -> Result<RawInvoice, CreationError> {
381-
use std::time::{SystemTime, UNIX_EPOCH};
382383

383384
// If an error occurred at any time before, return it now
384385
if let Some(e) = self.error {
@@ -391,12 +392,7 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
391392
si_prefix: self.si_prefix,
392393
};
393394

394-
let timestamp = self.timestamp.unwrap_or_else(|| {
395-
let now = SystemTime::now();
396-
let since_unix_epoch = now.duration_since(UNIX_EPOCH)
397-
.expect("it won't be 1970 ever again");
398-
since_unix_epoch.as_secs() as u64
399-
});
395+
let timestamp = self.timestamp.expect("ensured to be Some(t) by type T");
400396

401397
let tagged_fields = self.tagged_fields.into_iter().map(|tf| {
402398
RawTaggedField::KnownSemantics(tf)
@@ -1104,7 +1100,8 @@ mod test {
11041100

11051101
let builder = InvoiceBuilder::new(Currency::Bitcoin)
11061102
.description("Test".into())
1107-
.payment_hash([0;32]);
1103+
.payment_hash([0;32])
1104+
.current_timestamp();
11081105

11091106
let invoice = builder.clone()
11101107
.amount_pico_btc(15000)
@@ -1132,7 +1129,8 @@ mod test {
11321129
use secp256k1::Secp256k1;
11331130

11341131
let builder = InvoiceBuilder::new(Currency::Bitcoin)
1135-
.payment_hash([0;32]);
1132+
.payment_hash([0;32])
1133+
.current_timestamp();
11361134

11371135
let too_long_string = String::from_iter(
11381136
(0..1024).map(|_| '?')
@@ -1166,7 +1164,6 @@ mod test {
11661164

11671165
let sign_error_res = builder.clone()
11681166
.description("Test".into())
1169-
.current_timestamp()
11701167
.try_build_signed(|_| {
11711168
Err("ImaginaryError")
11721169
});

0 commit comments

Comments
 (0)