+ fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> {
+ let mut ret = (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound);
+ let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
+ local_ret
+ }
+ fn peer_disconnected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) {
+ (self.peer_disconnected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id))
+ }
+ fn timer_tick_occurred(&self) {
+ (self.timer_tick_occurred)(self.this_arg)
+ }
+ fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures {
+ let mut ret = (self.provided_node_features)(self.this_arg);
+ *unsafe { Box::from_raw(ret.take_inner()) }
+ }
+ fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures {
+ let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id));
+ *unsafe { Box::from_raw(ret.take_inner()) }
+ }
+}
+
+// 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 OnionMessageHandler {
+ type Target = Self;
+ fn deref(&self) -> &Self {
+ self
+ }
+}
+impl core::ops::DerefMut for OnionMessageHandler {
+ fn deref_mut(&mut self) -> &mut Self {
+ self
+ }
+}
+/// Calls the free function if one is set
+#[no_mangle]
+pub extern "C" fn OnionMessageHandler_free(this_ptr: OnionMessageHandler) { }
+impl Drop for OnionMessageHandler {
+ fn drop(&mut self) {
+ if let Some(f) = self.free {
+ f(self.this_arg);
+ }
+ }
+}
+
+use lightning::ln::msgs::FinalOnionHopData as nativeFinalOnionHopDataImport;
+pub(crate) type nativeFinalOnionHopData = nativeFinalOnionHopDataImport;
+
+/// Information communicated in the onion to the recipient for multi-part tracking and proof that
+/// the payment is associated with an invoice.
+#[must_use]
+#[repr(C)]
+pub struct FinalOnionHopData {
+ /// 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 nativeFinalOnionHopData,
+ /// 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 FinalOnionHopData {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeFinalOnionHopData>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the FinalOnionHopData, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn FinalOnionHopData_free(this_obj: FinalOnionHopData) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn FinalOnionHopData_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFinalOnionHopData) };
+}
+#[allow(unused)]
+impl FinalOnionHopData {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeFinalOnionHopData {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFinalOnionHopData {
+ 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 nativeFinalOnionHopData {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+}
+/// When sending a multi-part payment, this secret is used to identify a payment across HTLCs.
+/// Because it is generated by the recipient and included in the invoice, it also provides
+/// proof to the recipient that the payment was sent by someone with the generated invoice.
+#[no_mangle]
+pub extern "C" fn FinalOnionHopData_get_payment_secret(this_ptr: &FinalOnionHopData) -> *const [u8; 32] {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_secret;
+ &inner_val.0
+}
+/// When sending a multi-part payment, this secret is used to identify a payment across HTLCs.
+/// Because it is generated by the recipient and included in the invoice, it also provides
+/// proof to the recipient that the payment was sent by someone with the generated invoice.
+#[no_mangle]
+pub extern "C" fn FinalOnionHopData_set_payment_secret(this_ptr: &mut FinalOnionHopData, mut val: crate::c_types::ThirtyTwoBytes) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_secret = ::lightning::ln::types::PaymentSecret(val.data);
+}
+/// The intended total amount that this payment is for.
+///
+/// Message serialization may panic if this value is more than 21 million Bitcoin.
+#[no_mangle]
+pub extern "C" fn FinalOnionHopData_get_total_msat(this_ptr: &FinalOnionHopData) -> u64 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().total_msat;
+ *inner_val
+}
+/// The intended total amount that this payment is for.
+///
+/// Message serialization may panic if this value is more than 21 million Bitcoin.
+#[no_mangle]
+pub extern "C" fn FinalOnionHopData_set_total_msat(this_ptr: &mut FinalOnionHopData, mut val: u64) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.total_msat = val;
+}
+/// Constructs a new FinalOnionHopData given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn FinalOnionHopData_new(mut payment_secret_arg: crate::c_types::ThirtyTwoBytes, mut total_msat_arg: u64) -> FinalOnionHopData {
+ FinalOnionHopData { inner: ObjOps::heap_alloc(nativeFinalOnionHopData {
+ payment_secret: ::lightning::ln::types::PaymentSecret(payment_secret_arg.data),
+ total_msat: total_msat_arg,
+ }), is_owned: true }
+}
+impl Clone for FinalOnionHopData {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeFinalOnionHopData>::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 FinalOnionHopData_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFinalOnionHopData)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the FinalOnionHopData
+pub extern "C" fn FinalOnionHopData_clone(orig: &FinalOnionHopData) -> FinalOnionHopData {
+ orig.clone()
+}
+mod fuzzy_internal_msgs {
+
+use alloc::str::FromStr;
+use alloc::string::String;
+use core::ffi::c_void;
+use core::convert::Infallible;
+use bitcoin::hashes::Hash;
+use crate::c_types::*;
+#[cfg(feature="no-std")]
+use alloc::{vec::Vec, boxed::Box};
+
+}
+
+use lightning::ln::msgs::OnionPacket as nativeOnionPacketImport;
+pub(crate) type nativeOnionPacket = nativeOnionPacketImport;
+
+/// BOLT 4 onion packet including hop data for the next peer.
+#[must_use]
+#[repr(C)]
+pub struct OnionPacket {
+ /// 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 nativeOnionPacket,
+ /// 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 OnionPacket {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeOnionPacket>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the OnionPacket, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn OnionPacket_free(this_obj: OnionPacket) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn OnionPacket_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOnionPacket) };
+}
+#[allow(unused)]
+impl OnionPacket {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeOnionPacket {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionPacket {
+ 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 nativeOnionPacket {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+}
+/// BOLT 4 version number.
+#[no_mangle]
+pub extern "C" fn OnionPacket_get_version(this_ptr: &OnionPacket) -> u8 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().version;
+ *inner_val
+}
+/// BOLT 4 version number.
+#[no_mangle]
+pub extern "C" fn OnionPacket_set_version(this_ptr: &mut OnionPacket, mut val: u8) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.version = val;
+}
+/// In order to ensure we always return an error on onion decode in compliance with [BOLT
+/// #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
+/// deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
+/// public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
+/// like.
+///
+/// Returns a copy of the field.
+#[no_mangle]
+pub extern "C" fn OnionPacket_get_public_key(this_ptr: &OnionPacket) -> crate::c_types::derived::CResult_PublicKeySecp256k1ErrorZ {
+ let mut inner_val = this_ptr.get_native_mut_ref().public_key.clone();
+ let mut local_inner_val = match inner_val { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
+ local_inner_val
+}
+/// In order to ensure we always return an error on onion decode in compliance with [BOLT
+/// #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
+/// deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
+/// public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
+/// like.
+#[no_mangle]
+pub extern "C" fn OnionPacket_set_public_key(this_ptr: &mut OnionPacket, mut val: crate::c_types::derived::CResult_PublicKeySecp256k1ErrorZ) {
+ let mut local_val = match val.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut val.contents.result)) }).into_rust() }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut val.contents.err)) }).into_rust() })};
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.public_key = local_val;
+}
+/// HMAC to verify the integrity of hop_data.
+#[no_mangle]
+pub extern "C" fn OnionPacket_get_hmac(this_ptr: &OnionPacket) -> *const [u8; 32] {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().hmac;
+ inner_val
+}
+/// HMAC to verify the integrity of hop_data.
+#[no_mangle]
+pub extern "C" fn OnionPacket_set_hmac(this_ptr: &mut OnionPacket, mut val: crate::c_types::ThirtyTwoBytes) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hmac = val.data;
+}
+impl Clone for OnionPacket {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeOnionPacket>::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 OnionPacket_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOnionPacket)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the OnionPacket
+pub extern "C" fn OnionPacket_clone(orig: &OnionPacket) -> OnionPacket {
+ orig.clone()
+}
+/// Generates a non-cryptographic 64-bit hash of the OnionPacket.
+#[no_mangle]
+pub extern "C" fn OnionPacket_hash(o: &OnionPacket) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
+/// Checks if two OnionPackets 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 OnionPacket_eq(a: &OnionPacket, b: &OnionPacket) -> 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 }
+}
+/// Get a string which allows debug introspection of a OnionPacket object
+pub extern "C" fn OnionPacket_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::OnionPacket }).into()}
+
+use lightning::ln::msgs::TrampolineOnionPacket as nativeTrampolineOnionPacketImport;
+pub(crate) type nativeTrampolineOnionPacket = nativeTrampolineOnionPacketImport;
+
+/// BOLT 4 onion packet including hop data for the next peer.
+#[must_use]
+#[repr(C)]
+pub struct TrampolineOnionPacket {
+ /// 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 nativeTrampolineOnionPacket,
+ /// 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,