+/// 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: &PeeledOnionImport<crate::lightning::onion_message::packet::OnionMessageContents>) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativePeeledOnion) };
+ 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 the node id of the peer to send the message to, the message itself, and any addresses
+/// need to connect to the first node.
+///
+/// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None
+#[no_mangle]
+pub extern "C" fn create_onion_message(entropy_source: &crate::lightning::sign::EntropySource, node_signer: &crate::lightning::sign::NodeSigner, mut path: crate::lightning::onion_message::messenger::OnionMessagePath, mut contents: crate::lightning::onion_message::packet::OnionMessageContents, mut reply_path: crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_C3Tuple_PublicKeyOnionMessageCOption_CVec_SocketAddressZZZSendErrorZ {
+ let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) };
+ let mut ret = lightning::onion_message::messenger::create_onion_message::<crate::lightning::sign::EntropySource, crate::lightning::sign::NodeSigner, crate::lightning::onion_message::packet::OnionMessageContents>(entropy_source, node_signer, secp256k1::global::SECP256K1, *unsafe { Box::from_raw(path.take_inner()) }, contents, local_reply_path);
+ 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_orig_ret_0_2 = if orig_ret_0_2.is_none() { crate::c_types::derived::COption_CVec_SocketAddressZZ::None } else { crate::c_types::derived::COption_CVec_SocketAddressZZ::Some( { let mut local_orig_ret_0_2_0 = Vec::new(); for mut item in orig_ret_0_2.unwrap().drain(..) { local_orig_ret_0_2_0.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; local_orig_ret_0_2_0.into() }) }; let mut local_ret_0 = (crate::c_types::PublicKey::from_rust(&orig_ret_0_0), crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(orig_ret_0_1), is_owned: true }, local_orig_ret_0_2).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::onion_message::messenger::SendError::native_into(e) }).into() };
+ local_ret
+}
+
+/// Decode one layer of an incoming [`OnionMessage`].
+///
+/// Returns either the next layer of the onion for forwarding or the decrypted content for the
+/// receiver.
+#[no_mangle]
+pub extern "C" fn peel_onion_message(msg: &crate::lightning::ln::msgs::OnionMessage, mut node_signer: crate::lightning::sign::NodeSigner, mut logger: crate::lightning::util::logger::Logger, mut custom_handler: crate::lightning::onion_message::messenger::CustomOnionMessageHandler) -> crate::c_types::derived::CResult_PeeledOnionNoneZ {
+ let mut ret = lightning::onion_message::messenger::peel_onion_message::<crate::lightning::sign::NodeSigner, crate::lightning::util::logger::Logger, crate::lightning::onion_message::messenger::CustomOnionMessageHandler>(msg.get_native_ref(), secp256k1::global::SECP256K1, node_signer, logger, custom_handler);
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::onion_message::messenger::PeeledOnion::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
+ local_ret
+}
+