Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / onion_message / messenger.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! LDK sends, receives, and forwards onion messages via the [`OnionMessenger`]. See its docs for
10 //! more information.
11
12 use alloc::str::FromStr;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
19
20
21 use lightning::onion_message::messenger::OnionMessenger as nativeOnionMessengerImport;
22 pub(crate) type nativeOnionMessenger = nativeOnionMessengerImport<crate::lightning::chain::keysinterface::EntropySource, crate::lightning::chain::keysinterface::NodeSigner, crate::lightning::util::logger::Logger, crate::lightning::onion_message::messenger::CustomOnionMessageHandler>;
23
24 /// A sender, receiver and forwarder of onion messages. In upcoming releases, this object will be
25 /// used to retrieve invoices and fulfill invoice requests from [offers]. Currently, only sending
26 /// and receiving custom onion messages is supported.
27 ///
28 /// # Example
29 ///
30 /// ```
31 /// # extern crate bitcoin;
32 /// # use bitcoin::hashes::_export::_core::time::Duration;
33 /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
34 /// # use lightning::chain::keysinterface::KeysManager;
35 /// # use lightning::ln::peer_handler::IgnoringMessageHandler;
36 /// # use lightning::onion_message::blinded_path::BlindedPath;
37 /// # use lightning::onion_message::messenger::{Destination, OnionMessenger};
38 /// # use lightning::onion_message::packet::{CustomOnionMessageContents, OnionMessageContents};
39 /// # use lightning::util::logger::{Logger, Record};
40 /// # use lightning::util::ser::{Writeable, Writer};
41 /// # use lightning::io;
42 /// # use std::sync::Arc;
43 /// # struct FakeLogger;
44 /// # impl Logger for FakeLogger {
45 /// #     fn log(&self, record: &Record) { unimplemented!() }
46 /// # }
47 /// # let seed = [42u8; 32];
48 /// # let time = Duration::from_secs(123456);
49 /// # let keys_manager = KeysManager::new(&seed, time.as_secs(), time.subsec_nanos());
50 /// # let logger = Arc::new(FakeLogger {});
51 /// # let node_secret = SecretKey::from_slice(&hex::decode(\"0101010101010101010101010101010101010101010101010101010101010101\").unwrap()[..]).unwrap();
52 /// # let secp_ctx = Secp256k1::new();
53 /// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret);
54 /// # let (hop_node_id2, hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1, hop_node_id1);
55 /// # let destination_node_id = hop_node_id1;
56 /// # let your_custom_message_handler = IgnoringMessageHandler {};
57 /// // Create the onion messenger. This must use the same `keys_manager` as is passed to your
58 /// // ChannelManager.
59 /// let onion_messenger = OnionMessenger::new(&keys_manager, &keys_manager, logger, &your_custom_message_handler);
60 ///
61 /// # struct YourCustomMessage {}
62 /// impl Writeable for YourCustomMessage {
63 /// \tfn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
64 /// \t\t# Ok(())
65 /// \t\t// Write your custom onion message to `w`
66 /// \t}
67 /// }
68 /// impl CustomOnionMessageContents for YourCustomMessage {
69 /// \tfn tlv_type(&self) -> u64 {
70 /// \t\t# let your_custom_message_type = 42;
71 /// \t\tyour_custom_message_type
72 /// \t}
73 /// }
74 /// // Send a custom onion message to a node id.
75 /// let intermediate_hops = [hop_node_id1, hop_node_id2];
76 /// let reply_path = None;
77 /// # let your_custom_message = YourCustomMessage {};
78 /// let message = OnionMessageContents::Custom(your_custom_message);
79 /// onion_messenger.send_onion_message(&intermediate_hops, Destination::Node(destination_node_id), message, reply_path);
80 ///
81 /// // Create a blinded path to yourself, for someone to send an onion message to.
82 /// # let your_node_id = hop_node_id1;
83 /// let hops = [hop_node_id3, hop_node_id4, your_node_id];
84 /// let blinded_path = BlindedPath::new(&hops, &keys_manager, &secp_ctx).unwrap();
85 ///
86 /// // Send a custom onion message to a blinded path.
87 /// # let intermediate_hops = [hop_node_id1, hop_node_id2];
88 /// let reply_path = None;
89 /// # let your_custom_message = YourCustomMessage {};
90 /// let message = OnionMessageContents::Custom(your_custom_message);
91 /// onion_messenger.send_onion_message(&intermediate_hops, Destination::BlindedPath(blinded_path), message, reply_path);
92 /// ```
93 ///
94 /// [offers]: <https://github.com/lightning/bolts/pull/798>
95 /// [`OnionMessenger`]: crate::onion_message::OnionMessenger
96 #[must_use]
97 #[repr(C)]
98 pub struct OnionMessenger {
99         /// A pointer to the opaque Rust object.
100
101         /// Nearly everywhere, inner must be non-null, however in places where
102         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
103         pub inner: *mut nativeOnionMessenger,
104         /// Indicates that this is the only struct which contains the same pointer.
105
106         /// Rust functions which take ownership of an object provided via an argument require
107         /// this to be true and invalidate the object pointed to by inner.
108         pub is_owned: bool,
109 }
110
111 impl Drop for OnionMessenger {
112         fn drop(&mut self) {
113                 if self.is_owned && !<*mut nativeOnionMessenger>::is_null(self.inner) {
114                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
115                 }
116         }
117 }
118 /// Frees any resources used by the OnionMessenger, if is_owned is set and inner is non-NULL.
119 #[no_mangle]
120 pub extern "C" fn OnionMessenger_free(this_obj: OnionMessenger) { }
121 #[allow(unused)]
122 /// Used only if an object of this type is returned as a trait impl by a method
123 pub(crate) extern "C" fn OnionMessenger_free_void(this_ptr: *mut c_void) {
124         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOnionMessenger) };
125 }
126 #[allow(unused)]
127 impl OnionMessenger {
128         pub(crate) fn get_native_ref(&self) -> &'static nativeOnionMessenger {
129                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
130         }
131         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionMessenger {
132                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
133         }
134         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
135         pub(crate) fn take_inner(mut self) -> *mut nativeOnionMessenger {
136                 assert!(self.is_owned);
137                 let ret = ObjOps::untweak_ptr(self.inner);
138                 self.inner = core::ptr::null_mut();
139                 ret
140         }
141 }
142 /// The destination of an onion message.
143 #[derive(Clone)]
144 #[must_use]
145 #[repr(C)]
146 pub enum Destination {
147         /// We're sending this onion message to a node.
148         Node(
149                 crate::c_types::PublicKey),
150         /// We're sending this onion message to a blinded path.
151         BlindedPath(
152                 crate::lightning::onion_message::blinded_path::BlindedPath),
153 }
154 use lightning::onion_message::messenger::Destination as DestinationImport;
155 pub(crate) type nativeDestination = DestinationImport;
156
157 impl Destination {
158         #[allow(unused)]
159         pub(crate) fn to_native(&self) -> nativeDestination {
160                 match self {
161                         Destination::Node (ref a, ) => {
162                                 let mut a_nonref = Clone::clone(a);
163                                 nativeDestination::Node (
164                                         a_nonref.into_rust(),
165                                 )
166                         },
167                         Destination::BlindedPath (ref a, ) => {
168                                 let mut a_nonref = Clone::clone(a);
169                                 nativeDestination::BlindedPath (
170                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
171                                 )
172                         },
173                 }
174         }
175         #[allow(unused)]
176         pub(crate) fn into_native(self) -> nativeDestination {
177                 match self {
178                         Destination::Node (mut a, ) => {
179                                 nativeDestination::Node (
180                                         a.into_rust(),
181                                 )
182                         },
183                         Destination::BlindedPath (mut a, ) => {
184                                 nativeDestination::BlindedPath (
185                                         *unsafe { Box::from_raw(a.take_inner()) },
186                                 )
187                         },
188                 }
189         }
190         #[allow(unused)]
191         pub(crate) fn from_native(native: &nativeDestination) -> Self {
192                 match native {
193                         nativeDestination::Node (ref a, ) => {
194                                 let mut a_nonref = Clone::clone(a);
195                                 Destination::Node (
196                                         crate::c_types::PublicKey::from_rust(&a_nonref),
197                                 )
198                         },
199                         nativeDestination::BlindedPath (ref a, ) => {
200                                 let mut a_nonref = Clone::clone(a);
201                                 Destination::BlindedPath (
202                                         crate::lightning::onion_message::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
203                                 )
204                         },
205                 }
206         }
207         #[allow(unused)]
208         pub(crate) fn native_into(native: nativeDestination) -> Self {
209                 match native {
210                         nativeDestination::Node (mut a, ) => {
211                                 Destination::Node (
212                                         crate::c_types::PublicKey::from_rust(&a),
213                                 )
214                         },
215                         nativeDestination::BlindedPath (mut a, ) => {
216                                 Destination::BlindedPath (
217                                         crate::lightning::onion_message::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(a), is_owned: true },
218                                 )
219                         },
220                 }
221         }
222 }
223 /// Frees any resources used by the Destination
224 #[no_mangle]
225 pub extern "C" fn Destination_free(this_ptr: Destination) { }
226 /// Creates a copy of the Destination
227 #[no_mangle]
228 pub extern "C" fn Destination_clone(orig: &Destination) -> Destination {
229         orig.clone()
230 }
231 #[no_mangle]
232 /// Utility method to constructs a new Node-variant Destination
233 pub extern "C" fn Destination_node(a: crate::c_types::PublicKey) -> Destination {
234         Destination::Node(a, )
235 }
236 #[no_mangle]
237 /// Utility method to constructs a new BlindedPath-variant Destination
238 pub extern "C" fn Destination_blinded_path(a: crate::lightning::onion_message::blinded_path::BlindedPath) -> Destination {
239         Destination::BlindedPath(a, )
240 }
241 /// Errors that may occur when [sending an onion message].
242 ///
243 /// [sending an onion message]: OnionMessenger::send_onion_message
244 #[derive(Clone)]
245 #[must_use]
246 #[repr(C)]
247 pub enum SendError {
248         /// Errored computing onion message packet keys.
249         Secp256k1(
250                 crate::c_types::Secp256k1Error),
251         /// Because implementations such as Eclair will drop onion messages where the message packet
252         /// exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
253         TooBigPacket,
254         /// The provided [`Destination`] was an invalid [`BlindedPath`], due to having fewer than two
255         /// blinded hops.
256         TooFewBlindedHops,
257         /// Our next-hop peer was offline or does not support onion message forwarding.
258         InvalidFirstHop,
259         /// Onion message contents must have a TLV type >= 64.
260         InvalidMessage,
261         /// Our next-hop peer's buffer was full or our total outbound buffer was full.
262         BufferFull,
263         /// Failed to retrieve our node id from the provided [`NodeSigner`].
264         ///
265         /// [`NodeSigner`]: crate::chain::keysinterface::NodeSigner
266         GetNodeIdFailed,
267         /// We attempted to send to a blinded path where we are the introduction node, and failed to
268         /// advance the blinded path to make the second hop the new introduction node. Either
269         /// [`NodeSigner::ecdh`] failed, we failed to tweak the current blinding point to get the
270         /// new blinding point, or we were attempting to send to ourselves.
271         BlindedPathAdvanceFailed,
272 }
273 use lightning::onion_message::messenger::SendError as SendErrorImport;
274 pub(crate) type nativeSendError = SendErrorImport;
275
276 impl SendError {
277         #[allow(unused)]
278         pub(crate) fn to_native(&self) -> nativeSendError {
279                 match self {
280                         SendError::Secp256k1 (ref a, ) => {
281                                 let mut a_nonref = Clone::clone(a);
282                                 nativeSendError::Secp256k1 (
283                                         a_nonref.into_rust(),
284                                 )
285                         },
286                         SendError::TooBigPacket => nativeSendError::TooBigPacket,
287                         SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
288                         SendError::InvalidFirstHop => nativeSendError::InvalidFirstHop,
289                         SendError::InvalidMessage => nativeSendError::InvalidMessage,
290                         SendError::BufferFull => nativeSendError::BufferFull,
291                         SendError::GetNodeIdFailed => nativeSendError::GetNodeIdFailed,
292                         SendError::BlindedPathAdvanceFailed => nativeSendError::BlindedPathAdvanceFailed,
293                 }
294         }
295         #[allow(unused)]
296         pub(crate) fn into_native(self) -> nativeSendError {
297                 match self {
298                         SendError::Secp256k1 (mut a, ) => {
299                                 nativeSendError::Secp256k1 (
300                                         a.into_rust(),
301                                 )
302                         },
303                         SendError::TooBigPacket => nativeSendError::TooBigPacket,
304                         SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
305                         SendError::InvalidFirstHop => nativeSendError::InvalidFirstHop,
306                         SendError::InvalidMessage => nativeSendError::InvalidMessage,
307                         SendError::BufferFull => nativeSendError::BufferFull,
308                         SendError::GetNodeIdFailed => nativeSendError::GetNodeIdFailed,
309                         SendError::BlindedPathAdvanceFailed => nativeSendError::BlindedPathAdvanceFailed,
310                 }
311         }
312         #[allow(unused)]
313         pub(crate) fn from_native(native: &nativeSendError) -> Self {
314                 match native {
315                         nativeSendError::Secp256k1 (ref a, ) => {
316                                 let mut a_nonref = Clone::clone(a);
317                                 SendError::Secp256k1 (
318                                         crate::c_types::Secp256k1Error::from_rust(a_nonref),
319                                 )
320                         },
321                         nativeSendError::TooBigPacket => SendError::TooBigPacket,
322                         nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
323                         nativeSendError::InvalidFirstHop => SendError::InvalidFirstHop,
324                         nativeSendError::InvalidMessage => SendError::InvalidMessage,
325                         nativeSendError::BufferFull => SendError::BufferFull,
326                         nativeSendError::GetNodeIdFailed => SendError::GetNodeIdFailed,
327                         nativeSendError::BlindedPathAdvanceFailed => SendError::BlindedPathAdvanceFailed,
328                 }
329         }
330         #[allow(unused)]
331         pub(crate) fn native_into(native: nativeSendError) -> Self {
332                 match native {
333                         nativeSendError::Secp256k1 (mut a, ) => {
334                                 SendError::Secp256k1 (
335                                         crate::c_types::Secp256k1Error::from_rust(a),
336                                 )
337                         },
338                         nativeSendError::TooBigPacket => SendError::TooBigPacket,
339                         nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
340                         nativeSendError::InvalidFirstHop => SendError::InvalidFirstHop,
341                         nativeSendError::InvalidMessage => SendError::InvalidMessage,
342                         nativeSendError::BufferFull => SendError::BufferFull,
343                         nativeSendError::GetNodeIdFailed => SendError::GetNodeIdFailed,
344                         nativeSendError::BlindedPathAdvanceFailed => SendError::BlindedPathAdvanceFailed,
345                 }
346         }
347 }
348 /// Frees any resources used by the SendError
349 #[no_mangle]
350 pub extern "C" fn SendError_free(this_ptr: SendError) { }
351 /// Creates a copy of the SendError
352 #[no_mangle]
353 pub extern "C" fn SendError_clone(orig: &SendError) -> SendError {
354         orig.clone()
355 }
356 #[no_mangle]
357 /// Utility method to constructs a new Secp256k1-variant SendError
358 pub extern "C" fn SendError_secp256k1(a: crate::c_types::Secp256k1Error) -> SendError {
359         SendError::Secp256k1(a, )
360 }
361 #[no_mangle]
362 /// Utility method to constructs a new TooBigPacket-variant SendError
363 pub extern "C" fn SendError_too_big_packet() -> SendError {
364         SendError::TooBigPacket}
365 #[no_mangle]
366 /// Utility method to constructs a new TooFewBlindedHops-variant SendError
367 pub extern "C" fn SendError_too_few_blinded_hops() -> SendError {
368         SendError::TooFewBlindedHops}
369 #[no_mangle]
370 /// Utility method to constructs a new InvalidFirstHop-variant SendError
371 pub extern "C" fn SendError_invalid_first_hop() -> SendError {
372         SendError::InvalidFirstHop}
373 #[no_mangle]
374 /// Utility method to constructs a new InvalidMessage-variant SendError
375 pub extern "C" fn SendError_invalid_message() -> SendError {
376         SendError::InvalidMessage}
377 #[no_mangle]
378 /// Utility method to constructs a new BufferFull-variant SendError
379 pub extern "C" fn SendError_buffer_full() -> SendError {
380         SendError::BufferFull}
381 #[no_mangle]
382 /// Utility method to constructs a new GetNodeIdFailed-variant SendError
383 pub extern "C" fn SendError_get_node_id_failed() -> SendError {
384         SendError::GetNodeIdFailed}
385 #[no_mangle]
386 /// Utility method to constructs a new BlindedPathAdvanceFailed-variant SendError
387 pub extern "C" fn SendError_blinded_path_advance_failed() -> SendError {
388         SendError::BlindedPathAdvanceFailed}
389 /// Checks if two SendErrors contain equal inner contents.
390 /// This ignores pointers and is_owned flags and looks at the values in fields.
391 #[no_mangle]
392 pub extern "C" fn SendError_eq(a: &SendError, b: &SendError) -> bool {
393         if &a.to_native() == &b.to_native() { true } else { false }
394 }
395 /// Handler for custom onion messages. If you are using [`SimpleArcOnionMessenger`],
396 /// [`SimpleRefOnionMessenger`], or prefer to ignore inbound custom onion messages,
397 /// [`IgnoringMessageHandler`] must be provided to [`OnionMessenger::new`]. Otherwise, a custom
398 /// implementation of this trait must be provided, with [`CustomMessage`] specifying the supported
399 /// message types.
400 ///
401 /// See [`OnionMessenger`] for example usage.
402 ///
403 /// [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
404 /// [`CustomMessage`]: Self::CustomMessage
405 #[repr(C)]
406 pub struct CustomOnionMessageHandler {
407         /// An opaque pointer which is passed to your function implementations as an argument.
408         /// This has no meaning in the LDK, and can be NULL or any other value.
409         pub this_arg: *mut c_void,
410         /// Called with the custom message that was received.
411         pub handle_custom_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::onion_message::packet::CustomOnionMessageContents),
412         /// Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
413         /// message type is unknown.
414         #[must_use]
415         pub read_custom_message: extern "C" fn (this_arg: *const c_void, message_type: u64, buffer: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_CustomOnionMessageContentsZDecodeErrorZ,
416         /// Frees any resources associated with this object given its this_arg pointer.
417         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
418         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
419 }
420 unsafe impl Send for CustomOnionMessageHandler {}
421 unsafe impl Sync for CustomOnionMessageHandler {}
422 #[no_mangle]
423 pub(crate) extern "C" fn CustomOnionMessageHandler_clone_fields(orig: &CustomOnionMessageHandler) -> CustomOnionMessageHandler {
424         CustomOnionMessageHandler {
425                 this_arg: orig.this_arg,
426                 handle_custom_message: Clone::clone(&orig.handle_custom_message),
427                 read_custom_message: Clone::clone(&orig.read_custom_message),
428                 free: Clone::clone(&orig.free),
429         }
430 }
431
432 use lightning::onion_message::messenger::CustomOnionMessageHandler as rustCustomOnionMessageHandler;
433 impl rustCustomOnionMessageHandler for CustomOnionMessageHandler {
434         type CustomMessage = crate::lightning::onion_message::packet::CustomOnionMessageContents;
435         fn handle_custom_message(&self, mut msg: crate::lightning::onion_message::packet::CustomOnionMessageContents) {
436                 (self.handle_custom_message)(self.this_arg, Into::into(msg))
437         }
438         fn read_custom_message<R:crate::c_types::io::Read>(&self, mut message_type: u64, mut buffer: &mut R) -> Result<Option<crate::lightning::onion_message::packet::CustomOnionMessageContents>, lightning::ln::msgs::DecodeError> {
439                 let mut ret = (self.read_custom_message)(self.this_arg, message_type, crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec(buffer)));
440                 let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = { /* (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ let ret_0_opt = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }); { } if ret_0_opt.is_none() { None } else { Some({ ret_0_opt.take() }) } }; local_ret_0 }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
441                 local_ret
442         }
443 }
444
445 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
446 // directly as a Deref trait in higher-level structs:
447 impl core::ops::Deref for CustomOnionMessageHandler {
448         type Target = Self;
449         fn deref(&self) -> &Self {
450                 self
451         }
452 }
453 /// Calls the free function if one is set
454 #[no_mangle]
455 pub extern "C" fn CustomOnionMessageHandler_free(this_ptr: CustomOnionMessageHandler) { }
456 impl Drop for CustomOnionMessageHandler {
457         fn drop(&mut self) {
458                 if let Some(f) = self.free {
459                         f(self.this_arg);
460                 }
461         }
462 }
463 /// Constructs a new `OnionMessenger` to send, forward, and delegate received onion messages to
464 /// their respective handlers.
465 #[must_use]
466 #[no_mangle]
467 pub extern "C" fn OnionMessenger_new(mut entropy_source: crate::lightning::chain::keysinterface::EntropySource, mut node_signer: crate::lightning::chain::keysinterface::NodeSigner, mut logger: crate::lightning::util::logger::Logger, mut custom_handler: crate::lightning::onion_message::messenger::CustomOnionMessageHandler) -> crate::lightning::onion_message::messenger::OnionMessenger {
468         let mut ret = lightning::onion_message::messenger::OnionMessenger::new(entropy_source, node_signer, logger, custom_handler);
469         crate::lightning::onion_message::messenger::OnionMessenger { inner: ObjOps::heap_alloc(ret), is_owned: true }
470 }
471
472 /// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
473 /// See [`OnionMessenger`] for example usage.
474 ///
475 /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None
476 #[must_use]
477 #[no_mangle]
478 pub extern "C" fn OnionMessenger_send_onion_message(this_arg: &crate::lightning::onion_message::messenger::OnionMessenger, mut intermediate_nodes: crate::c_types::derived::CVec_PublicKeyZ, mut destination: crate::lightning::onion_message::messenger::Destination, mut message: crate::lightning::onion_message::packet::OnionMessageContents, mut reply_path: crate::lightning::onion_message::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_NoneSendErrorZ {
479         let mut local_intermediate_nodes = Vec::new(); for mut item in intermediate_nodes.into_rust().drain(..) { local_intermediate_nodes.push( { item.into_rust() }); };
480         let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) };
481         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_onion_message(&local_intermediate_nodes[..], destination.into_native(), message.into_native(), local_reply_path);
482         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::onion_message::messenger::SendError::native_into(e) }).into() };
483         local_ret
484 }
485
486 impl From<nativeOnionMessenger> for crate::lightning::ln::msgs::OnionMessageHandler {
487         fn from(obj: nativeOnionMessenger) -> Self {
488                 let mut rust_obj = OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true };
489                 let mut ret = OnionMessenger_as_OnionMessageHandler(&rust_obj);
490                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
491                 rust_obj.inner = core::ptr::null_mut();
492                 ret.free = Some(OnionMessenger_free_void);
493                 ret
494         }
495 }
496 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
497 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
498 #[no_mangle]
499 pub extern "C" fn OnionMessenger_as_OnionMessageHandler(this_arg: &OnionMessenger) -> crate::lightning::ln::msgs::OnionMessageHandler {
500         crate::lightning::ln::msgs::OnionMessageHandler {
501                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
502                 free: None,
503                 handle_onion_message: OnionMessenger_OnionMessageHandler_handle_onion_message,
504                 peer_connected: OnionMessenger_OnionMessageHandler_peer_connected,
505                 peer_disconnected: OnionMessenger_OnionMessageHandler_peer_disconnected,
506                 provided_node_features: OnionMessenger_OnionMessageHandler_provided_node_features,
507                 provided_init_features: OnionMessenger_OnionMessageHandler_provided_init_features,
508                 OnionMessageProvider: crate::lightning::util::events::OnionMessageProvider {
509                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
510                         free: None,
511                         next_onion_message_for_peer: OnionMessenger_OnionMessageProvider_next_onion_message_for_peer,
512                 },
513         }
514 }
515
516 extern "C" fn OnionMessenger_OnionMessageHandler_handle_onion_message(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OnionMessage) {
517         <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::handle_onion_message(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &peer_node_id.into_rust(), msg.get_native_ref())
518 }
519 #[must_use]
520 extern "C" fn OnionMessenger_OnionMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init, mut inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ {
521         let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust(), init.get_native_ref(), inbound);
522         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
523         local_ret
524 }
525 extern "C" fn OnionMessenger_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
526         <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust())
527 }
528 #[must_use]
529 extern "C" fn OnionMessenger_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
530         let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, );
531         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
532 }
533 #[must_use]
534 extern "C" fn OnionMessenger_OnionMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
535         let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust());
536         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
537 }
538
539 impl From<nativeOnionMessenger> for crate::lightning::util::events::OnionMessageProvider {
540         fn from(obj: nativeOnionMessenger) -> Self {
541                 let mut rust_obj = OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true };
542                 let mut ret = OnionMessenger_as_OnionMessageProvider(&rust_obj);
543                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
544                 rust_obj.inner = core::ptr::null_mut();
545                 ret.free = Some(OnionMessenger_free_void);
546                 ret
547         }
548 }
549 /// Constructs a new OnionMessageProvider which calls the relevant methods on this_arg.
550 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageProvider must be freed before this_arg is
551 #[no_mangle]
552 pub extern "C" fn OnionMessenger_as_OnionMessageProvider(this_arg: &OnionMessenger) -> crate::lightning::util::events::OnionMessageProvider {
553         crate::lightning::util::events::OnionMessageProvider {
554                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
555                 free: None,
556                 next_onion_message_for_peer: OnionMessenger_OnionMessageProvider_next_onion_message_for_peer,
557         }
558 }
559
560 #[must_use]
561 extern "C" fn OnionMessenger_OnionMessageProvider_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage {
562         let mut ret = <nativeOnionMessenger as lightning::util::events::OnionMessageProvider<>>::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, peer_node_id.into_rust());
563         let mut local_ret = crate::lightning::ln::msgs::OnionMessage { inner: if ret.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
564         local_ret
565 }
566