@@ -375,10 +375,11 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
375
375
}
376
376
self
377
377
}
378
+ }
378
379
380
+ impl < D : tb:: Bool , H : tb:: Bool > InvoiceBuilder < D , H , tb:: True > {
379
381
/// Builds a `RawInvoice` if no `CreationError` occurred while construction any of the fields.
380
382
pub fn build_raw ( self ) -> Result < RawInvoice , CreationError > {
381
- use std:: time:: { SystemTime , UNIX_EPOCH } ;
382
383
383
384
// If an error occurred at any time before, return it now
384
385
if let Some ( e) = self . error {
@@ -391,12 +392,7 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
391
392
si_prefix : self . si_prefix ,
392
393
} ;
393
394
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" ) ;
400
396
401
397
let tagged_fields = self . tagged_fields . into_iter ( ) . map ( |tf| {
402
398
RawTaggedField :: KnownSemantics ( tf)
@@ -1104,7 +1100,8 @@ mod test {
1104
1100
1105
1101
let builder = InvoiceBuilder :: new ( Currency :: Bitcoin )
1106
1102
. description ( "Test" . into ( ) )
1107
- . payment_hash ( [ 0 ; 32 ] ) ;
1103
+ . payment_hash ( [ 0 ; 32 ] )
1104
+ . current_timestamp ( ) ;
1108
1105
1109
1106
let invoice = builder. clone ( )
1110
1107
. amount_pico_btc ( 15000 )
@@ -1132,7 +1129,8 @@ mod test {
1132
1129
use secp256k1:: Secp256k1 ;
1133
1130
1134
1131
let builder = InvoiceBuilder :: new ( Currency :: Bitcoin )
1135
- . payment_hash ( [ 0 ; 32 ] ) ;
1132
+ . payment_hash ( [ 0 ; 32 ] )
1133
+ . current_timestamp ( ) ;
1136
1134
1137
1135
let too_long_string = String :: from_iter (
1138
1136
( 0 ..1024 ) . map ( |_| '?' )
@@ -1166,7 +1164,6 @@ mod test {
1166
1164
1167
1165
let sign_error_res = builder. clone ( )
1168
1166
. description ( "Test" . into ( ) )
1169
- . current_timestamp ( )
1170
1167
. try_build_signed ( |_| {
1171
1168
Err ( "ImaginaryError" )
1172
1169
} ) ;
0 commit comments