+use lightning::routing::router::BlindedTail as nativeBlindedTailImport;
+pub(crate) type nativeBlindedTail = nativeBlindedTailImport;
+
+/// The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
+/// their [`Bolt12Invoice`].
+///
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
+#[must_use]
+#[repr(C)]
+pub struct BlindedTail {
+ /// 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 nativeBlindedTail,
+ /// 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 BlindedTail {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeBlindedTail>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the BlindedTail, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn BlindedTail_free(this_obj: BlindedTail) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn BlindedTail_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedTail) };
+}
+#[allow(unused)]
+impl BlindedTail {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedTail {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedTail {
+ 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 nativeBlindedTail {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+}
+/// The hops of the [`BlindedPath`] provided by the recipient.
+///
+/// [`BlindedPath`]: crate::blinded_path::BlindedPath
+#[no_mangle]
+pub extern "C" fn BlindedTail_get_hops(this_ptr: &BlindedTail) -> crate::c_types::derived::CVec_BlindedHopZ {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
+ let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::blinded_path::BlindedHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::blinded_path::BlindedHop<>) as *mut _) }, is_owned: false } }); };
+ local_inner_val.into()
+}
+/// The hops of the [`BlindedPath`] provided by the recipient.
+///
+/// [`BlindedPath`]: crate::blinded_path::BlindedPath
+#[no_mangle]
+pub extern "C" fn BlindedTail_set_hops(this_ptr: &mut BlindedTail, mut val: crate::c_types::derived::CVec_BlindedHopZ) {
+ let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
+}
+/// The blinding point of the [`BlindedPath`] provided by the recipient.
+///
+/// [`BlindedPath`]: crate::blinded_path::BlindedPath
+#[no_mangle]
+pub extern "C" fn BlindedTail_get_blinding_point(this_ptr: &BlindedTail) -> crate::c_types::PublicKey {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().blinding_point;
+ crate::c_types::PublicKey::from_rust(&inner_val)
+}
+/// The blinding point of the [`BlindedPath`] provided by the recipient.
+///
+/// [`BlindedPath`]: crate::blinded_path::BlindedPath
+#[no_mangle]
+pub extern "C" fn BlindedTail_set_blinding_point(this_ptr: &mut BlindedTail, mut val: crate::c_types::PublicKey) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinding_point = val.into_rust();
+}
+/// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
+/// inferring the destination. May be 0.
+#[no_mangle]
+pub extern "C" fn BlindedTail_get_excess_final_cltv_expiry_delta(this_ptr: &BlindedTail) -> u32 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().excess_final_cltv_expiry_delta;
+ *inner_val
+}
+/// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
+/// inferring the destination. May be 0.
+#[no_mangle]
+pub extern "C" fn BlindedTail_set_excess_final_cltv_expiry_delta(this_ptr: &mut BlindedTail, mut val: u32) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_final_cltv_expiry_delta = val;
+}
+/// The total amount paid on this [`Path`], excluding the fees.
+#[no_mangle]
+pub extern "C" fn BlindedTail_get_final_value_msat(this_ptr: &BlindedTail) -> u64 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
+ *inner_val
+}
+/// The total amount paid on this [`Path`], excluding the fees.
+#[no_mangle]
+pub extern "C" fn BlindedTail_set_final_value_msat(this_ptr: &mut BlindedTail, mut val: u64) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
+}
+/// Constructs a new BlindedTail given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn BlindedTail_new(mut hops_arg: crate::c_types::derived::CVec_BlindedHopZ, mut blinding_point_arg: crate::c_types::PublicKey, mut excess_final_cltv_expiry_delta_arg: u32, mut final_value_msat_arg: u64) -> BlindedTail {
+ let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ BlindedTail { inner: ObjOps::heap_alloc(nativeBlindedTail {
+ hops: local_hops_arg,
+ blinding_point: blinding_point_arg.into_rust(),
+ excess_final_cltv_expiry_delta: excess_final_cltv_expiry_delta_arg,
+ final_value_msat: final_value_msat_arg,
+ }), is_owned: true }
+}
+impl Clone for BlindedTail {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeBlindedTail>::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 BlindedTail_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedTail)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the BlindedTail
+pub extern "C" fn BlindedTail_clone(orig: &BlindedTail) -> BlindedTail {
+ orig.clone()
+}
+/// Generates a non-cryptographic 64-bit hash of the BlindedTail.
+#[no_mangle]
+pub extern "C" fn BlindedTail_hash(o: &BlindedTail) -> 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 BlindedTails 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 BlindedTail_eq(a: &BlindedTail, b: &BlindedTail) -> 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 }
+}
+#[no_mangle]
+/// Serialize the BlindedTail object into a byte array which can be read by BlindedTail_read
+pub extern "C" fn BlindedTail_write(obj: &crate::lightning::routing::router::BlindedTail) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
+}
+#[allow(unused)]
+pub(crate) extern "C" fn BlindedTail_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedTail) })
+}
+#[no_mangle]
+/// Read a BlindedTail from a byte array, created by BlindedTail_write
+pub extern "C" fn BlindedTail_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedTailDecodeErrorZ {
+ let res: Result<lightning::routing::router::BlindedTail, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::BlindedTail { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
+ local_res
+}
+
+use lightning::routing::router::Path as nativePathImport;
+pub(crate) type nativePath = nativePathImport;
+
+/// A path in a [`Route`] to the payment recipient. Must always be at least length one.
+/// If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
+#[must_use]
+#[repr(C)]
+pub struct Path {
+ /// 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 nativePath,
+ /// 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 Path {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativePath>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the Path, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn Path_free(this_obj: Path) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Path_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePath) };
+}
+#[allow(unused)]
+impl Path {
+ pub(crate) fn get_native_ref(&self) -> &'static nativePath {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePath {
+ 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 nativePath {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+}
+/// The list of unblinded hops in this [`Path`]. Must be at least length one.
+#[no_mangle]
+pub extern "C" fn Path_get_hops(this_ptr: &Path) -> crate::c_types::derived::CVec_RouteHopZ {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
+ let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); };
+ local_inner_val.into()
+}
+/// The list of unblinded hops in this [`Path`]. Must be at least length one.
+#[no_mangle]
+pub extern "C" fn Path_set_hops(this_ptr: &mut Path, mut val: crate::c_types::derived::CVec_RouteHopZ) {
+ let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
+}
+/// The blinded path at which this path terminates, if we're sending to one, and its metadata.
+///
+/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
+#[no_mangle]
+pub extern "C" fn Path_get_blinded_tail(this_ptr: &Path) -> crate::lightning::routing::router::BlindedTail {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().blinded_tail;
+ let mut local_inner_val = crate::lightning::routing::router::BlindedTail { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::BlindedTail<>) as *mut _ }, is_owned: false };
+ local_inner_val
+}
+/// The blinded path at which this path terminates, if we're sending to one, and its metadata.
+///
+/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
+#[no_mangle]
+pub extern "C" fn Path_set_blinded_tail(this_ptr: &mut Path, mut val: crate::lightning::routing::router::BlindedTail) {
+ let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinded_tail = local_val;
+}
+/// Constructs a new Path given each field
+///
+/// Note that blinded_tail_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Path_new(mut hops_arg: crate::c_types::derived::CVec_RouteHopZ, mut blinded_tail_arg: crate::lightning::routing::router::BlindedTail) -> Path {
+ let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ let mut local_blinded_tail_arg = if blinded_tail_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded_tail_arg.take_inner()) } }) };
+ Path { inner: ObjOps::heap_alloc(nativePath {
+ hops: local_hops_arg,
+ blinded_tail: local_blinded_tail_arg,
+ }), is_owned: true }
+}
+impl Clone for Path {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativePath>::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 Path_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePath)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the Path
+pub extern "C" fn Path_clone(orig: &Path) -> Path {
+ orig.clone()
+}
+/// Generates a non-cryptographic 64-bit hash of the Path.
+#[no_mangle]
+pub extern "C" fn Path_hash(o: &Path) -> 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 Paths 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 Path_eq(a: &Path, b: &Path) -> 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 }
+}
+/// Gets the fees for a given path, excluding any excess paid to the recipient.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Path_fee_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fee_msat();
+ ret
+}
+
+/// Gets the total amount paid on this [`Path`], excluding the fees.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Path_final_value_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_value_msat();
+ ret
+}
+
+/// Gets the final hop's CLTV expiry delta.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Path_final_cltv_expiry_delta(this_arg: &crate::lightning::routing::router::Path) -> crate::c_types::derived::COption_u32Z {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_cltv_expiry_delta();
+ let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { ret.unwrap() }) };
+ local_ret
+}
+
+