From: Duncan Dean Date: Tue, 10 May 2022 16:56:02 +0000 (+0200) Subject: Actually add expiry to phantom invoice utils X-Git-Tag: v0.0.107~33^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=15a840147acca45e05d3beab1613cbe079a16f02;p=rust-lightning Actually add expiry to phantom invoice utils --- diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index deea02a92..d287ea672 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -162,7 +162,8 @@ fn _create_phantom_invoice( .current_timestamp() .payment_hash(Hash::from_slice(&payment_hash.0).unwrap()) .payment_secret(payment_secret) - .min_final_cltv_expiry(MIN_FINAL_CLTV_EXPIRY.into()); + .min_final_cltv_expiry(MIN_FINAL_CLTV_EXPIRY.into()) + .expiry_time(Duration::from_secs(invoice_expiry_delta_secs.into())); if let Some(amt) = amt_msat { invoice = invoice.amount_milli_satoshis(amt); } @@ -799,8 +800,14 @@ mod test { } else { None }; + let non_default_invoice_expiry_secs = 4200; - let invoice = ::utils::create_phantom_invoice::(Some(payment_amt), payment_hash, "test".to_string(), 3600, route_hints, &nodes[1].keys_manager, Currency::BitcoinTestnet).unwrap(); + let invoice = ::utils::create_phantom_invoice::< + EnforcingSigner, &test_utils::TestKeysInterface + >( + Some(payment_amt), payment_hash, "test".to_string(), non_default_invoice_expiry_secs, + route_hints, &nodes[1].keys_manager, Currency::BitcoinTestnet + ).unwrap(); let (payment_hash, payment_secret) = (PaymentHash(invoice.payment_hash().into_inner()), *invoice.payment_secret()); let payment_preimage = if user_generated_pmt_hash { user_payment_preimage @@ -811,6 +818,7 @@ mod test { assert_eq!(invoice.min_final_cltv_expiry(), MIN_FINAL_CLTV_EXPIRY as u64); assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string()))); assert_eq!(invoice.route_hints().len(), 2); + assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into())); assert!(!invoice.features().unwrap().supports_basic_mpp()); let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key()) @@ -931,10 +939,17 @@ mod test { ]; let description_hash = crate::Sha256(Hash::hash("Description hash phantom invoice".as_bytes())); - let invoice = ::utils::create_phantom_invoice_with_description_hash::(Some(payment_amt), None, 3600, description_hash, route_hints, &nodes[1].keys_manager, Currency::BitcoinTestnet).unwrap(); - + let non_default_invoice_expiry_secs = 4200; + let invoice = ::utils::create_phantom_invoice_with_description_hash::< + EnforcingSigner, &test_utils::TestKeysInterface, + >( + Some(payment_amt), None, non_default_invoice_expiry_secs, description_hash, + route_hints, &nodes[1].keys_manager, Currency::BitcoinTestnet + ) + .unwrap(); assert_eq!(invoice.amount_pico_btc(), Some(200_000)); assert_eq!(invoice.min_final_cltv_expiry(), MIN_FINAL_CLTV_EXPIRY as u64); + assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into())); assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Description hash phantom invoice".as_bytes())))); }