Update auto-generated bindings to LDK 0.0.121
[ldk-c-bindings] / lightning-c-bindings / src / lightning_invoice / payment.rs
index 4c19e67ae5f88d6022cae6f64132b24d60d800b0..de0ea57064100eb96f98a3210dcff28f09894332 100644 (file)
@@ -6,9 +6,10 @@
 // license as that which applies to the original source files from which this
 // source was automatically generated.
 
-//! Convenient utilities for paying Lightning invoices and sending spontaneous payments.
+//! Convenient utilities for paying Lightning invoices.
 
 use alloc::str::FromStr;
+use alloc::string::String;
 use core::ffi::c_void;
 use core::convert::Infallible;
 use bitcoin::hashes::Hash;
@@ -16,166 +17,40 @@ use crate::c_types::*;
 #[cfg(feature="no-std")]
 use alloc::{vec::Vec, boxed::Box};
 
-/// Pays the given [`Invoice`], retrying if needed based on [`Retry`].
+/// Builds the necessary parameters to pay or pre-flight probe the given zero-amount
+/// [`Bolt11Invoice`] using [`ChannelManager::send_payment`] or
+/// [`ChannelManager::send_preflight_probes`].
 ///
-/// [`Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
-/// as the payment is still pending. Once the payment completes or fails, you must ensure that
-/// a second payment with the same [`PaymentHash`] is never sent.
+/// Prior to paying, you must ensure that the [`Bolt11Invoice::payment_hash`] is unique and the
+/// same [`PaymentHash`] has never been paid before.
 ///
-/// If you wish to use a different payment idempotency token, see [`pay_invoice_with_id`].
-#[no_mangle]
-pub extern "C" fn pay_invoice(invoice: &crate::lightning_invoice::Invoice, mut retry_strategy: crate::lightning::ln::outbound_payment::Retry, channelmanager: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CResult_PaymentIdPaymentErrorZ {
-       let mut ret = lightning_invoice::payment::pay_invoice::<crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::EntropySource, crate::lightning::chain::keysinterface::NodeSigner, crate::lightning::chain::keysinterface::SignerProvider, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::routing::router::Router, crate::lightning::util::logger::Logger>(invoice.get_native_ref(), retry_strategy.into_native(), channelmanager.get_native_ref());
-       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::payment::PaymentError::native_into(e) }).into() };
-       local_ret
-}
-
-/// Pays the given [`Invoice`] with a custom idempotency key, retrying if needed based on [`Retry`].
-///
-/// Note that idempotency is only guaranteed as long as the payment is still pending. Once the
-/// payment completes or fails, no idempotency guarantees are made.
-///
-/// You should ensure that the [`Invoice::payment_hash`] is unique and the same [`PaymentHash`]
-/// has never been paid before.
-///
-/// See [`pay_invoice`] for a variant which uses the [`PaymentHash`] for the idempotency token.
-#[no_mangle]
-pub extern "C" fn pay_invoice_with_id(invoice: &crate::lightning_invoice::Invoice, mut payment_id: crate::c_types::ThirtyTwoBytes, mut retry_strategy: crate::lightning::ln::outbound_payment::Retry, channelmanager: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CResult_NonePaymentErrorZ {
-       let mut ret = lightning_invoice::payment::pay_invoice_with_id::<crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::EntropySource, crate::lightning::chain::keysinterface::NodeSigner, crate::lightning::chain::keysinterface::SignerProvider, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::routing::router::Router, crate::lightning::util::logger::Logger>(invoice.get_native_ref(), ::lightning::ln::channelmanager::PaymentId(payment_id.data), retry_strategy.into_native(), channelmanager.get_native_ref());
-       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::payment::PaymentError::native_into(e) }).into() };
-       local_ret
-}
-
-/// Pays the given zero-value [`Invoice`] using the given amount, retrying if needed based on
-/// [`Retry`].
+/// Will always succeed unless the invoice has an amount specified, in which case
+/// [`payment_parameters_from_invoice`] should be used.
 ///
-/// [`Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
-/// as the payment is still pending. Once the payment completes or fails, you must ensure that
-/// a second payment with the same [`PaymentHash`] is never sent.
-///
-/// If you wish to use a different payment idempotency token, see
-/// [`pay_zero_value_invoice_with_id`].
+/// [`ChannelManager::send_payment`]: lightning::ln::channelmanager::ChannelManager::send_payment
+/// [`ChannelManager::send_preflight_probes`]: lightning::ln::channelmanager::ChannelManager::send_preflight_probes
 #[no_mangle]
-pub extern "C" fn pay_zero_value_invoice(invoice: &crate::lightning_invoice::Invoice, mut amount_msats: u64, mut retry_strategy: crate::lightning::ln::outbound_payment::Retry, channelmanager: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CResult_PaymentIdPaymentErrorZ {
-       let mut ret = lightning_invoice::payment::pay_zero_value_invoice::<crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::EntropySource, crate::lightning::chain::keysinterface::NodeSigner, crate::lightning::chain::keysinterface::SignerProvider, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::routing::router::Router, crate::lightning::util::logger::Logger>(invoice.get_native_ref(), amount_msats, retry_strategy.into_native(), channelmanager.get_native_ref());
-       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::payment::PaymentError::native_into(e) }).into() };
+pub extern "C" fn payment_parameters_from_zero_amount_invoice(invoice: &crate::lightning_invoice::Bolt11Invoice, mut amount_msat: u64) -> crate::c_types::derived::CResult_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ {
+       let mut ret = lightning_invoice::payment::payment_parameters_from_zero_amount_invoice(invoice.get_native_ref(), amount_msat);
+       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: ObjOps::heap_alloc(orig_ret_0_1), is_owned: true }, crate::lightning::routing::router::RouteParameters { inner: ObjOps::heap_alloc(orig_ret_0_2), is_owned: true }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
        local_ret
 }
 
-/// Pays the given zero-value [`Invoice`] using the given amount and custom idempotency key,
-/// , retrying if needed based on [`Retry`].
+/// Builds the necessary parameters to pay or pre-flight probe the given [`Bolt11Invoice`] using
+/// [`ChannelManager::send_payment`] or [`ChannelManager::send_preflight_probes`].
 ///
-/// Note that idempotency is only guaranteed as long as the payment is still pending. Once the
-/// payment completes or fails, no idempotency guarantees are made.
+/// Prior to paying, you must ensure that the [`Bolt11Invoice::payment_hash`] is unique and the
+/// same [`PaymentHash`] has never been paid before.
 ///
-/// You should ensure that the [`Invoice::payment_hash`] is unique and the same [`PaymentHash`]
-/// has never been paid before.
+/// Will always succeed unless the invoice has no amount specified, in which case
+/// [`payment_parameters_from_zero_amount_invoice`] should be used.
 ///
-/// See [`pay_zero_value_invoice`] for a variant which uses the [`PaymentHash`] for the
-/// idempotency token.
+/// [`ChannelManager::send_payment`]: lightning::ln::channelmanager::ChannelManager::send_payment
+/// [`ChannelManager::send_preflight_probes`]: lightning::ln::channelmanager::ChannelManager::send_preflight_probes
 #[no_mangle]
-pub extern "C" fn pay_zero_value_invoice_with_id(invoice: &crate::lightning_invoice::Invoice, mut amount_msats: u64, mut payment_id: crate::c_types::ThirtyTwoBytes, mut retry_strategy: crate::lightning::ln::outbound_payment::Retry, channelmanager: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CResult_NonePaymentErrorZ {
-       let mut ret = lightning_invoice::payment::pay_zero_value_invoice_with_id::<crate::lightning::chain::Watch, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::keysinterface::EntropySource, crate::lightning::chain::keysinterface::NodeSigner, crate::lightning::chain::keysinterface::SignerProvider, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::routing::router::Router, crate::lightning::util::logger::Logger>(invoice.get_native_ref(), amount_msats, ::lightning::ln::channelmanager::PaymentId(payment_id.data), retry_strategy.into_native(), channelmanager.get_native_ref());
-       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::payment::PaymentError::native_into(e) }).into() };
+pub extern "C" fn payment_parameters_from_invoice(invoice: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CResult_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ {
+       let mut ret = lightning_invoice::payment::payment_parameters_from_invoice(invoice.get_native_ref());
+       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: ObjOps::heap_alloc(orig_ret_0_1), is_owned: true }, crate::lightning::routing::router::RouteParameters { inner: ObjOps::heap_alloc(orig_ret_0_2), is_owned: true }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
        local_ret
 }
 
-/// An error that may occur when making a payment.
-#[derive(Clone)]
-#[must_use]
-#[repr(C)]
-pub enum PaymentError {
-       /// An error resulting from the provided [`Invoice`] or payment hash.
-       Invoice(
-               crate::c_types::Str),
-       /// An error occurring when sending a payment.
-       Sending(
-               crate::lightning::ln::outbound_payment::RetryableSendFailure),
-}
-use lightning_invoice::payment::PaymentError as PaymentErrorImport;
-pub(crate) type nativePaymentError = PaymentErrorImport;
-
-impl PaymentError {
-       #[allow(unused)]
-       pub(crate) fn to_native(&self) -> nativePaymentError {
-               match self {
-                       PaymentError::Invoice (ref a, ) => {
-                               let mut a_nonref = Clone::clone(a);
-                               nativePaymentError::Invoice (
-                                       a_nonref.into_str(),
-                               )
-                       },
-                       PaymentError::Sending (ref a, ) => {
-                               let mut a_nonref = Clone::clone(a);
-                               nativePaymentError::Sending (
-                                       a_nonref.into_native(),
-                               )
-                       },
-               }
-       }
-       #[allow(unused)]
-       pub(crate) fn into_native(self) -> nativePaymentError {
-               match self {
-                       PaymentError::Invoice (mut a, ) => {
-                               nativePaymentError::Invoice (
-                                       a.into_str(),
-                               )
-                       },
-                       PaymentError::Sending (mut a, ) => {
-                               nativePaymentError::Sending (
-                                       a.into_native(),
-                               )
-                       },
-               }
-       }
-       #[allow(unused)]
-       pub(crate) fn from_native(native: &nativePaymentError) -> Self {
-               match native {
-                       nativePaymentError::Invoice (ref a, ) => {
-                               let mut a_nonref = Clone::clone(a);
-                               PaymentError::Invoice (
-                                       a_nonref.into(),
-                               )
-                       },
-                       nativePaymentError::Sending (ref a, ) => {
-                               let mut a_nonref = Clone::clone(a);
-                               PaymentError::Sending (
-                                       crate::lightning::ln::outbound_payment::RetryableSendFailure::native_into(a_nonref),
-                               )
-                       },
-               }
-       }
-       #[allow(unused)]
-       pub(crate) fn native_into(native: nativePaymentError) -> Self {
-               match native {
-                       nativePaymentError::Invoice (mut a, ) => {
-                               PaymentError::Invoice (
-                                       a.into(),
-                               )
-                       },
-                       nativePaymentError::Sending (mut a, ) => {
-                               PaymentError::Sending (
-                                       crate::lightning::ln::outbound_payment::RetryableSendFailure::native_into(a),
-                               )
-                       },
-               }
-       }
-}
-/// Frees any resources used by the PaymentError
-#[no_mangle]
-pub extern "C" fn PaymentError_free(this_ptr: PaymentError) { }
-/// Creates a copy of the PaymentError
-#[no_mangle]
-pub extern "C" fn PaymentError_clone(orig: &PaymentError) -> PaymentError {
-       orig.clone()
-}
-#[no_mangle]
-/// Utility method to constructs a new Invoice-variant PaymentError
-pub extern "C" fn PaymentError_invoice(a: crate::c_types::Str) -> PaymentError {
-       PaymentError::Invoice(a, )
-}
-#[no_mangle]
-/// Utility method to constructs a new Sending-variant PaymentError
-pub extern "C" fn PaymentError_sending(a: crate::lightning::ln::outbound_payment::RetryableSendFailure) -> PaymentError {
-       PaymentError::Sending(a, )
-}