@@ -154,11 +154,11 @@ pub const DEFAULT_EXPIRY_TIME: u64 = 3600;
154
154
/// Default minimum final CLTV expiry as defined by [BOLT 11].
155
155
///
156
156
/// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
157
- /// provided in [`MIN_FINAL_CLTV_EXPIRY `].
157
+ /// provided in [`MIN_FINAL_CLTV_EXPIRY_DELTA `].
158
158
///
159
159
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
160
- /// [`MIN_FINAL_CLTV_EXPIRY `]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
161
- pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY : u64 = 18 ;
160
+ /// [`MIN_FINAL_CLTV_EXPIRY_DELTA `]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
161
+ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA : u64 = 18 ;
162
162
163
163
/// Builder for `Invoice`s. It's the most convenient and advised way to use this library. It ensures
164
164
/// that only a semantically and syntactically correct Invoice can be built using it.
@@ -199,7 +199,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = 18;
199
199
/// .payment_hash(payment_hash)
200
200
/// .payment_secret(payment_secret)
201
201
/// .current_timestamp()
202
- /// .min_final_cltv_expiry (144)
202
+ /// .min_final_cltv_expiry_delta (144)
203
203
/// .build_signed(|hash| {
204
204
/// Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)
205
205
/// })
@@ -410,7 +410,7 @@ pub enum TaggedField {
410
410
PayeePubKey ( PayeePubKey ) ,
411
411
DescriptionHash ( Sha256 ) ,
412
412
ExpiryTime ( ExpiryTime ) ,
413
- MinFinalCltvExpiry ( MinFinalCltvExpiry ) ,
413
+ MinFinalCltvExpiryDelta ( MinFinalCltvExpiryDelta ) ,
414
414
Fallback ( Fallback ) ,
415
415
PrivateRoute ( PrivateRoute ) ,
416
416
PaymentSecret ( PaymentSecret ) ,
@@ -438,9 +438,9 @@ pub struct PayeePubKey(pub PublicKey);
438
438
#[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
439
439
pub struct ExpiryTime ( Duration ) ;
440
440
441
- /// `min_final_cltv_expiry ` to use for the last HTLC in the route
441
+ /// `min_final_cltv_expiry_delta ` to use for the last HTLC in the route
442
442
#[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
443
- pub struct MinFinalCltvExpiry ( pub u64 ) ;
443
+ pub struct MinFinalCltvExpiryDelta ( pub u64 ) ;
444
444
445
445
// TODO: better types instead onf byte arrays
446
446
/// Fallback address in case no LN payment is possible
@@ -475,7 +475,7 @@ pub mod constants {
475
475
pub const TAG_PAYEE_PUB_KEY : u8 = 19 ;
476
476
pub const TAG_DESCRIPTION_HASH : u8 = 23 ;
477
477
pub const TAG_EXPIRY_TIME : u8 = 6 ;
478
- pub const TAG_MIN_FINAL_CLTV_EXPIRY : u8 = 24 ;
478
+ pub const TAG_MIN_FINAL_CLTV_EXPIRY_DELTA : u8 = 24 ;
479
479
pub const TAG_FALLBACK : u8 = 9 ;
480
480
pub const TAG_PRIVATE_ROUTE : u8 = 3 ;
481
481
pub const TAG_PAYMENT_SECRET : u8 = 16 ;
@@ -654,9 +654,9 @@ impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBuilder<D, H, tb
654
654
}
655
655
656
656
impl < D : tb:: Bool , H : tb:: Bool , T : tb:: Bool , S : tb:: Bool > InvoiceBuilder < D , H , T , tb:: False , S > {
657
- /// Sets `min_final_cltv_expiry `.
658
- pub fn min_final_cltv_expiry ( mut self , min_final_cltv_expiry : u64 ) -> InvoiceBuilder < D , H , T , tb:: True , S > {
659
- self . tagged_fields . push ( TaggedField :: MinFinalCltvExpiry ( MinFinalCltvExpiry ( min_final_cltv_expiry ) ) ) ;
657
+ /// Sets `min_final_cltv_expiry_delta `.
658
+ pub fn min_final_cltv_expiry_delta ( mut self , min_final_cltv_expiry_delta : u64 ) -> InvoiceBuilder < D , H , T , tb:: True , S > {
659
+ self . tagged_fields . push ( TaggedField :: MinFinalCltvExpiryDelta ( MinFinalCltvExpiryDelta ( min_final_cltv_expiry_delta ) ) ) ;
660
660
self . set_flags ( )
661
661
}
662
662
}
@@ -929,8 +929,8 @@ impl RawInvoice {
929
929
find_extract ! ( self . known_tagged_fields( ) , TaggedField :: ExpiryTime ( ref x) , x)
930
930
}
931
931
932
- pub fn min_final_cltv_expiry ( & self ) -> Option < & MinFinalCltvExpiry > {
933
- find_extract ! ( self . known_tagged_fields( ) , TaggedField :: MinFinalCltvExpiry ( ref x) , x)
932
+ pub fn min_final_cltv_expiry_delta ( & self ) -> Option < & MinFinalCltvExpiryDelta > {
933
+ find_extract ! ( self . known_tagged_fields( ) , TaggedField :: MinFinalCltvExpiryDelta ( ref x) , x)
934
934
}
935
935
936
936
pub fn payment_secret ( & self ) -> Option < & PaymentSecret > {
@@ -1243,12 +1243,12 @@ impl Invoice {
1243
1243
. unwrap_or_else ( || Duration :: new ( u64:: max_value ( ) , 1_000_000_000 - 1 ) ) < at_time
1244
1244
}
1245
1245
1246
- /// Returns the invoice's `min_final_cltv_expiry ` time, if present, otherwise
1247
- /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY `].
1248
- pub fn min_final_cltv_expiry ( & self ) -> u64 {
1249
- self . signed_invoice . min_final_cltv_expiry ( )
1246
+ /// Returns the invoice's `min_final_cltv_expiry_delta ` time, if present, otherwise
1247
+ /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA `].
1248
+ pub fn min_final_cltv_expiry_delta ( & self ) -> u64 {
1249
+ self . signed_invoice . min_final_cltv_expiry_delta ( )
1250
1250
. map ( |x| x. 0 )
1251
- . unwrap_or ( DEFAULT_MIN_FINAL_CLTV_EXPIRY )
1251
+ . unwrap_or ( DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA )
1252
1252
}
1253
1253
1254
1254
/// Returns a list of all fallback addresses
@@ -1301,7 +1301,7 @@ impl TaggedField {
1301
1301
TaggedField :: PayeePubKey ( _) => constants:: TAG_PAYEE_PUB_KEY ,
1302
1302
TaggedField :: DescriptionHash ( _) => constants:: TAG_DESCRIPTION_HASH ,
1303
1303
TaggedField :: ExpiryTime ( _) => constants:: TAG_EXPIRY_TIME ,
1304
- TaggedField :: MinFinalCltvExpiry ( _) => constants:: TAG_MIN_FINAL_CLTV_EXPIRY ,
1304
+ TaggedField :: MinFinalCltvExpiryDelta ( _) => constants:: TAG_MIN_FINAL_CLTV_EXPIRY_DELTA ,
1305
1305
TaggedField :: Fallback ( _) => constants:: TAG_FALLBACK ,
1306
1306
TaggedField :: PrivateRoute ( _) => constants:: TAG_PRIVATE_ROUTE ,
1307
1307
TaggedField :: PaymentSecret ( _) => constants:: TAG_PAYMENT_SECRET ,
@@ -1448,6 +1448,11 @@ pub enum CreationError {
1448
1448
///
1449
1449
/// [phantom invoices]: crate::utils::create_phantom_invoice
1450
1450
MissingRouteHints ,
1451
+
1452
+ /// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
1453
+ ///
1454
+ /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
1455
+ MinFinalCltvExpiryDeltaTooShort ,
1451
1456
}
1452
1457
1453
1458
impl Display for CreationError {
@@ -1458,6 +1463,8 @@ impl Display for CreationError {
1458
1463
CreationError :: TimestampOutOfBounds => f. write_str ( "The Unix timestamp of the supplied date is less than zero or greater than 35-bits" ) ,
1459
1464
CreationError :: InvalidAmount => f. write_str ( "The supplied millisatoshi amount was greater than the total bitcoin supply" ) ,
1460
1465
CreationError :: MissingRouteHints => f. write_str ( "The invoice required route hints and they weren't provided" ) ,
1466
+ CreationError :: MinFinalCltvExpiryDeltaTooShort => f. write_str (
1467
+ "The supplied final CLTV expiry delta was less than LDK's `MIN_FINAL_CLTV_EXPIRY_DELTA`" ) ,
1461
1468
}
1462
1469
}
1463
1470
}
@@ -1804,7 +1811,7 @@ mod test {
1804
1811
let builder = InvoiceBuilder :: new ( Currency :: Bitcoin )
1805
1812
. payment_hash ( sha256:: Hash :: from_slice ( & [ 0 ; 32 ] [ ..] ) . unwrap ( ) )
1806
1813
. duration_since_epoch ( Duration :: from_secs ( 1234567 ) )
1807
- . min_final_cltv_expiry ( 144 ) ;
1814
+ . min_final_cltv_expiry_delta ( 144 ) ;
1808
1815
1809
1816
let too_long_string = String :: from_iter (
1810
1817
( 0 ..1024 ) . map ( |_| '?' )
@@ -1922,7 +1929,7 @@ mod test {
1922
1929
. duration_since_epoch ( Duration :: from_secs ( 1234567 ) )
1923
1930
. payee_pub_key ( public_key. clone ( ) )
1924
1931
. expiry_time ( Duration :: from_secs ( 54321 ) )
1925
- . min_final_cltv_expiry ( 144 )
1932
+ . min_final_cltv_expiry_delta ( 144 )
1926
1933
. fallback ( Fallback :: PubKeyHash ( [ 0 ; 20 ] ) )
1927
1934
. private_route ( route_1. clone ( ) )
1928
1935
. private_route ( route_2. clone ( ) )
@@ -1948,7 +1955,7 @@ mod test {
1948
1955
) ;
1949
1956
assert_eq ! ( invoice. payee_pub_key( ) , Some ( & public_key) ) ;
1950
1957
assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( 54321 ) ) ;
1951
- assert_eq ! ( invoice. min_final_cltv_expiry ( ) , 144 ) ;
1958
+ assert_eq ! ( invoice. min_final_cltv_expiry_delta ( ) , 144 ) ;
1952
1959
assert_eq ! ( invoice. fallbacks( ) , vec![ & Fallback :: PubKeyHash ( [ 0 ; 20 ] ) ] ) ;
1953
1960
assert_eq ! ( invoice. private_routes( ) , vec![ & PrivateRoute ( route_1) , & PrivateRoute ( route_2) ] ) ;
1954
1961
assert_eq ! (
@@ -1989,7 +1996,7 @@ mod test {
1989
1996
. unwrap ( ) ;
1990
1997
let invoice = Invoice :: from_signed ( signed_invoice) . unwrap ( ) ;
1991
1998
1992
- assert_eq ! ( invoice. min_final_cltv_expiry ( ) , DEFAULT_MIN_FINAL_CLTV_EXPIRY ) ;
1999
+ assert_eq ! ( invoice. min_final_cltv_expiry_delta ( ) , DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA ) ;
1993
2000
assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( DEFAULT_EXPIRY_TIME ) ) ;
1994
2001
assert ! ( !invoice. would_expire( Duration :: from_secs( 1234568 ) ) ) ;
1995
2002
}
0 commit comments