Skip to content

Commit 15a8401

Browse files
committed
Actually add expiry to phantom invoice utils
1 parent 29727a3 commit 15a8401

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lightning-invoice/src/utils.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ fn _create_phantom_invoice<Signer: Sign, K: Deref>(
162162
.current_timestamp()
163163
.payment_hash(Hash::from_slice(&payment_hash.0).unwrap())
164164
.payment_secret(payment_secret)
165-
.min_final_cltv_expiry(MIN_FINAL_CLTV_EXPIRY.into());
165+
.min_final_cltv_expiry(MIN_FINAL_CLTV_EXPIRY.into())
166+
.expiry_time(Duration::from_secs(invoice_expiry_delta_secs.into()));
166167
if let Some(amt) = amt_msat {
167168
invoice = invoice.amount_milli_satoshis(amt);
168169
}
@@ -799,8 +800,14 @@ mod test {
799800
} else {
800801
None
801802
};
803+
let non_default_invoice_expiry_secs = 4200;
802804

803-
let invoice = ::utils::create_phantom_invoice::<EnforcingSigner, &test_utils::TestKeysInterface>(Some(payment_amt), payment_hash, "test".to_string(), 3600, route_hints, &nodes[1].keys_manager, Currency::BitcoinTestnet).unwrap();
805+
let invoice = ::utils::create_phantom_invoice::<
806+
EnforcingSigner, &test_utils::TestKeysInterface
807+
>(
808+
Some(payment_amt), payment_hash, "test".to_string(), non_default_invoice_expiry_secs,
809+
route_hints, &nodes[1].keys_manager, Currency::BitcoinTestnet
810+
).unwrap();
804811
let (payment_hash, payment_secret) = (PaymentHash(invoice.payment_hash().into_inner()), *invoice.payment_secret());
805812
let payment_preimage = if user_generated_pmt_hash {
806813
user_payment_preimage
@@ -811,6 +818,7 @@ mod test {
811818
assert_eq!(invoice.min_final_cltv_expiry(), MIN_FINAL_CLTV_EXPIRY as u64);
812819
assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
813820
assert_eq!(invoice.route_hints().len(), 2);
821+
assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
814822
assert!(!invoice.features().unwrap().supports_basic_mpp());
815823

816824
let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key())
@@ -931,10 +939,17 @@ mod test {
931939
];
932940

933941
let description_hash = crate::Sha256(Hash::hash("Description hash phantom invoice".as_bytes()));
934-
let invoice = ::utils::create_phantom_invoice_with_description_hash::<EnforcingSigner,&test_utils::TestKeysInterface>(Some(payment_amt), None, 3600, description_hash, route_hints, &nodes[1].keys_manager, Currency::BitcoinTestnet).unwrap();
935-
942+
let non_default_invoice_expiry_secs = 4200;
943+
let invoice = ::utils::create_phantom_invoice_with_description_hash::<
944+
EnforcingSigner, &test_utils::TestKeysInterface,
945+
>(
946+
Some(payment_amt), None, non_default_invoice_expiry_secs, description_hash,
947+
route_hints, &nodes[1].keys_manager, Currency::BitcoinTestnet
948+
)
949+
.unwrap();
936950
assert_eq!(invoice.amount_pico_btc(), Some(200_000));
937951
assert_eq!(invoice.min_final_cltv_expiry(), MIN_FINAL_CLTV_EXPIRY as u64);
952+
assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
938953
assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Description hash phantom invoice".as_bytes()))));
939954
}
940955

0 commit comments

Comments
 (0)