@@ -146,6 +146,7 @@ pub fn check_platform() {
146
146
/// .description("Coins pls!".into())
147
147
/// .payment_hash(payment_hash)
148
148
/// .current_timestamp()
149
+ /// .min_final_cltv_expiry(144)
149
150
/// .build_signed(|hash| {
150
151
/// Secp256k1::new().sign_recoverable(hash, &private_key)
151
152
/// })
@@ -162,7 +163,7 @@ pub fn check_platform() {
162
163
/// * `H`: exactly one `PaymentHash`
163
164
/// * `T`: the timestamp is set
164
165
#[ derive( Eq , PartialEq , Debug , Clone ) ]
165
- pub struct InvoiceBuilder < D : tb:: Bool , H : tb:: Bool , T : tb:: Bool > {
166
+ pub struct InvoiceBuilder < D : tb:: Bool , H : tb:: Bool , T : tb:: Bool , C : tb :: Bool > {
166
167
currency : Currency ,
167
168
amount : Option < u64 > ,
168
169
si_prefix : Option < SiPrefix > ,
@@ -173,6 +174,7 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool> {
173
174
phantom_d : std:: marker:: PhantomData < D > ,
174
175
phantom_h : std:: marker:: PhantomData < H > ,
175
176
phantom_t : std:: marker:: PhantomData < T > ,
177
+ phantom_c : std:: marker:: PhantomData < C > ,
176
178
}
177
179
178
180
/// Represents a syntactically and semantically correct lightning BOLT11 invoice.
@@ -416,7 +418,7 @@ pub mod constants {
416
418
pub const TAG_FEATURES : u8 = 5 ;
417
419
}
418
420
419
- impl InvoiceBuilder < tb:: False , tb:: False , tb:: False > {
421
+ impl InvoiceBuilder < tb:: False , tb:: False , tb:: False , tb :: False > {
420
422
/// Construct new, empty `InvoiceBuilder`. All necessary fields have to be filled first before
421
423
/// `InvoiceBuilder::build(self)` becomes available.
422
424
pub fn new ( currrency : Currency ) -> Self {
@@ -431,14 +433,15 @@ impl InvoiceBuilder<tb::False, tb::False, tb::False> {
431
433
phantom_d : std:: marker:: PhantomData ,
432
434
phantom_h : std:: marker:: PhantomData ,
433
435
phantom_t : std:: marker:: PhantomData ,
436
+ phantom_c : std:: marker:: PhantomData ,
434
437
}
435
438
}
436
439
}
437
440
438
- impl < D : tb:: Bool , H : tb:: Bool , T : tb:: Bool > InvoiceBuilder < D , H , T > {
441
+ impl < D : tb:: Bool , H : tb:: Bool , T : tb:: Bool , C : tb :: Bool > InvoiceBuilder < D , H , T , C > {
439
442
/// Helper function to set the completeness flags.
440
- fn set_flags < DN : tb:: Bool , HN : tb:: Bool , TN : tb:: Bool > ( self ) -> InvoiceBuilder < DN , HN , TN > {
441
- InvoiceBuilder :: < DN , HN , TN > {
443
+ fn set_flags < DN : tb:: Bool , HN : tb:: Bool , TN : tb:: Bool , CN : tb :: Bool > ( self ) -> InvoiceBuilder < DN , HN , TN , CN > {
444
+ InvoiceBuilder :: < DN , HN , TN , CN > {
442
445
currency : self . currency ,
443
446
amount : self . amount ,
444
447
si_prefix : self . si_prefix ,
@@ -449,6 +452,7 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
449
452
phantom_d : std:: marker:: PhantomData ,
450
453
phantom_h : std:: marker:: PhantomData ,
451
454
phantom_t : std:: marker:: PhantomData ,
455
+ phantom_c : std:: marker:: PhantomData ,
452
456
}
453
457
}
454
458
@@ -484,12 +488,6 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
484
488
self
485
489
}
486
490
487
- /// Sets `min_final_cltv_expiry`.
488
- pub fn min_final_cltv_expiry ( mut self , min_final_cltv_expiry : u64 ) -> Self {
489
- self . tagged_fields . push ( TaggedField :: MinFinalCltvExpiry ( MinFinalCltvExpiry ( min_final_cltv_expiry) ) ) ;
490
- self
491
- }
492
-
493
491
/// Adds a fallback address.
494
492
pub fn fallback ( mut self , fallback : Fallback ) -> Self {
495
493
self . tagged_fields . push ( TaggedField :: Fallback ( fallback) ) ;
@@ -513,7 +511,7 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
513
511
}
514
512
}
515
513
516
- impl < D : tb:: Bool , H : tb:: Bool > InvoiceBuilder < D , H , tb:: True > {
514
+ impl < D : tb:: Bool , H : tb:: Bool , C : tb :: Bool > InvoiceBuilder < D , H , tb:: True , C > {
517
515
/// Builds a `RawInvoice` if no `CreationError` occurred while construction any of the fields.
518
516
pub fn build_raw ( self ) -> Result < RawInvoice , CreationError > {
519
517
@@ -546,9 +544,9 @@ impl<D: tb::Bool, H: tb::Bool> InvoiceBuilder<D, H, tb::True> {
546
544
}
547
545
}
548
546
549
- impl < H : tb:: Bool , T : tb:: Bool > InvoiceBuilder < tb:: False , H , T > {
547
+ impl < H : tb:: Bool , T : tb:: Bool , C : tb :: Bool > InvoiceBuilder < tb:: False , H , T , C > {
550
548
/// Set the description. This function is only available if no description (hash) was set.
551
- pub fn description ( mut self , description : String ) -> InvoiceBuilder < tb:: True , H , T > {
549
+ pub fn description ( mut self , description : String ) -> InvoiceBuilder < tb:: True , H , T , C > {
552
550
match Description :: new ( description) {
553
551
Ok ( d) => self . tagged_fields . push ( TaggedField :: Description ( d) ) ,
554
552
Err ( e) => self . error = Some ( e) ,
@@ -557,23 +555,23 @@ impl<H: tb::Bool, T: tb::Bool> InvoiceBuilder<tb::False, H, T> {
557
555
}
558
556
559
557
/// Set the description hash. This function is only available if no description (hash) was set.
560
- pub fn description_hash ( mut self , description_hash : sha256:: Hash ) -> InvoiceBuilder < tb:: True , H , T > {
558
+ pub fn description_hash ( mut self , description_hash : sha256:: Hash ) -> InvoiceBuilder < tb:: True , H , T , C > {
561
559
self . tagged_fields . push ( TaggedField :: DescriptionHash ( Sha256 ( description_hash) ) ) ;
562
560
self . set_flags ( )
563
561
}
564
562
}
565
563
566
- impl < D : tb:: Bool , T : tb:: Bool > InvoiceBuilder < D , tb:: False , T > {
564
+ impl < D : tb:: Bool , T : tb:: Bool , C : tb :: Bool > InvoiceBuilder < D , tb:: False , T , C > {
567
565
/// Set the payment hash. This function is only available if no payment hash was set.
568
- pub fn payment_hash ( mut self , hash : sha256:: Hash ) -> InvoiceBuilder < D , tb:: True , T > {
566
+ pub fn payment_hash ( mut self , hash : sha256:: Hash ) -> InvoiceBuilder < D , tb:: True , T , C > {
569
567
self . tagged_fields . push ( TaggedField :: PaymentHash ( Sha256 ( hash) ) ) ;
570
568
self . set_flags ( )
571
569
}
572
570
}
573
571
574
- impl < D : tb:: Bool , H : tb:: Bool > InvoiceBuilder < D , H , tb:: False > {
572
+ impl < D : tb:: Bool , H : tb:: Bool , C : tb :: Bool > InvoiceBuilder < D , H , tb:: False , C > {
575
573
/// Sets the timestamp.
576
- pub fn timestamp ( mut self , time : SystemTime ) -> InvoiceBuilder < D , H , tb:: True > {
574
+ pub fn timestamp ( mut self , time : SystemTime ) -> InvoiceBuilder < D , H , tb:: True , C > {
577
575
match PositiveTimestamp :: from_system_time ( time) {
578
576
Ok ( t) => self . timestamp = Some ( t) ,
579
577
Err ( e) => self . error = Some ( e) ,
@@ -583,14 +581,22 @@ impl<D: tb::Bool, H: tb::Bool> InvoiceBuilder<D, H, tb::False> {
583
581
}
584
582
585
583
/// Sets the timestamp to the current UNIX timestamp.
586
- pub fn current_timestamp ( mut self ) -> InvoiceBuilder < D , H , tb:: True > {
584
+ pub fn current_timestamp ( mut self ) -> InvoiceBuilder < D , H , tb:: True , C > {
587
585
let now = PositiveTimestamp :: from_system_time ( SystemTime :: now ( ) ) ;
588
586
self . timestamp = Some ( now. expect ( "for the foreseeable future this shouldn't happen" ) ) ;
589
587
self . set_flags ( )
590
588
}
591
589
}
592
590
593
- impl InvoiceBuilder < tb:: True , tb:: True , tb:: True > {
591
+ impl < D : tb:: Bool , H : tb:: Bool , T : tb:: Bool > InvoiceBuilder < D , H , T , tb:: False > {
592
+ /// Sets `min_final_cltv_expiry`.
593
+ pub fn min_final_cltv_expiry ( mut self , min_final_cltv_expiry : u64 ) -> InvoiceBuilder < D , H , T , tb:: True > {
594
+ self . tagged_fields . push ( TaggedField :: MinFinalCltvExpiry ( MinFinalCltvExpiry ( min_final_cltv_expiry) ) ) ;
595
+ self . set_flags ( )
596
+ }
597
+ }
598
+
599
+ impl InvoiceBuilder < tb:: True , tb:: True , tb:: True , tb:: True > {
594
600
/// Builds and signs an invoice using the supplied `sign_function`. This function MAY NOT fail
595
601
/// and MUST produce a recoverable signature valid for the given hash and if applicable also for
596
602
/// the included payee public key.
@@ -1465,7 +1471,8 @@ mod test {
1465
1471
1466
1472
let builder = InvoiceBuilder :: new ( Currency :: Bitcoin )
1467
1473
. payment_hash ( sha256:: Hash :: from_slice ( & [ 0 ; 32 ] [ ..] ) . unwrap ( ) )
1468
- . current_timestamp ( ) ;
1474
+ . current_timestamp ( )
1475
+ . min_final_cltv_expiry ( 144 ) ;
1469
1476
1470
1477
let too_long_string = String :: from_iter (
1471
1478
( 0 ..1024 ) . map ( |_| '?' )
@@ -1582,7 +1589,6 @@ mod test {
1582
1589
. payee_pub_key ( public_key. clone ( ) )
1583
1590
. expiry_time ( Duration :: from_secs ( 54321 ) )
1584
1591
. min_final_cltv_expiry ( 144 )
1585
- . min_final_cltv_expiry ( 143 )
1586
1592
. fallback ( Fallback :: PubKeyHash ( [ 0 ; 20 ] ) )
1587
1593
. route ( route_1. clone ( ) )
1588
1594
. route ( route_2. clone ( ) )
@@ -1594,7 +1600,7 @@ mod test {
1594
1600
} ) . unwrap ( ) ;
1595
1601
1596
1602
assert ! ( invoice. check_signature( ) . is_ok( ) ) ;
1597
- assert_eq ! ( invoice. tagged_fields( ) . count( ) , 9 ) ;
1603
+ assert_eq ! ( invoice. tagged_fields( ) . count( ) , 8 ) ;
1598
1604
1599
1605
assert_eq ! ( invoice. amount_pico_btc( ) , Some ( 123 ) ) ;
1600
1606
assert_eq ! ( invoice. currency( ) , Currency :: BitcoinTestnet ) ;
0 commit comments