-
-use lightning_invoice::payment::InvoicePayer as nativeInvoicePayerImport;
-pub(crate) type nativeInvoicePayer = nativeInvoicePayerImport<crate::lightning_invoice::payment::Payer, crate::lightning_invoice::payment::Router, crate::lightning::routing::Score, &'static lightning::routing::LockableScore<crate::lightning::routing::Score>, crate::lightning::util::logger::Logger, crate::lightning::util::events::EventHandler>;
-
-/// A utility for paying [`Invoice]`s.
-#[must_use]
-#[repr(C)]
-pub struct InvoicePayer {
- /// A pointer to the opaque Rust object.
-
- /// Nearly everywhere, inner must be non-null, however in places where
- /// the Rust equivalent takes an Option, it may be set to null to indicate None.
- pub inner: *mut nativeInvoicePayer,
- /// Indicates that this is the only struct which contains the same pointer.
-
- /// Rust functions which take ownership of an object provided via an argument require
- /// this to be true and invalidate the object pointed to by inner.
- pub is_owned: bool,
-}
-
-impl Drop for InvoicePayer {
- fn drop(&mut self) {
- if self.is_owned && !<*mut nativeInvoicePayer>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
- }
- }
-}
-/// Frees any resources used by the InvoicePayer, if is_owned is set and inner is non-NULL.
-#[no_mangle]
-pub extern "C" fn InvoicePayer_free(this_obj: InvoicePayer) { }
-#[allow(unused)]
-/// Used only if an object of this type is returned as a trait impl by a method
-pub(crate) extern "C" fn InvoicePayer_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoicePayer); }
-}
-#[allow(unused)]
-impl InvoicePayer {
- pub(crate) fn get_native_ref(&self) -> &'static nativeInvoicePayer {
- unsafe { &*ObjOps::untweak_ptr(self.inner) }
- }
- pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoicePayer {
- unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
- }
- /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
- pub(crate) fn take_inner(mut self) -> *mut nativeInvoicePayer {
- assert!(self.is_owned);
- let ret = ObjOps::untweak_ptr(self.inner);
- self.inner = std::ptr::null_mut();
- ret
- }
-}
-/// A trait defining behavior of an [`Invoice`] payer.
-#[repr(C)]
-pub struct Payer {
- /// An opaque pointer which is passed to your function implementations as an argument.
- /// This has no meaning in the LDK, and can be NULL or any other value.
- pub this_arg: *mut c_void,
- /// Returns the payer's node id.
- #[must_use]
- pub node_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::PublicKey,
- /// Returns the payer's channels.
- #[must_use]
- pub first_hops: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_ChannelDetailsZ,
- /// Sends a payment over the Lightning Network using the given [`Route`].
- ///
- /// Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
- #[must_use]
- pub send_payment: extern "C" fn (this_arg: *const c_void, route: &crate::lightning::routing::router::Route, payment_hash: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_PaymentIdPaymentSendFailureZ,
- /// Retries a failed payment path for the [`PaymentId`] using the given [`Route`].
- #[must_use]
- pub retry_payment: extern "C" fn (this_arg: *const c_void, route: &crate::lightning::routing::router::Route, payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ,
- /// Frees any resources associated with this object given its this_arg pointer.
- /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
- pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
-}
-unsafe impl Send for Payer {}
-unsafe impl Sync for Payer {}
-#[no_mangle]
-pub(crate) extern "C" fn Payer_clone_fields(orig: &Payer) -> Payer {
- Payer {
- this_arg: orig.this_arg,
- node_id: Clone::clone(&orig.node_id),
- first_hops: Clone::clone(&orig.first_hops),
- send_payment: Clone::clone(&orig.send_payment),
- retry_payment: Clone::clone(&orig.retry_payment),
- free: Clone::clone(&orig.free),
- }
-}
-
-use lightning_invoice::payment::Payer as rustPayer;
-impl rustPayer for Payer {
- fn node_id(&self) -> secp256k1::key::PublicKey {
- let mut ret = (self.node_id)(self.this_arg);
- ret.into_rust()
- }
- fn first_hops(&self) -> Vec<lightning::ln::channelmanager::ChannelDetails> {
- let mut ret = (self.first_hops)(self.this_arg);
- let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
- local_ret
- }
- fn send_payment(&self, mut route: &lightning::routing::router::Route, mut payment_hash: lightning::ln::PaymentHash, mut payment_secret: &Option<lightning::ln::PaymentSecret>) -> Result<lightning::ln::channelmanager::PaymentId, lightning::ln::channelmanager::PaymentSendFailure> {
- let mut local_payment_secret = if payment_secret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_secret.unwrap()).0 } } };
- let mut ret = (self.send_payment)(self.this_arg, &crate::lightning::routing::router::Route { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route as *const lightning::routing::router::Route<>) as *mut _) }, is_owned: false }, crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, local_payment_secret);
- let mut local_ret = match ret.result_ok { true => Ok( { ::lightning::ln::channelmanager::PaymentId((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).data) }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
- local_ret
- }
- fn retry_payment(&self, mut route: &lightning::routing::router::Route, mut payment_id: lightning::ln::channelmanager::PaymentId) -> Result<(), lightning::ln::channelmanager::PaymentSendFailure> {
- let mut ret = (self.retry_payment)(self.this_arg, &crate::lightning::routing::router::Route { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route as *const lightning::routing::router::Route<>) as *mut _) }, is_owned: false }, crate::c_types::ThirtyTwoBytes { data: payment_id.0 });
- let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
- local_ret
- }
-}
-
-// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
-// directly as a Deref trait in higher-level structs:
-impl std::ops::Deref for Payer {
- type Target = Self;
- fn deref(&self) -> &Self {
- self
- }
-}
-/// Calls the free function if one is set
-#[no_mangle]
-pub extern "C" fn Payer_free(this_ptr: Payer) { }
-impl Drop for Payer {
- fn drop(&mut self) {
- if let Some(f) = self.free {
- f(self.this_arg);
- }
- }
-}
-/// A trait defining behavior for routing an [`Invoice`] payment.
-#[repr(C)]
-pub struct Router {
- /// An opaque pointer which is passed to your function implementations as an argument.
- /// This has no meaning in the LDK, and can be NULL or any other value.
- pub this_arg: *mut c_void,
- /// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
- ///
- /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
- #[must_use]
- pub find_route: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, scorer: &crate::lightning::routing::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
- /// Frees any resources associated with this object given its this_arg pointer.
- /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
- pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
-}
-unsafe impl Send for Router {}
-unsafe impl Sync for Router {}
-#[no_mangle]
-pub(crate) extern "C" fn Router_clone_fields(orig: &Router) -> Router {
- Router {
- this_arg: orig.this_arg,
- find_route: Clone::clone(&orig.find_route),
- free: Clone::clone(&orig.free),
- }
-}
-
-use lightning_invoice::payment::Router as rustRouter;
-impl rustRouter<crate::lightning::routing::Score> for Router {
- fn find_route(&self, mut payer: &secp256k1::key::PublicKey, mut params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut scorer: &crate::lightning::routing::Score) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
- let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
- let mut ret = (self.find_route)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, scorer);
- let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
- local_ret
- }
-}
-
-// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
-// directly as a Deref trait in higher-level structs:
-impl std::ops::Deref for Router {
- type Target = Self;
- fn deref(&self) -> &Self {
- self
- }
-}
-/// Calls the free function if one is set
-#[no_mangle]
-pub extern "C" fn Router_free(this_ptr: Router) { }
-impl Drop for Router {
- fn drop(&mut self) {
- if let Some(f) = self.free {
- f(self.this_arg);
- }
- }
-}
-
-use lightning_invoice::payment::RetryAttempts as nativeRetryAttemptsImport;
-pub(crate) type nativeRetryAttempts = nativeRetryAttemptsImport;
-
-/// Number of attempts to retry payment path failures for an [`Invoice`].