X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-invoice%2Fsrc%2Fpayment.rs;h=89842591fdec8a89693cbb62457389e9f4a46dc9;hb=803fb557e805a27c63db48dd72d311f73e0ad4e7;hp=f5b20d87fa192f25f2ee709749d9cd903d71792d;hpb=f2fe95e5657ffa8f2b2f4793f1b693e4c1c0bd9c;p=rust-lightning diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index f5b20d87..89842591 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -9,7 +9,8 @@ //! Convenient utilities for paying Lightning invoices. -use crate::{Bolt11Invoice, Vec}; +use crate::Bolt11Invoice; +use crate::prelude::*; use bitcoin_hashes::Hash; @@ -32,9 +33,10 @@ use core::time::Duration; /// with the same [`PaymentHash`] is never sent. /// /// If you wish to use a different payment idempotency token, see [`pay_invoice_with_id`]. -pub fn pay_invoice( - invoice: &Bolt11Invoice, retry_strategy: Retry, channelmanager: &C +pub fn pay_invoice( + invoice: &Bolt11Invoice, retry_strategy: Retry, channelmanager: C ) -> Result +where C::Target: AChannelManager, { let payment_id = PaymentId(invoice.payment_hash().into_inner()); pay_invoice_with_id(invoice, payment_id, retry_strategy, channelmanager.get_cm()) @@ -51,9 +53,10 @@ pub fn pay_invoice( /// [`PaymentHash`] has never been paid before. /// /// See [`pay_invoice`] for a variant which uses the [`PaymentHash`] for the idempotency token. -pub fn pay_invoice_with_id( - invoice: &Bolt11Invoice, payment_id: PaymentId, retry_strategy: Retry, channelmanager: &C +pub fn pay_invoice_with_id( + invoice: &Bolt11Invoice, payment_id: PaymentId, retry_strategy: Retry, channelmanager: C ) -> Result<(), PaymentError> +where C::Target: AChannelManager, { let amt_msat = invoice.amount_milli_satoshis().ok_or(PaymentError::Invoice("amount missing"))?; pay_invoice_using_amount(invoice, amt_msat, payment_id, retry_strategy, channelmanager.get_cm()) @@ -68,9 +71,10 @@ pub fn pay_invoice_with_id( /// /// If you wish to use a different payment idempotency token, see /// [`pay_zero_value_invoice_with_id`]. -pub fn pay_zero_value_invoice( - invoice: &Bolt11Invoice, amount_msats: u64, retry_strategy: Retry, channelmanager: &C +pub fn pay_zero_value_invoice( + invoice: &Bolt11Invoice, amount_msats: u64, retry_strategy: Retry, channelmanager: C ) -> Result +where C::Target: AChannelManager, { let payment_id = PaymentId(invoice.payment_hash().into_inner()); pay_zero_value_invoice_with_id(invoice, amount_msats, payment_id, retry_strategy, @@ -89,10 +93,11 @@ pub fn pay_zero_value_invoice( /// /// See [`pay_zero_value_invoice`] for a variant which uses the [`PaymentHash`] for the /// idempotency token. -pub fn pay_zero_value_invoice_with_id( +pub fn pay_zero_value_invoice_with_id( invoice: &Bolt11Invoice, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry, - channelmanager: &C + channelmanager: C ) -> Result<(), PaymentError> +where C::Target: AChannelManager, { if invoice.amount_milli_satoshis().is_some() { Err(PaymentError::Invoice("amount unexpected")) @@ -116,10 +121,7 @@ fn pay_invoice_using_amount( if let Some(features) = invoice.features() { payment_params = payment_params.with_bolt11_features(features.clone()).unwrap(); } - let route_params = RouteParameters { - payment_params, - final_value_msat: amount_msats, - }; + let route_params = RouteParameters::from_payment_params_and_value(payment_params, amount_msats); payer.send_payment(payment_hash, recipient_onion, payment_id, route_params, retry_strategy) } @@ -127,9 +129,10 @@ fn pay_invoice_using_amount( /// Sends payment probes over all paths of a route that would be used to pay the given invoice. /// /// See [`ChannelManager::send_preflight_probes`] for more information. -pub fn preflight_probe_invoice( - invoice: &Bolt11Invoice, channelmanager: &C, liquidity_limit_multiplier: Option, +pub fn preflight_probe_invoice( + invoice: &Bolt11Invoice, channelmanager: C, liquidity_limit_multiplier: Option, ) -> Result, ProbingError> +where C::Target: AChannelManager, { let amount_msat = if let Some(invoice_amount_msat) = invoice.amount_milli_satoshis() { invoice_amount_msat @@ -148,7 +151,7 @@ pub fn preflight_probe_invoice( if let Some(features) = invoice.features() { payment_params = payment_params.with_bolt11_features(features.clone()).unwrap(); } - let route_params = RouteParameters { payment_params, final_value_msat: amount_msat }; + let route_params = RouteParameters::from_payment_params_and_value(payment_params, amount_msat); channelmanager.get_cm().send_preflight_probes(route_params, liquidity_limit_multiplier) .map_err(ProbingError::Sending) @@ -158,10 +161,11 @@ pub fn preflight_probe_invoice( /// invoice using the given amount. /// /// See [`ChannelManager::send_preflight_probes`] for more information. -pub fn preflight_probe_zero_value_invoice( - invoice: &Bolt11Invoice, amount_msat: u64, channelmanager: &C, +pub fn preflight_probe_zero_value_invoice( + invoice: &Bolt11Invoice, amount_msat: u64, channelmanager: C, liquidity_limit_multiplier: Option, ) -> Result, ProbingError> +where C::Target: AChannelManager, { if invoice.amount_milli_satoshis().is_some() { return Err(ProbingError::Invoice("amount unexpected")); @@ -178,7 +182,7 @@ pub fn preflight_probe_zero_value_invoice( if let Some(features) = invoice.features() { payment_params = payment_params.with_bolt11_features(features.clone()).unwrap(); } - let route_params = RouteParameters { payment_params, final_value_msat: amount_msat }; + let route_params = RouteParameters::from_payment_params_and_value(payment_params, amount_msat); channelmanager.get_cm().send_preflight_probes(route_params, liquidity_limit_multiplier) .map_err(ProbingError::Sending)