+/// A trait indicating an object may generate onion messages to send
+#[repr(C)]
+pub struct OnionMessageProvider {
+ /// 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,
+ /// Gets the next pending onion message for the peer with the given node id.
+ ///
+ /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
+ #[must_use]
+ pub next_onion_message_for_peer: extern "C" fn (this_arg: *const c_void, peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage,
+ /// 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 OnionMessageProvider {}
+unsafe impl Sync for OnionMessageProvider {}
+#[no_mangle]
+pub(crate) extern "C" fn OnionMessageProvider_clone_fields(orig: &OnionMessageProvider) -> OnionMessageProvider {
+ OnionMessageProvider {
+ this_arg: orig.this_arg,
+ next_onion_message_for_peer: Clone::clone(&orig.next_onion_message_for_peer),
+ free: Clone::clone(&orig.free),
+ }
+}
+
+use lightning::util::events::OnionMessageProvider as rustOnionMessageProvider;
+impl rustOnionMessageProvider for OnionMessageProvider {
+ fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option<lightning::ln::msgs::OnionMessage> {
+ let mut ret = (self.next_onion_message_for_peer)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id));
+ let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.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 core::ops::Deref for OnionMessageProvider {
+ type Target = Self;
+ fn deref(&self) -> &Self {
+ self
+ }
+}
+/// Calls the free function if one is set
+#[no_mangle]
+pub extern "C" fn OnionMessageProvider_free(this_ptr: OnionMessageProvider) { }
+impl Drop for OnionMessageProvider {
+ fn drop(&mut self) {
+ if let Some(f) = self.free {
+ f(self.this_arg);
+ }
+ }
+}