X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Frouting%2Fnetwork_graph.rs;h=7947ac628b0d34b0ad439fc484ddec49b501e204;hb=a0762e60278ee25dd39ce1c880f23e95329e90ea;hp=72910e8a39934b97280c18c7f3d063a62031ce53;hpb=1495575b517c90da925698da14f627bf0d5b313f;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/routing/network_graph.rs b/lightning-c-bindings/src/routing/network_graph.rs index 72910e8..7947ac6 100644 --- a/lightning-c-bindings/src/routing/network_graph.rs +++ b/lightning-c-bindings/src/routing/network_graph.rs @@ -1,3 +1,11 @@ +// This file is Copyright its original authors, visible in version control +// history and in the source files from which this was generated. +// +// This file is licensed under the license available in the LICENSE or LICENSE.md +// file in the root of this repository or, if no such file exists, the same +// license as that which applies to the original source files from which this +// source was automatically generated. + //! The top-level network map tracking logic lives here. use std::ffi::c_void; @@ -12,9 +20,15 @@ type nativeNetworkGraph = nativeNetworkGraphImport; #[must_use] #[repr(C)] pub struct NetworkGraph { + /// 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 nativeNetworkGraph, + /// 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, } @@ -25,8 +39,9 @@ impl Drop for NetworkGraph { } } } +/// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn NetworkGraph_free(this_ptr: NetworkGraph) { } +pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) { @@ -57,6 +72,7 @@ pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mu Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void } #[no_mangle] +/// Creates a copy of the NetworkGraph pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph { orig.clone() } @@ -70,9 +86,15 @@ type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>; #[must_use] #[repr(C)] pub struct LockedNetworkGraph { + /// 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 nativeLockedNetworkGraph, + /// 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, } @@ -83,8 +105,9 @@ impl Drop for LockedNetworkGraph { } } } +/// Frees any resources used by the LockedNetworkGraph, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn LockedNetworkGraph_free(this_ptr: LockedNetworkGraph) { } +pub extern "C" fn LockedNetworkGraph_free(this_obj: LockedNetworkGraph) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) { @@ -112,9 +135,15 @@ type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport for crate::ln::msgs::RoutingMessageHandler { ret } } +/// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is #[no_mangle] pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler { crate::ln::msgs::RoutingMessageHandler { @@ -277,8 +309,8 @@ extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channe local_ret } #[must_use] -extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ { - let mut ret = >::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) }); +extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = >::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) }); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() }; local_ret } @@ -305,6 +337,8 @@ impl From for crate::util::events::MessageSendEventsPr ret } } +/// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is #[no_mangle] pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::util::events::MessageSendEventsProvider { crate::util::events::MessageSendEventsProvider { @@ -330,9 +364,15 @@ type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport; #[must_use] #[repr(C)] pub struct DirectionalChannelInfo { + /// 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 nativeDirectionalChannelInfo, + /// 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, } @@ -343,8 +383,9 @@ impl Drop for DirectionalChannelInfo { } } } +/// Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn DirectionalChannelInfo_free(this_ptr: DirectionalChannelInfo) { } +pub extern "C" fn DirectionalChannelInfo_free(this_obj: DirectionalChannelInfo) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) { @@ -406,6 +447,19 @@ pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &Direct pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) { unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val; } +/// The maximum value which may be relayed to the next hop via the channel. +#[no_mangle] +pub extern "C" fn DirectionalChannelInfo_get_htlc_maximum_msat(this_ptr: &DirectionalChannelInfo) -> crate::c_types::derived::COption_u64Z { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_maximum_msat; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } }; + local_inner_val +} +/// The maximum value which may be relayed to the next hop via the channel. +#[no_mangle] +pub extern "C" fn DirectionalChannelInfo_set_htlc_maximum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: crate::c_types::derived::COption_u64Z) { + let mut local_val = if val.is_some() { Some( { val.take() }) } else { None }; + unsafe { &mut *this_ptr.inner }.htlc_maximum_msat = local_val; +} /// Fees charged when the channel is used for routing #[no_mangle] pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::routing::network_graph::RoutingFees { @@ -436,6 +490,22 @@ pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; unsafe { &mut *this_ptr.inner }.last_update_message = local_val; } +/// Constructs a new DirectionalChannelInfo given each field +#[must_use] +#[no_mangle] +pub extern "C" fn DirectionalChannelInfo_new(mut last_update_arg: u32, mut enabled_arg: bool, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z, mut fees_arg: crate::routing::network_graph::RoutingFees, mut last_update_message_arg: crate::ln::msgs::ChannelUpdate) -> DirectionalChannelInfo { + let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None }; + let mut local_last_update_message_arg = if last_update_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(last_update_message_arg.take_inner()) } }) }; + DirectionalChannelInfo { inner: Box::into_raw(Box::new(nativeDirectionalChannelInfo { + last_update: last_update_arg, + enabled: enabled_arg, + cltv_expiry_delta: cltv_expiry_delta_arg, + htlc_minimum_msat: htlc_minimum_msat_arg, + htlc_maximum_msat: local_htlc_maximum_msat_arg, + fees: *unsafe { Box::from_raw(fees_arg.take_inner()) }, + last_update_message: local_last_update_message_arg, + })), is_owned: true } +} impl Clone for DirectionalChannelInfo { fn clone(&self) -> Self { Self { @@ -451,10 +521,12 @@ pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_vo Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void } #[no_mangle] +/// Creates a copy of the DirectionalChannelInfo pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo { orig.clone() } #[no_mangle] +/// Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) } @@ -463,6 +535,7 @@ pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) }) } #[no_mangle] +/// Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ { let res = crate::c_types::deserialize_obj(ser); let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::DirectionalChannelInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() }; @@ -477,9 +550,15 @@ type nativeChannelInfo = nativeChannelInfoImport; #[must_use] #[repr(C)] pub struct ChannelInfo { + /// 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 nativeChannelInfo, + /// 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, } @@ -490,8 +569,9 @@ impl Drop for ChannelInfo { } } } +/// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn ChannelInfo_free(this_ptr: ChannelInfo) { } +pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) { @@ -566,6 +646,19 @@ pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; unsafe { &mut *this_ptr.inner }.two_to_one = local_val; } +/// The channel capacity as seen on-chain, if chain lookup is available. +#[no_mangle] +pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.capacity_sats; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } }; + local_inner_val +} +/// The channel capacity as seen on-chain, if chain lookup is available. +#[no_mangle] +pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) { + let mut local_val = if val.is_some() { Some( { val.take() }) } else { None }; + unsafe { &mut *this_ptr.inner }.capacity_sats = local_val; +} /// An initial announcement of the channel /// Mostly redundant with the data we store in fields explicitly. /// Everything else is useful only for sending out for initial routing sync. @@ -585,6 +678,24 @@ pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInf let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; unsafe { &mut *this_ptr.inner }.announcement_message = local_val; } +/// Constructs a new ChannelInfo given each field +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelInfo_new(mut features_arg: crate::ln::features::ChannelFeatures, mut node_one_arg: crate::c_types::PublicKey, mut one_to_two_arg: crate::routing::network_graph::DirectionalChannelInfo, mut node_two_arg: crate::c_types::PublicKey, mut two_to_one_arg: crate::routing::network_graph::DirectionalChannelInfo, mut capacity_sats_arg: crate::c_types::derived::COption_u64Z, mut announcement_message_arg: crate::ln::msgs::ChannelAnnouncement) -> ChannelInfo { + let mut local_one_to_two_arg = if one_to_two_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(one_to_two_arg.take_inner()) } }) }; + let mut local_two_to_one_arg = if two_to_one_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(two_to_one_arg.take_inner()) } }) }; + let mut local_capacity_sats_arg = if capacity_sats_arg.is_some() { Some( { capacity_sats_arg.take() }) } else { None }; + let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_inner()) } }) }; + ChannelInfo { inner: Box::into_raw(Box::new(nativeChannelInfo { + features: *unsafe { Box::from_raw(features_arg.take_inner()) }, + node_one: node_one_arg.into_rust(), + one_to_two: local_one_to_two_arg, + node_two: node_two_arg.into_rust(), + two_to_one: local_two_to_one_arg, + capacity_sats: local_capacity_sats_arg, + announcement_message: local_announcement_message_arg, + })), is_owned: true } +} impl Clone for ChannelInfo { fn clone(&self) -> Self { Self { @@ -600,10 +711,12 @@ pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void } #[no_mangle] +/// Creates a copy of the ChannelInfo pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo { orig.clone() } #[no_mangle] +/// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) } @@ -612,6 +725,7 @@ pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_ crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) }) } #[no_mangle] +/// Read a ChannelInfo from a byte array, created by ChannelInfo_write pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ { let res = crate::c_types::deserialize_obj(ser); let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::ChannelInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() }; @@ -625,9 +739,15 @@ type nativeRoutingFees = nativeRoutingFeesImport; #[must_use] #[repr(C)] pub struct RoutingFees { + /// 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 nativeRoutingFees, + /// 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, } @@ -638,8 +758,9 @@ impl Drop for RoutingFees { } } } +/// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn RoutingFees_free(this_ptr: RoutingFees) { } +pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) { @@ -679,6 +800,7 @@ pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) { unsafe { &mut *this_ptr.inner }.proportional_millionths = val; } +/// Constructs a new RoutingFees given each field #[must_use] #[no_mangle] pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees { @@ -702,16 +824,19 @@ pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void } #[no_mangle] +/// Creates a copy of the RoutingFees pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees { orig.clone() } #[no_mangle] +/// Read a RoutingFees from a byte array, created by RoutingFees_write pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ { let res = crate::c_types::deserialize_obj(ser); let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::RoutingFees { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() }; local_res } #[no_mangle] +/// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) } @@ -727,9 +852,15 @@ type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport; #[must_use] #[repr(C)] pub struct NodeAnnouncementInfo { + /// 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 nativeNodeAnnouncementInfo, + /// 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, } @@ -740,8 +871,9 @@ impl Drop for NodeAnnouncementInfo { } } } +/// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_free(this_ptr: NodeAnnouncementInfo) { } +pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) { @@ -832,6 +964,7 @@ pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut N let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; unsafe { &mut *this_ptr.inner }.announcement_message = local_val; } +/// Constructs a new NodeAnnouncementInfo given each field #[must_use] #[no_mangle] pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::ln::features::NodeFeatures, mut last_update_arg: u32, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::c_types::ThirtyTwoBytes, mut addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo { @@ -861,10 +994,12 @@ pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void } #[no_mangle] +/// Creates a copy of the NodeAnnouncementInfo pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo { orig.clone() } #[no_mangle] +/// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) } @@ -873,6 +1008,7 @@ pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) }) } #[no_mangle] +/// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ { let res = crate::c_types::deserialize_obj(ser); let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NodeAnnouncementInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() }; @@ -886,9 +1022,15 @@ type nativeNodeInfo = nativeNodeInfoImport; #[must_use] #[repr(C)] pub struct NodeInfo { + /// 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 nativeNodeInfo, + /// 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, } @@ -899,8 +1041,9 @@ impl Drop for NodeInfo { } } } +/// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn NodeInfo_free(this_ptr: NodeInfo) { } +pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) { @@ -956,6 +1099,7 @@ pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut va let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; unsafe { &mut *this_ptr.inner }.announcement_info = local_val; } +/// Constructs a new NodeInfo given each field #[must_use] #[no_mangle] pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::routing::network_graph::RoutingFees, mut announcement_info_arg: crate::routing::network_graph::NodeAnnouncementInfo) -> NodeInfo { @@ -983,10 +1127,12 @@ pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_ Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void } #[no_mangle] +/// Creates a copy of the NodeInfo pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo { orig.clone() } #[no_mangle] +/// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) } @@ -995,12 +1141,14 @@ pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_typ crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) }) } #[no_mangle] +/// Read a NodeInfo from a byte array, created by NodeInfo_write pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ { let res = crate::c_types::deserialize_obj(ser); let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NodeInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() }; local_res } #[no_mangle] +/// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) } @@ -1009,6 +1157,7 @@ pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) }) } #[no_mangle] +/// Read a NetworkGraph from a byte array, created by NetworkGraph_write pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ { let res = crate::c_types::deserialize_obj(ser); let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };