+use lightning::routing::network_graph::DirectedChannelInfo as nativeDirectedChannelInfoImport;
+pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static>;
+
+/// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
+/// source node to a target node.
+#[must_use]
+#[repr(C)]
+pub struct DirectedChannelInfo {
+ /// 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 nativeDirectedChannelInfo,
+ /// 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 DirectedChannelInfo {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
+ unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo); }
+}
+#[allow(unused)]
+impl DirectedChannelInfo {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
+ 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 nativeDirectedChannelInfo {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+}
+impl Clone for DirectedChannelInfo {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeDirectedChannelInfo>::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 DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the DirectedChannelInfo
+pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
+ orig.clone()
+}
+/// Returns information for the channel.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routing::network_graph::DirectedChannelInfo) -> crate::lightning::routing::network_graph::ChannelInfo {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
+ crate::lightning::routing::network_graph::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::network_graph::ChannelInfo<>) as *mut _) }, is_owned: false }
+}
+
+/// Returns information for the direction.
+///
+/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
+#[must_use]
+#[no_mangle]
+pub extern "C" fn DirectedChannelInfo_direction(this_arg: &crate::lightning::routing::network_graph::DirectedChannelInfo) -> crate::lightning::routing::network_graph::ChannelUpdateInfo {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.direction();
+ let mut local_ret = crate::lightning::routing::network_graph::ChannelUpdateInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::network_graph::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
+ local_ret
+}
+
+/// Returns the [`EffectiveCapacity`] of the channel in the direction.
+///
+/// This is either the total capacity from the funding transaction, if known, or the
+/// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
+/// whichever is smaller.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::lightning::routing::network_graph::DirectedChannelInfo) -> crate::lightning::routing::network_graph::EffectiveCapacity {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
+ crate::lightning::routing::network_graph::EffectiveCapacity::native_into(ret)
+}
+
+/// The effective capacity of a channel for routing purposes.
+///
+/// While this may be smaller than the actual channel capacity, amounts greater than
+/// [`Self::as_msat`] should not be routed through the channel.
+#[must_use]
+#[derive(Clone)]
+#[repr(C)]
+pub enum EffectiveCapacity {
+ /// The available liquidity in the channel known from being a channel counterparty, and thus a
+ /// direct hop.
+ ExactLiquidity {
+ /// Either the inbound or outbound liquidity depending on the direction, denominated in
+ /// millisatoshi.
+ liquidity_msat: u64,
+ },
+ /// The maximum HTLC amount in one direction as advertised on the gossip network.
+ MaximumHTLC {
+ /// The maximum HTLC amount denominated in millisatoshi.
+ amount_msat: u64,
+ },
+ /// The total capacity of the channel as determined by the funding transaction.
+ Total {
+ /// The funding amount denominated in millisatoshi.
+ capacity_msat: u64,
+ },
+ /// A capacity sufficient to route any payment, typically used for private channels provided by
+ /// an invoice.
+ Infinite,
+ /// A capacity that is unknown possibly because either the chain state is unavailable to know
+ /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
+ Unknown,
+}
+use lightning::routing::network_graph::EffectiveCapacity as nativeEffectiveCapacity;
+impl EffectiveCapacity {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
+ match self {
+ EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
+ let mut liquidity_msat_nonref = (*liquidity_msat).clone();
+ nativeEffectiveCapacity::ExactLiquidity {
+ liquidity_msat: liquidity_msat_nonref,
+ }
+ },
+ EffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
+ let mut amount_msat_nonref = (*amount_msat).clone();
+ nativeEffectiveCapacity::MaximumHTLC {
+ amount_msat: amount_msat_nonref,
+ }
+ },
+ EffectiveCapacity::Total {ref capacity_msat, } => {
+ let mut capacity_msat_nonref = (*capacity_msat).clone();
+ nativeEffectiveCapacity::Total {
+ capacity_msat: capacity_msat_nonref,
+ }
+ },
+ EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
+ EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
+ match self {
+ EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
+ nativeEffectiveCapacity::ExactLiquidity {
+ liquidity_msat: liquidity_msat,
+ }
+ },
+ EffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
+ nativeEffectiveCapacity::MaximumHTLC {
+ amount_msat: amount_msat,
+ }
+ },
+ EffectiveCapacity::Total {mut capacity_msat, } => {
+ nativeEffectiveCapacity::Total {
+ capacity_msat: capacity_msat,
+ }
+ },
+ EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
+ EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self {
+ match native {
+ nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
+ let mut liquidity_msat_nonref = (*liquidity_msat).clone();
+ EffectiveCapacity::ExactLiquidity {
+ liquidity_msat: liquidity_msat_nonref,
+ }
+ },
+ nativeEffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
+ let mut amount_msat_nonref = (*amount_msat).clone();
+ EffectiveCapacity::MaximumHTLC {
+ amount_msat: amount_msat_nonref,
+ }
+ },
+ nativeEffectiveCapacity::Total {ref capacity_msat, } => {
+ let mut capacity_msat_nonref = (*capacity_msat).clone();
+ EffectiveCapacity::Total {
+ capacity_msat: capacity_msat_nonref,
+ }
+ },
+ nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
+ nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
+ match native {
+ nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
+ EffectiveCapacity::ExactLiquidity {
+ liquidity_msat: liquidity_msat,
+ }
+ },
+ nativeEffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
+ EffectiveCapacity::MaximumHTLC {
+ amount_msat: amount_msat,
+ }
+ },
+ nativeEffectiveCapacity::Total {mut capacity_msat, } => {
+ EffectiveCapacity::Total {
+ capacity_msat: capacity_msat,
+ }
+ },
+ nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
+ nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
+ }
+ }
+}
+/// Frees any resources used by the EffectiveCapacity
+#[no_mangle]
+pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
+/// Creates a copy of the EffectiveCapacity
+#[no_mangle]
+pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
+pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
+ EffectiveCapacity::ExactLiquidity {
+ liquidity_msat,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity
+pub extern "C" fn EffectiveCapacity_maximum_htlc(amount_msat: u64) -> EffectiveCapacity {
+ EffectiveCapacity::MaximumHTLC {
+ amount_msat,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new Total-variant EffectiveCapacity
+pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64) -> EffectiveCapacity {
+ EffectiveCapacity::Total {
+ capacity_msat,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new Infinite-variant EffectiveCapacity
+pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
+ EffectiveCapacity::Infinite}
+#[no_mangle]
+/// Utility method to constructs a new Unknown-variant EffectiveCapacity
+pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
+ EffectiveCapacity::Unknown}
+/// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
+/// use when making routing decisions.
+
+#[no_mangle]
+pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::network_graph::UNKNOWN_CHANNEL_CAPACITY_MSAT;
+/// Returns the effective capacity denominated in millisatoshi.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &crate::lightning::routing::network_graph::EffectiveCapacity) -> u64 {
+ let mut ret = this_arg.to_native().as_msat();
+ ret
+}
+
+