+/// Checks if two PaymentSendFailures contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn PaymentSendFailure_eq(a: &PaymentSendFailure, b: &PaymentSendFailure) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+/// Indicates that we failed to send a payment probe. Further errors may be surfaced later via
+/// [`Event::ProbeFailed`].
+///
+/// [`Event::ProbeFailed`]: crate::events::Event::ProbeFailed
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum ProbeSendFailure {
+ /// We were unable to find a route to the destination.
+ RouteNotFound,
+ /// We failed to send the payment probes.
+ SendingFailed(
+ crate::lightning::ln::outbound_payment::PaymentSendFailure),
+}
+use lightning::ln::outbound_payment::ProbeSendFailure as ProbeSendFailureImport;
+pub(crate) type nativeProbeSendFailure = ProbeSendFailureImport;
+
+impl ProbeSendFailure {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeProbeSendFailure {
+ match self {
+ ProbeSendFailure::RouteNotFound => nativeProbeSendFailure::RouteNotFound,
+ ProbeSendFailure::SendingFailed (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeProbeSendFailure::SendingFailed (
+ a_nonref.into_native(),
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeProbeSendFailure {
+ match self {
+ ProbeSendFailure::RouteNotFound => nativeProbeSendFailure::RouteNotFound,
+ ProbeSendFailure::SendingFailed (mut a, ) => {
+ nativeProbeSendFailure::SendingFailed (
+ a.into_native(),
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeProbeSendFailure) -> Self {
+ match native {
+ nativeProbeSendFailure::RouteNotFound => ProbeSendFailure::RouteNotFound,
+ nativeProbeSendFailure::SendingFailed (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ProbeSendFailure::SendingFailed (
+ crate::lightning::ln::outbound_payment::PaymentSendFailure::native_into(a_nonref),
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeProbeSendFailure) -> Self {
+ match native {
+ nativeProbeSendFailure::RouteNotFound => ProbeSendFailure::RouteNotFound,
+ nativeProbeSendFailure::SendingFailed (mut a, ) => {
+ ProbeSendFailure::SendingFailed (
+ crate::lightning::ln::outbound_payment::PaymentSendFailure::native_into(a),
+ )
+ },
+ }
+ }
+}
+/// Frees any resources used by the ProbeSendFailure
+#[no_mangle]
+pub extern "C" fn ProbeSendFailure_free(this_ptr: ProbeSendFailure) { }
+/// Creates a copy of the ProbeSendFailure
+#[no_mangle]
+pub extern "C" fn ProbeSendFailure_clone(orig: &ProbeSendFailure) -> ProbeSendFailure {
+ orig.clone()
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn ProbeSendFailure_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ProbeSendFailure)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn ProbeSendFailure_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut ProbeSendFailure) };
+}
+#[no_mangle]
+/// Utility method to constructs a new RouteNotFound-variant ProbeSendFailure
+pub extern "C" fn ProbeSendFailure_route_not_found() -> ProbeSendFailure {
+ ProbeSendFailure::RouteNotFound}
+#[no_mangle]
+/// Utility method to constructs a new SendingFailed-variant ProbeSendFailure
+pub extern "C" fn ProbeSendFailure_sending_failed(a: crate::lightning::ln::outbound_payment::PaymentSendFailure) -> ProbeSendFailure {
+ ProbeSendFailure::SendingFailed(a, )
+}
+/// Checks if two ProbeSendFailures contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn ProbeSendFailure_eq(a: &ProbeSendFailure, b: &ProbeSendFailure) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+
+use lightning::ln::outbound_payment::RecipientOnionFields as nativeRecipientOnionFieldsImport;
+pub(crate) type nativeRecipientOnionFields = nativeRecipientOnionFieldsImport;
+
+/// Information which is provided, encrypted, to the payment recipient when sending HTLCs.
+///
+/// This should generally be constructed with data communicated to us from the recipient (via a
+/// BOLT11 or BOLT12 invoice).
+#[must_use]
+#[repr(C)]
+pub struct RecipientOnionFields {
+ /// 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 nativeRecipientOnionFields,
+ /// 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 RecipientOnionFields {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeRecipientOnionFields>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the RecipientOnionFields, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_free(this_obj: RecipientOnionFields) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn RecipientOnionFields_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRecipientOnionFields) };
+}
+#[allow(unused)]
+impl RecipientOnionFields {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeRecipientOnionFields {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRecipientOnionFields {
+ 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 nativeRecipientOnionFields {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+}
+/// The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
+/// in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
+/// authenticate the sender to the recipient and prevent payment-probing (deanonymization)
+/// attacks.
+///
+/// If you do not have one, the [`Route`] you pay over must not contain multiple paths as
+/// multi-path payments require a recipient-provided secret.
+///
+/// Some implementations may reject spontaneous payments with payment secrets, so you may only
+/// want to provide a secret for a spontaneous payment if MPP is needed and you know your
+/// recipient will not reject it.
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_get_payment_secret(this_ptr: &RecipientOnionFields) -> crate::c_types::derived::COption_ThirtyTwoBytesZ {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_secret;
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*inner_val.as_ref().unwrap()).clone().0 } }) };
+ local_inner_val
+}
+/// The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
+/// in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
+/// authenticate the sender to the recipient and prevent payment-probing (deanonymization)
+/// attacks.
+///
+/// If you do not have one, the [`Route`] you pay over must not contain multiple paths as
+/// multi-path payments require a recipient-provided secret.
+///
+/// Some implementations may reject spontaneous payments with payment secrets, so you may only
+/// want to provide a secret for a spontaneous payment if MPP is needed and you know your
+/// recipient will not reject it.
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_set_payment_secret(this_ptr: &mut RecipientOnionFields, mut val: crate::c_types::derived::COption_ThirtyTwoBytesZ) {
+ let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentSecret({ val_opt.take() }.data) }})} };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_secret = local_val;
+}
+/// The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
+/// arbitrary length. This gives recipients substantially more flexibility to receive
+/// additional data.
+///
+/// In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
+/// scheme to authenticate received payments against expected payments and invoices, this field
+/// is not used in LDK for received payments, and can be used to store arbitrary data in
+/// invoices which will be received with the payment.
+///
+/// Note that this field was added to the lightning specification more recently than
+/// [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
+/// may not be supported as universally.
+///
+/// Returns a copy of the field.
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_get_payment_metadata(this_ptr: &RecipientOnionFields) -> crate::c_types::derived::COption_CVec_u8ZZ {
+ let mut inner_val = this_ptr.get_native_mut_ref().payment_metadata.clone();
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_inner_val_0 = Vec::new(); for mut item in inner_val.unwrap().drain(..) { local_inner_val_0.push( { item }); }; local_inner_val_0.into() }) };
+ local_inner_val
+}
+/// The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
+/// arbitrary length. This gives recipients substantially more flexibility to receive
+/// additional data.
+///
+/// In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
+/// scheme to authenticate received payments against expected payments and invoices, this field
+/// is not used in LDK for received payments, and can be used to store arbitrary data in
+/// invoices which will be received with the payment.
+///
+/// Note that this field was added to the lightning specification more recently than
+/// [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
+/// may not be supported as universally.
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_set_payment_metadata(this_ptr: &mut RecipientOnionFields, mut val: crate::c_types::derived::COption_CVec_u8ZZ) {
+ let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { let mut local_val_0 = Vec::new(); for mut item in { val_opt.take() }.into_rust().drain(..) { local_val_0.push( { item }); }; local_val_0 }})} };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_metadata = local_val;
+}
+impl Clone for RecipientOnionFields {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeRecipientOnionFields>::is_null(self.inner) { core::ptr::null_mut() } else {
+ ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
+ is_owned: true,
+ }
+ }
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn RecipientOnionFields_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRecipientOnionFields)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the RecipientOnionFields
+pub extern "C" fn RecipientOnionFields_clone(orig: &RecipientOnionFields) -> RecipientOnionFields {
+ orig.clone()
+}
+/// Checks if two RecipientOnionFieldss contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+/// Two objects with NULL inner values will be considered "equal" here.
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_eq(a: &RecipientOnionFields, b: &RecipientOnionFields) -> bool {
+ if a.inner == b.inner { return true; }
+ if a.inner.is_null() || b.inner.is_null() { return false; }
+ if a.get_native_ref() == b.get_native_ref() { true } else { false }
+}
+#[no_mangle]
+/// Serialize the RecipientOnionFields object into a byte array which can be read by RecipientOnionFields_read
+pub extern "C" fn RecipientOnionFields_write(obj: &crate::lightning::ln::outbound_payment::RecipientOnionFields) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
+}
+#[allow(unused)]
+pub(crate) extern "C" fn RecipientOnionFields_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRecipientOnionFields) })
+}
+#[no_mangle]
+/// Read a RecipientOnionFields from a byte array, created by RecipientOnionFields_write
+pub extern "C" fn RecipientOnionFields_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RecipientOnionFieldsDecodeErrorZ {
+ let res: Result<lightning::ln::outbound_payment::RecipientOnionFields, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
+ local_res
+}
+/// Creates a [`RecipientOnionFields`] from only a [`PaymentSecret`]. This is the most common
+/// set of onion fields for today's BOLT11 invoices - most nodes require a [`PaymentSecret`]
+/// but do not require or provide any further data.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_secret_only(mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::lightning::ln::outbound_payment::RecipientOnionFields {
+ let mut ret = lightning::ln::outbound_payment::RecipientOnionFields::secret_only(::lightning::ln::PaymentSecret(payment_secret.data));
+ crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// Creates a new [`RecipientOnionFields`] with no fields. This generally does not create
+/// payable HTLCs except for single-path spontaneous payments, i.e. this should generally
+/// only be used for calls to [`ChannelManager::send_spontaneous_payment`]. If you are sending
+/// a spontaneous MPP this will not work as all MPP require payment secrets; you may
+/// instead want to use [`RecipientOnionFields::secret_only`].
+///
+/// [`ChannelManager::send_spontaneous_payment`]: super::channelmanager::ChannelManager::send_spontaneous_payment
+/// [`RecipientOnionFields::secret_only`]: RecipientOnionFields::secret_only
+#[must_use]
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_spontaneous_empty() -> crate::lightning::ln::outbound_payment::RecipientOnionFields {
+ let mut ret = lightning::ln::outbound_payment::RecipientOnionFields::spontaneous_empty();
+ crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// Creates a new [`RecipientOnionFields`] from an existing one, adding custom TLVs. Each
+/// TLV is provided as a `(u64, Vec<u8>)` for the type number and serialized value
+/// respectively. TLV type numbers must be unique and within the range
+/// reserved for custom types, i.e. >= 2^16, otherwise this method will return `Err(())`.
+///
+/// This method will also error for types in the experimental range which have been
+/// standardized within the protocol, which only includes 5482373484 (keysend) for now.
+///
+/// See [`Self::custom_tlvs`] for more info.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_with_custom_tlvs(mut this_arg: crate::lightning::ln::outbound_payment::RecipientOnionFields, mut custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ) -> crate::c_types::derived::CResult_RecipientOnionFieldsNoneZ {
+ let mut local_custom_tlvs = Vec::new(); for mut item in custom_tlvs.into_rust().drain(..) { local_custom_tlvs.push( { let (mut orig_custom_tlvs_0_0, mut orig_custom_tlvs_0_1) = item.to_rust(); let mut local_orig_custom_tlvs_0_1 = Vec::new(); for mut item in orig_custom_tlvs_0_1.into_rust().drain(..) { local_orig_custom_tlvs_0_1.push( { item }); }; let mut local_custom_tlvs_0 = (orig_custom_tlvs_0_0, local_orig_custom_tlvs_0_1); local_custom_tlvs_0 }); };
+ let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).with_custom_tlvs(local_custom_tlvs);
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
+ local_ret
+}
+
+/// Gets the custom TLVs that will be sent or have been received.
+///
+/// Custom TLVs allow sending extra application-specific data with a payment. They provide
+/// additional flexibility on top of payment metadata, as while other implementations may
+/// require `payment_metadata` to reflect metadata provided in an invoice, custom TLVs
+/// do not have this restriction.
+///
+/// Note that if this field is non-empty, it will contain strictly increasing TLVs, each
+/// represented by a `(u64, Vec<u8>)` for its type number and serialized value respectively.
+/// This is validated when setting this field using [`Self::with_custom_tlvs`].
+#[must_use]
+#[no_mangle]
+pub extern "C" fn RecipientOnionFields_custom_tlvs(this_arg: &crate::lightning::ln::outbound_payment::RecipientOnionFields) -> crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.custom_tlvs();
+ let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { item }); }; let mut local_ret_0 = (orig_ret_0_0, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
+ local_ret.into()
+}
+