Merge pull request #2162 from jkczyz/2023-04-invoice-hash
[rust-lightning] / lightning-invoice / src / payment.rs
index db47f9954800a2296785bdabd622aa31b7bd41c4..00b17db7899d60e235d95057d45b3e97886eadf7 100644 (file)
@@ -16,8 +16,8 @@ use bitcoin_hashes::Hash;
 use lightning::chain;
 use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
 use lightning::chain::keysinterface::{NodeSigner, SignerProvider, EntropySource};
-use lightning::ln::{PaymentHash, PaymentSecret};
-use lightning::ln::channelmanager::{ChannelManager, PaymentId, Retry, RetryableSendFailure};
+use lightning::ln::PaymentHash;
+use lightning::ln::channelmanager::{ChannelManager, PaymentId, Retry, RetryableSendFailure, RecipientOnionFields};
 use lightning::routing::router::{PaymentParameters, RouteParameters, Router};
 use lightning::util::logger::Logger;
 
@@ -144,11 +144,12 @@ fn pay_invoice_using_amount<P: Deref>(
        invoice: &Invoice, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry,
        payer: P
 ) -> Result<(), PaymentError> where P::Target: Payer {
-       let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
-       let payment_secret = Some(invoice.payment_secret().clone());
+       let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
+       let payment_secret = Some(*invoice.payment_secret());
+       let recipient_onion = RecipientOnionFields { payment_secret };
        let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
                invoice.min_final_cltv_expiry_delta() as u32)
-               .with_expiry_time(expiry_time_from_unix_epoch(&invoice).as_secs())
+               .with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
                .with_route_hints(invoice.route_hints());
        if let Some(features) = invoice.features() {
                payment_params = payment_params.with_features(features.clone());
@@ -156,10 +157,9 @@ fn pay_invoice_using_amount<P: Deref>(
        let route_params = RouteParameters {
                payment_params,
                final_value_msat: amount_msats,
-               final_cltv_expiry_delta: invoice.min_final_cltv_expiry_delta() as u32,
        };
 
-       payer.send_payment(payment_hash, &payment_secret, payment_id, route_params, retry_strategy)
+       payer.send_payment(payment_hash, recipient_onion, payment_id, route_params, retry_strategy)
 }
 
 fn expiry_time_from_unix_epoch(invoice: &Invoice) -> Duration {
@@ -183,7 +183,7 @@ trait Payer {
        ///
        /// [`Route`]: lightning::routing::router::Route
        fn send_payment(
-               &self, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>,
+               &self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
                payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
        ) -> Result<(), PaymentError>;
 }
@@ -200,11 +200,11 @@ where
                L::Target: Logger,
 {
        fn send_payment(
-               &self, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>,
+               &self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
                payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
        ) -> Result<(), PaymentError> {
-               self.send_payment_with_retry(payment_hash, payment_secret, payment_id, route_params, retry_strategy)
-                       .map_err(|e| PaymentError::Sending(e))
+               self.send_payment(payment_hash, recipient_onion, payment_id, route_params, retry_strategy)
+                       .map_err(PaymentError::Sending)
        }
 }
 
@@ -213,7 +213,7 @@ mod tests {
        use super::*;
        use crate::{InvoiceBuilder, Currency};
        use bitcoin_hashes::sha256::Hash as Sha256;
-       use lightning::ln::PaymentPreimage;
+       use lightning::ln::{PaymentPreimage, PaymentSecret};
        use lightning::ln::functional_test_utils::*;
        use secp256k1::{SecretKey, Secp256k1};
        use std::collections::VecDeque;
@@ -250,7 +250,7 @@ mod tests {
 
        impl Payer for TestPayer {
                fn send_payment(
-                       &self, _payment_hash: PaymentHash, _payment_secret: &Option<PaymentSecret>,
+                       &self, _payment_hash: PaymentHash, _recipient_onion: RecipientOnionFields,
                        _payment_id: PaymentId, route_params: RouteParameters, _retry_strategy: Retry
                ) -> Result<(), PaymentError> {
                        self.check_value_msats(Amount(route_params.final_value_msat));
@@ -345,7 +345,7 @@ mod tests {
                let invoice = invoice(payment_preimage);
                let amt_msat = 10_000;
 
-               match pay_zero_value_invoice(&invoice, amt_msat, Retry::Attempts(0), &nodes[0].node) {
+               match pay_zero_value_invoice(&invoice, amt_msat, Retry::Attempts(0), nodes[0].node) {
                        Err(PaymentError::Invoice("amount unexpected")) => {},
                        _ => panic!()
                }