+/// A processed incoming onion message, containing either a Forward (another onion message)
+/// or a Receive payload with decrypted contents.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum PeeledOnion {
+ /// Forwarded onion, with the next node id and a new onion
+ Forward(
+ crate::c_types::PublicKey,
+ crate::lightning::ln::msgs::OnionMessage),
+ /// Received onion message, with decrypted contents, path_id, and reply path
+ Receive(
+ crate::lightning::onion_message::packet::ParsedOnionMessageContents,
+ ///
+ /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ crate::c_types::ThirtyTwoBytes,
+ ///
+ /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ crate::lightning::blinded_path::BlindedPath),
+}
+use lightning::onion_message::messenger::PeeledOnion as PeeledOnionImport;
+pub(crate) type nativePeeledOnion = PeeledOnionImport<crate::lightning::onion_message::packet::OnionMessageContents>;
+
+impl PeeledOnion {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativePeeledOnion {
+ match self {
+ PeeledOnion::Forward (ref a, ref b, ) => {
+ let mut a_nonref = Clone::clone(a);
+ let mut b_nonref = Clone::clone(b);
+ nativePeeledOnion::Forward (
+ a_nonref.into_rust(),
+ *unsafe { Box::from_raw(b_nonref.take_inner()) },
+ )
+ },
+ PeeledOnion::Receive (ref a, ref b, ref c, ) => {
+ let mut a_nonref = Clone::clone(a);
+ let mut b_nonref = Clone::clone(b);
+ let mut local_b_nonref = if b_nonref.data == [0; 32] { None } else { Some( { b_nonref.data }) };
+ let mut c_nonref = Clone::clone(c);
+ let mut local_c_nonref = if c_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(c_nonref.take_inner()) } }) };
+ nativePeeledOnion::Receive (
+ a_nonref.into_native(),
+ local_b_nonref,
+ local_c_nonref,
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativePeeledOnion {
+ match self {
+ PeeledOnion::Forward (mut a, mut b, ) => {
+ nativePeeledOnion::Forward (
+ a.into_rust(),
+ *unsafe { Box::from_raw(b.take_inner()) },
+ )
+ },
+ PeeledOnion::Receive (mut a, mut b, mut c, ) => {
+ let mut local_b = if b.data == [0; 32] { None } else { Some( { b.data }) };
+ let mut local_c = if c.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(c.take_inner()) } }) };
+ nativePeeledOnion::Receive (
+ a.into_native(),
+ local_b,
+ local_c,
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativePeeledOnion) -> Self {
+ match native {
+ nativePeeledOnion::Forward (ref a, ref b, ) => {
+ let mut a_nonref = Clone::clone(a);
+ let mut b_nonref = Clone::clone(b);
+ PeeledOnion::Forward (
+ crate::c_types::PublicKey::from_rust(&a_nonref),
+ crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(b_nonref), is_owned: true },
+ )
+ },
+ nativePeeledOnion::Receive (ref a, ref b, ref c, ) => {
+ let mut a_nonref = Clone::clone(a);
+ let mut b_nonref = Clone::clone(b);
+ let mut local_b_nonref = if b_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (b_nonref.unwrap()) } } };
+ let mut c_nonref = Clone::clone(c);
+ let mut local_c_nonref = crate::lightning::blinded_path::BlindedPath { inner: if c_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((c_nonref.unwrap())) } }, is_owned: true };
+ PeeledOnion::Receive (
+ crate::lightning::onion_message::packet::ParsedOnionMessageContents::native_into(a_nonref),
+ local_b_nonref,
+ local_c_nonref,
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativePeeledOnion) -> Self {
+ match native {
+ nativePeeledOnion::Forward (mut a, mut b, ) => {
+ PeeledOnion::Forward (
+ crate::c_types::PublicKey::from_rust(&a),
+ crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(b), is_owned: true },
+ )
+ },
+ nativePeeledOnion::Receive (mut a, mut b, mut c, ) => {
+ let mut local_b = if b.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (b.unwrap()) } } };
+ let mut local_c = crate::lightning::blinded_path::BlindedPath { inner: if c.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((c.unwrap())) } }, is_owned: true };
+ PeeledOnion::Receive (
+ crate::lightning::onion_message::packet::ParsedOnionMessageContents::native_into(a),
+ local_b,
+ local_c,
+ )
+ },
+ }
+ }
+}
+/// Frees any resources used by the PeeledOnion
+#[no_mangle]
+pub extern "C" fn PeeledOnion_free(this_ptr: PeeledOnion) { }
+/// Creates a copy of the PeeledOnion
+#[no_mangle]
+pub extern "C" fn PeeledOnion_clone(orig: &PeeledOnion) -> PeeledOnion {
+ 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 PeeledOnion_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PeeledOnion)).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 PeeledOnion_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut PeeledOnion) };
+}
+#[no_mangle]
+/// Utility method to constructs a new Forward-variant PeeledOnion
+pub extern "C" fn PeeledOnion_forward(a: crate::c_types::PublicKey,b: crate::lightning::ln::msgs::OnionMessage) -> PeeledOnion {
+ PeeledOnion::Forward(a, b, )
+}
+#[no_mangle]
+/// Utility method to constructs a new Receive-variant PeeledOnion
+pub extern "C" fn PeeledOnion_receive(a: crate::lightning::onion_message::packet::ParsedOnionMessageContents,b: crate::c_types::ThirtyTwoBytes,c: crate::lightning::blinded_path::BlindedPath) -> PeeledOnion {
+ PeeledOnion::Receive(a, b, c, )
+}
+/// Creates an [`OnionMessage`] with the given `contents` for sending to the destination of
+/// `path`.
+///
+/// Returns both the node id of the peer to send the message to and the message itself.