1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The top-level network map tracking logic lives here.
11 use std::str::FromStr;
13 use bitcoin::hashes::Hash;
14 use crate::c_types::*;
17 use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport;
18 type nativeNetworkGraph = nativeNetworkGraphImport;
20 /// Represents the network as nodes and channels between them
23 pub struct NetworkGraph {
24 /// A pointer to the opaque Rust object.
26 /// Nearly everywhere, inner must be non-null, however in places where
27 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
28 pub inner: *mut nativeNetworkGraph,
29 /// Indicates that this is the only struct which contains the same pointer.
31 /// Rust functions which take ownership of an object provided via an argument require
32 /// this to be true and invalidate the object pointed to by inner.
36 impl Drop for NetworkGraph {
38 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
39 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
43 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
45 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
47 /// Used only if an object of this type is returned as a trait impl by a method
48 extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
49 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
53 pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
54 unsafe { &*ObjOps::untweak_ptr(self.inner) }
56 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
57 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
59 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
60 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
61 assert!(self.is_owned);
62 let ret = ObjOps::untweak_ptr(self.inner);
63 self.inner = std::ptr::null_mut();
67 impl Clone for NetworkGraph {
68 fn clone(&self) -> Self {
70 inner: if <*mut nativeNetworkGraph>::is_null(self.inner) { std::ptr::null_mut() } else {
71 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
77 /// Used only if an object of this type is returned as a trait impl by a method
78 pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void {
79 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void
82 /// Creates a copy of the NetworkGraph
83 pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph {
87 use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport;
88 type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>;
90 /// A simple newtype for RwLockReadGuard<'a, NetworkGraph>.
91 /// This exists only to make accessing a RwLock<NetworkGraph> possible from
92 /// the C bindings, as it can be done directly in Rust code.
95 pub struct LockedNetworkGraph {
96 /// A pointer to the opaque Rust object.
98 /// Nearly everywhere, inner must be non-null, however in places where
99 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
100 pub inner: *mut nativeLockedNetworkGraph,
101 /// Indicates that this is the only struct which contains the same pointer.
103 /// Rust functions which take ownership of an object provided via an argument require
104 /// this to be true and invalidate the object pointed to by inner.
108 impl Drop for LockedNetworkGraph {
110 if self.is_owned && !<*mut nativeLockedNetworkGraph>::is_null(self.inner) {
111 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
115 /// Frees any resources used by the LockedNetworkGraph, if is_owned is set and inner is non-NULL.
117 pub extern "C" fn LockedNetworkGraph_free(this_obj: LockedNetworkGraph) { }
119 /// Used only if an object of this type is returned as a trait impl by a method
120 extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) {
121 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedNetworkGraph); }
124 impl LockedNetworkGraph {
125 pub(crate) fn get_native_ref(&self) -> &'static nativeLockedNetworkGraph {
126 unsafe { &*ObjOps::untweak_ptr(self.inner) }
128 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeLockedNetworkGraph {
129 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
131 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
132 pub(crate) fn take_inner(mut self) -> *mut nativeLockedNetworkGraph {
133 assert!(self.is_owned);
134 let ret = ObjOps::untweak_ptr(self.inner);
135 self.inner = std::ptr::null_mut();
140 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
141 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::lightning::chain::Access, crate::lightning::util::logger::Logger>;
143 /// Receives and validates network updates from peers,
144 /// stores authentic and relevant data as a network graph.
145 /// This network graph is then used for routing payments.
146 /// Provides interface to help with initial routing sync by
147 /// serving historical announcements.
150 pub struct NetGraphMsgHandler {
151 /// A pointer to the opaque Rust object.
153 /// Nearly everywhere, inner must be non-null, however in places where
154 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
155 pub inner: *mut nativeNetGraphMsgHandler,
156 /// Indicates that this is the only struct which contains the same pointer.
158 /// Rust functions which take ownership of an object provided via an argument require
159 /// this to be true and invalidate the object pointed to by inner.
163 impl Drop for NetGraphMsgHandler {
165 if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) {
166 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
170 /// Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL.
172 pub extern "C" fn NetGraphMsgHandler_free(this_obj: NetGraphMsgHandler) { }
174 /// Used only if an object of this type is returned as a trait impl by a method
175 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
176 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
179 impl NetGraphMsgHandler {
180 pub(crate) fn get_native_ref(&self) -> &'static nativeNetGraphMsgHandler {
181 unsafe { &*ObjOps::untweak_ptr(self.inner) }
183 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetGraphMsgHandler {
184 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
186 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
187 pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
188 assert!(self.is_owned);
189 let ret = ObjOps::untweak_ptr(self.inner);
190 self.inner = std::ptr::null_mut();
194 /// Creates a new tracker of the actual state of the network of channels and nodes,
195 /// assuming a fresh network graph.
196 /// Chain monitor is used to make sure announced channels exist on-chain,
197 /// channel data is correct, and that the announcement is signed with
198 /// channel owners' keys.
200 /// Note that chain_access (or a relevant inner pointer) may be NULL or all-0s to represent None
203 pub extern "C" fn NetGraphMsgHandler_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, chain_access: *mut crate::lightning::chain::Access, mut logger: crate::lightning::util::logger::Logger) -> NetGraphMsgHandler {
204 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
205 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), local_chain_access, logger);
206 NetGraphMsgHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
209 /// Creates a new tracker of the actual state of the network of channels and nodes,
210 /// assuming an existing Network Graph.
212 /// Note that chain_access (or a relevant inner pointer) may be NULL or all-0s to represent None
215 pub extern "C" fn NetGraphMsgHandler_from_net_graph(chain_access: *mut crate::lightning::chain::Access, mut logger: crate::lightning::util::logger::Logger, mut network_graph: crate::lightning::routing::network_graph::NetworkGraph) -> NetGraphMsgHandler {
216 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
217 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_inner()) });
218 NetGraphMsgHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
221 /// Adds a provider used to check new announcements. Does not affect
222 /// existing announcements unless they are updated.
223 /// Add, update or remove the provider would replace the current one.
225 /// Note that chain_access (or a relevant inner pointer) may be NULL or all-0s to represent None
227 pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut NetGraphMsgHandler, chain_access: *mut crate::lightning::chain::Access) {
228 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
229 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access)
232 /// Take a read lock on the network_graph and return it in the C-bindings
233 /// newtype helper. This is likely only useful when called via the C
234 /// bindings as you can call `self.network_graph.read().unwrap()` in Rust
238 pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::lightning::routing::network_graph::LockedNetworkGraph {
239 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_locked_graph();
240 crate::lightning::routing::network_graph::LockedNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
243 /// Get a reference to the NetworkGraph which this read-lock contains.
246 pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::lightning::routing::network_graph::NetworkGraph {
247 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.graph();
248 crate::lightning::routing::network_graph::NetworkGraph { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
251 impl From<nativeNetGraphMsgHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
252 fn from(obj: nativeNetGraphMsgHandler) -> Self {
253 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
254 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
255 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
256 rust_obj.inner = std::ptr::null_mut();
257 ret.free = Some(NetGraphMsgHandler_free_void);
261 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
262 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
264 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
265 crate::lightning::ln::msgs::RoutingMessageHandler {
266 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
268 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
269 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
270 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
271 handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
272 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
273 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
274 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
275 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
276 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
277 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
278 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
279 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
280 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
282 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
288 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
289 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
290 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
294 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
295 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
296 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
299 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::lightning::ln::msgs::HTLCFailChannelUpdate) {
300 <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_htlc_fail_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &update.to_native())
303 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
304 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
305 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
309 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements(this_arg: *const c_void, mut starting_point: u64, mut batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
310 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount);
311 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_1 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_1.unwrap())) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(orig_ret_0_0), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); };
315 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements(this_arg: *const c_void, mut starting_point: crate::c_types::PublicKey, mut batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ {
316 let mut local_starting_point_base = if starting_point.is_null() { None } else { Some( { starting_point.into_rust() }) }; let mut local_starting_point = local_starting_point_base.as_ref();
317 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, local_starting_point, batch_amount);
318 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
321 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init_msg: &crate::lightning::ln::msgs::Init) {
322 <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::sync_routing_table(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), init_msg.get_native_ref())
325 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
326 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
327 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
331 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
332 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_short_channel_ids_end(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
333 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
337 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::lightning::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
338 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
339 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
343 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
344 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_short_channel_ids(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
345 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
349 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::MessageSendEventsProvider {
350 fn from(obj: nativeNetGraphMsgHandler) -> Self {
351 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
352 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
353 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
354 rust_obj.inner = std::ptr::null_mut();
355 ret.free = Some(NetGraphMsgHandler_free_void);
359 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
360 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
362 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
363 crate::lightning::util::events::MessageSendEventsProvider {
364 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
366 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
371 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
372 let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
373 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
378 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
379 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
381 /// Details about one direction of a channel. Received
382 /// within a channel update.
385 pub struct DirectionalChannelInfo {
386 /// A pointer to the opaque Rust object.
388 /// Nearly everywhere, inner must be non-null, however in places where
389 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
390 pub inner: *mut nativeDirectionalChannelInfo,
391 /// Indicates that this is the only struct which contains the same pointer.
393 /// Rust functions which take ownership of an object provided via an argument require
394 /// this to be true and invalidate the object pointed to by inner.
398 impl Drop for DirectionalChannelInfo {
400 if self.is_owned && !<*mut nativeDirectionalChannelInfo>::is_null(self.inner) {
401 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
405 /// Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL.
407 pub extern "C" fn DirectionalChannelInfo_free(this_obj: DirectionalChannelInfo) { }
409 /// Used only if an object of this type is returned as a trait impl by a method
410 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
411 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
414 impl DirectionalChannelInfo {
415 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectionalChannelInfo {
416 unsafe { &*ObjOps::untweak_ptr(self.inner) }
418 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectionalChannelInfo {
419 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
421 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
422 pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo {
423 assert!(self.is_owned);
424 let ret = ObjOps::untweak_ptr(self.inner);
425 self.inner = std::ptr::null_mut();
429 /// When the last update to the channel direction was issued.
430 /// Value is opaque, as set in the announcement.
432 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
433 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
436 /// When the last update to the channel direction was issued.
437 /// Value is opaque, as set in the announcement.
439 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
440 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
442 /// Whether the channel can be currently used for payments (in this one direction).
444 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
445 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
448 /// Whether the channel can be currently used for payments (in this one direction).
450 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
451 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
453 /// The difference in CLTV values that you must have when routing through this channel.
455 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
456 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
459 /// The difference in CLTV values that you must have when routing through this channel.
461 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
462 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
464 /// The minimum value, which must be relayed to the next hop via the channel
466 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
467 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
470 /// The minimum value, which must be relayed to the next hop via the channel
472 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
473 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
475 /// The maximum value which may be relayed to the next hop via the channel.
477 pub extern "C" fn DirectionalChannelInfo_get_htlc_maximum_msat(this_ptr: &DirectionalChannelInfo) -> crate::c_types::derived::COption_u64Z {
478 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
479 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()) } };
482 /// The maximum value which may be relayed to the next hop via the channel.
484 pub extern "C" fn DirectionalChannelInfo_set_htlc_maximum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
485 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
486 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
488 /// Fees charged when the channel is used for routing
490 pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::lightning::routing::network_graph::RoutingFees {
491 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
492 crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
494 /// Fees charged when the channel is used for routing
496 pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
497 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
499 /// Most recent update for the channel received from the network
500 /// Mostly redundant with the data we store in fields explicitly.
501 /// Everything else is useful only for sending out for initial routing sync.
502 /// Not stored if contains excess data to prevent DoS.
504 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
506 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
507 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
508 let mut local_inner_val = crate::lightning::ln::msgs::ChannelUpdate { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
511 /// Most recent update for the channel received from the network
512 /// Mostly redundant with the data we store in fields explicitly.
513 /// Everything else is useful only for sending out for initial routing sync.
514 /// Not stored if contains excess data to prevent DoS.
516 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
518 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
519 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
520 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
522 /// Constructs a new DirectionalChannelInfo given each field
525 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::lightning::routing::network_graph::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> DirectionalChannelInfo {
526 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
527 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()) } }) };
528 DirectionalChannelInfo { inner: ObjOps::heap_alloc(nativeDirectionalChannelInfo {
529 last_update: last_update_arg,
530 enabled: enabled_arg,
531 cltv_expiry_delta: cltv_expiry_delta_arg,
532 htlc_minimum_msat: htlc_minimum_msat_arg,
533 htlc_maximum_msat: local_htlc_maximum_msat_arg,
534 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
535 last_update_message: local_last_update_message_arg,
538 impl Clone for DirectionalChannelInfo {
539 fn clone(&self) -> Self {
541 inner: if <*mut nativeDirectionalChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
542 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
548 /// Used only if an object of this type is returned as a trait impl by a method
549 pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
550 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
553 /// Creates a copy of the DirectionalChannelInfo
554 pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
558 /// Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read
559 pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
560 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
563 pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
564 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) })
567 /// Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write
568 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ {
569 let res = crate::c_types::deserialize_obj(ser);
570 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::DirectionalChannelInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
574 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
575 type nativeChannelInfo = nativeChannelInfoImport;
577 /// Details about a channel (both directions).
578 /// Received within a channel announcement.
581 pub struct ChannelInfo {
582 /// A pointer to the opaque Rust object.
584 /// Nearly everywhere, inner must be non-null, however in places where
585 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
586 pub inner: *mut nativeChannelInfo,
587 /// Indicates that this is the only struct which contains the same pointer.
589 /// Rust functions which take ownership of an object provided via an argument require
590 /// this to be true and invalidate the object pointed to by inner.
594 impl Drop for ChannelInfo {
596 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
597 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
601 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
603 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
605 /// Used only if an object of this type is returned as a trait impl by a method
606 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
607 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
611 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
612 unsafe { &*ObjOps::untweak_ptr(self.inner) }
614 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
615 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
617 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
618 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
619 assert!(self.is_owned);
620 let ret = ObjOps::untweak_ptr(self.inner);
621 self.inner = std::ptr::null_mut();
625 /// Protocol features of a channel communicated during its announcement
627 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
628 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
629 crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
631 /// Protocol features of a channel communicated during its announcement
633 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
634 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
636 /// Source node of the first direction of a channel
638 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
639 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
640 crate::c_types::PublicKey::from_rust(&inner_val)
642 /// Source node of the first direction of a channel
644 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
645 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = val.into_rust();
647 /// Details about the first direction of a channel
649 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
651 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
652 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
653 let mut local_inner_val = crate::lightning::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
656 /// Details about the first direction of a channel
658 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
660 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
661 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
662 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
664 /// Source node of the second direction of a channel
666 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
667 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
668 crate::c_types::PublicKey::from_rust(&inner_val)
670 /// Source node of the second direction of a channel
672 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
673 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = val.into_rust();
675 /// Details about the second direction of a channel
677 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
679 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
680 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
681 let mut local_inner_val = crate::lightning::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
684 /// Details about the second direction of a channel
686 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
688 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
689 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
690 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
692 /// The channel capacity as seen on-chain, if chain lookup is available.
694 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
695 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
696 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()) } };
699 /// The channel capacity as seen on-chain, if chain lookup is available.
701 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
702 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
703 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
705 /// An initial announcement of the channel
706 /// Mostly redundant with the data we store in fields explicitly.
707 /// Everything else is useful only for sending out for initial routing sync.
708 /// Not stored if contains excess data to prevent DoS.
710 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
712 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
713 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
714 let mut local_inner_val = crate::lightning::ln::msgs::ChannelAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
717 /// An initial announcement of the channel
718 /// Mostly redundant with the data we store in fields explicitly.
719 /// Everything else is useful only for sending out for initial routing sync.
720 /// Not stored if contains excess data to prevent DoS.
722 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
724 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
725 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
726 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
728 /// Constructs a new ChannelInfo given each field
731 pub extern "C" fn ChannelInfo_new(mut features_arg: crate::lightning::ln::features::ChannelFeatures, mut node_one_arg: crate::c_types::PublicKey, mut one_to_two_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut node_two_arg: crate::c_types::PublicKey, mut two_to_one_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut capacity_sats_arg: crate::c_types::derived::COption_u64Z, mut announcement_message_arg: crate::lightning::ln::msgs::ChannelAnnouncement) -> ChannelInfo {
732 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()) } }) };
733 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()) } }) };
734 let mut local_capacity_sats_arg = if capacity_sats_arg.is_some() { Some( { capacity_sats_arg.take() }) } else { None };
735 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()) } }) };
736 ChannelInfo { inner: ObjOps::heap_alloc(nativeChannelInfo {
737 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
738 node_one: node_one_arg.into_rust(),
739 one_to_two: local_one_to_two_arg,
740 node_two: node_two_arg.into_rust(),
741 two_to_one: local_two_to_one_arg,
742 capacity_sats: local_capacity_sats_arg,
743 announcement_message: local_announcement_message_arg,
746 impl Clone for ChannelInfo {
747 fn clone(&self) -> Self {
749 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
750 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
756 /// Used only if an object of this type is returned as a trait impl by a method
757 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
758 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
761 /// Creates a copy of the ChannelInfo
762 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
766 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
767 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
768 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
771 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
772 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
775 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
776 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
777 let res = crate::c_types::deserialize_obj(ser);
778 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::ChannelInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
782 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
783 type nativeRoutingFees = nativeRoutingFeesImport;
785 /// Fees for routing via a given channel or a node
788 pub struct RoutingFees {
789 /// A pointer to the opaque Rust object.
791 /// Nearly everywhere, inner must be non-null, however in places where
792 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
793 pub inner: *mut nativeRoutingFees,
794 /// Indicates that this is the only struct which contains the same pointer.
796 /// Rust functions which take ownership of an object provided via an argument require
797 /// this to be true and invalidate the object pointed to by inner.
801 impl Drop for RoutingFees {
803 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
804 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
808 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
810 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
812 /// Used only if an object of this type is returned as a trait impl by a method
813 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
814 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
818 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
819 unsafe { &*ObjOps::untweak_ptr(self.inner) }
821 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
822 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
824 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
825 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
826 assert!(self.is_owned);
827 let ret = ObjOps::untweak_ptr(self.inner);
828 self.inner = std::ptr::null_mut();
832 /// Flat routing fee in satoshis
834 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
835 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
838 /// Flat routing fee in satoshis
840 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
841 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
843 /// Liquidity-based routing fee in millionths of a routed amount.
844 /// In other words, 10000 is 1%.
846 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
847 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
850 /// Liquidity-based routing fee in millionths of a routed amount.
851 /// In other words, 10000 is 1%.
853 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
854 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
856 /// Constructs a new RoutingFees given each field
859 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
860 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
861 base_msat: base_msat_arg,
862 proportional_millionths: proportional_millionths_arg,
865 /// Checks if two RoutingFeess contain equal inner contents.
866 /// This ignores pointers and is_owned flags and looks at the values in fields.
867 /// Two objects with NULL inner values will be considered "equal" here.
869 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
870 if a.inner == b.inner { return true; }
871 if a.inner.is_null() || b.inner.is_null() { return false; }
872 if a.get_native_ref() == b.get_native_ref() { true } else { false }
874 impl Clone for RoutingFees {
875 fn clone(&self) -> Self {
877 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { std::ptr::null_mut() } else {
878 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
884 /// Used only if an object of this type is returned as a trait impl by a method
885 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
886 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
889 /// Creates a copy of the RoutingFees
890 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
894 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
895 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
896 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
899 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
900 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
903 /// Read a RoutingFees from a byte array, created by RoutingFees_write
904 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
905 let res = crate::c_types::deserialize_obj(ser);
906 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::RoutingFees { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
910 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
911 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
913 /// Information received in the latest node_announcement from this node.
916 pub struct NodeAnnouncementInfo {
917 /// A pointer to the opaque Rust object.
919 /// Nearly everywhere, inner must be non-null, however in places where
920 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
921 pub inner: *mut nativeNodeAnnouncementInfo,
922 /// Indicates that this is the only struct which contains the same pointer.
924 /// Rust functions which take ownership of an object provided via an argument require
925 /// this to be true and invalidate the object pointed to by inner.
929 impl Drop for NodeAnnouncementInfo {
931 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
932 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
936 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
938 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
940 /// Used only if an object of this type is returned as a trait impl by a method
941 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
942 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
945 impl NodeAnnouncementInfo {
946 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
947 unsafe { &*ObjOps::untweak_ptr(self.inner) }
949 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
950 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
952 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
953 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
954 assert!(self.is_owned);
955 let ret = ObjOps::untweak_ptr(self.inner);
956 self.inner = std::ptr::null_mut();
960 /// Protocol features the node announced support for
962 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
963 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
964 crate::lightning::ln::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
966 /// Protocol features the node announced support for
968 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
969 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
971 /// When the last known update to the node state was issued.
972 /// Value is opaque, as set in the announcement.
974 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
975 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
978 /// When the last known update to the node state was issued.
979 /// Value is opaque, as set in the announcement.
981 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
982 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
984 /// Color assigned to the node
986 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
987 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
990 /// Color assigned to the node
992 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
993 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
995 /// Moniker assigned to the node.
996 /// May be invalid or malicious (eg control chars),
997 /// should not be exposed to the user.
999 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
1000 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1003 /// Moniker assigned to the node.
1004 /// May be invalid or malicious (eg control chars),
1005 /// should not be exposed to the user.
1007 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
1008 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = val.data;
1010 /// Internet-level addresses via which one can connect to the node
1012 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
1013 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
1014 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val;
1016 /// An initial announcement of the node
1017 /// Mostly redundant with the data we store in fields explicitly.
1018 /// Everything else is useful only for sending out for initial routing sync.
1019 /// Not stored if contains excess data to prevent DoS.
1021 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1023 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1024 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1025 let mut local_inner_val = crate::lightning::ln::msgs::NodeAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1028 /// An initial announcement of the node
1029 /// Mostly redundant with the data we store in fields explicitly.
1030 /// Everything else is useful only for sending out for initial routing sync.
1031 /// Not stored if contains excess data to prevent DoS.
1033 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1035 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1036 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1037 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1039 /// Constructs a new NodeAnnouncementInfo given each field
1042 pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::lightning::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::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo {
1043 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
1044 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()) } }) };
1045 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1046 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1047 last_update: last_update_arg,
1049 alias: alias_arg.data,
1050 addresses: local_addresses_arg,
1051 announcement_message: local_announcement_message_arg,
1052 }), is_owned: true }
1054 impl Clone for NodeAnnouncementInfo {
1055 fn clone(&self) -> Self {
1057 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1058 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1064 /// Used only if an object of this type is returned as a trait impl by a method
1065 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1066 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1069 /// Creates a copy of the NodeAnnouncementInfo
1070 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1074 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1075 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1076 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1079 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1080 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1083 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1084 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1085 let res = crate::c_types::deserialize_obj(ser);
1086 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeAnnouncementInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1090 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
1091 type nativeNodeInfo = nativeNodeInfoImport;
1093 /// Details about a node in the network, known from the network announcement.
1096 pub struct NodeInfo {
1097 /// A pointer to the opaque Rust object.
1099 /// Nearly everywhere, inner must be non-null, however in places where
1100 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1101 pub inner: *mut nativeNodeInfo,
1102 /// Indicates that this is the only struct which contains the same pointer.
1104 /// Rust functions which take ownership of an object provided via an argument require
1105 /// this to be true and invalidate the object pointed to by inner.
1109 impl Drop for NodeInfo {
1110 fn drop(&mut self) {
1111 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1112 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1116 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1118 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1120 /// Used only if an object of this type is returned as a trait impl by a method
1121 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1122 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1126 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1127 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1129 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1130 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1132 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1133 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1134 assert!(self.is_owned);
1135 let ret = ObjOps::untweak_ptr(self.inner);
1136 self.inner = std::ptr::null_mut();
1140 /// All valid channels a node has announced
1142 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1143 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1144 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1146 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1147 /// The two fields (flat and proportional fee) are independent,
1148 /// meaning they don't have to refer to the same channel.
1150 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1152 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::RoutingFees {
1153 let mut inner_val = &mut this_ptr.get_native_mut_ref().lowest_inbound_channel_fees;
1154 let mut local_inner_val = crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1157 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1158 /// The two fields (flat and proportional fee) are independent,
1159 /// meaning they don't have to refer to the same channel.
1161 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1163 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
1164 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1165 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.lowest_inbound_channel_fees = local_val;
1167 /// More information about a node from node_announcement.
1168 /// Optional because we store a Node entry after learning about it from
1169 /// a channel announcement, but before receiving a node announcement.
1171 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1173 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::NodeAnnouncementInfo {
1174 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1175 let mut local_inner_val = crate::lightning::routing::network_graph::NodeAnnouncementInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1178 /// More information about a node from node_announcement.
1179 /// Optional because we store a Node entry after learning about it from
1180 /// a channel announcement, but before receiving a node announcement.
1182 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1184 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::NodeAnnouncementInfo) {
1185 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1186 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1188 /// Constructs a new NodeInfo given each field
1191 pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::lightning::routing::network_graph::RoutingFees, mut announcement_info_arg: crate::lightning::routing::network_graph::NodeAnnouncementInfo) -> NodeInfo {
1192 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1193 let mut local_lowest_inbound_channel_fees_arg = if lowest_inbound_channel_fees_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(lowest_inbound_channel_fees_arg.take_inner()) } }) };
1194 let mut local_announcement_info_arg = if announcement_info_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_info_arg.take_inner()) } }) };
1195 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1196 channels: local_channels_arg,
1197 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1198 announcement_info: local_announcement_info_arg,
1199 }), is_owned: true }
1201 impl Clone for NodeInfo {
1202 fn clone(&self) -> Self {
1204 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1205 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1211 /// Used only if an object of this type is returned as a trait impl by a method
1212 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1213 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1216 /// Creates a copy of the NodeInfo
1217 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1221 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1222 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1223 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1226 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1227 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1230 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1231 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1232 let res = crate::c_types::deserialize_obj(ser);
1233 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1237 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1238 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1239 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1242 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1243 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1246 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1247 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1248 let res = crate::c_types::deserialize_obj(ser);
1249 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NetworkGraph { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1252 /// Creates a new, empty, network graph.
1255 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::lightning::routing::network_graph::NetworkGraph {
1256 let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1257 crate::lightning::routing::network_graph::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1260 /// For an already known node (from channel announcements), update its stored properties from a
1261 /// given node announcement.
1263 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1264 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1265 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1268 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1269 let mut ret = unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(msg.get_native_ref(), secp256k1::SECP256K1);
1270 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1274 /// For an already known node (from channel announcements), update its stored properties from a
1275 /// given node announcement without verifying the associated signatures. Because we aren't
1276 /// given the associated signatures here we cannot relay the node announcement to any of our
1280 pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1281 let mut ret = unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(msg.get_native_ref());
1282 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1286 /// Store or update channel info from a channel announcement.
1288 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1289 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1290 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1292 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1293 /// the corresponding UTXO exists on chain and is correctly-formatted.
1295 /// Note that chain_access (or a relevant inner pointer) may be NULL or all-0s to represent None
1298 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, chain_access: *mut crate::lightning::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1299 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1300 let mut ret = unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(msg.get_native_ref(), &local_chain_access, secp256k1::SECP256K1);
1301 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1305 /// Store or update channel info from a channel announcement without verifying the associated
1306 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1307 /// channel announcement to any of our peers.
1309 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1310 /// the corresponding UTXO exists on chain and is correctly-formatted.
1312 /// Note that chain_access (or a relevant inner pointer) may be NULL or all-0s to represent None
1315 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, chain_access: *mut crate::lightning::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1316 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1317 let mut ret = unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_chain_access);
1318 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1322 /// Close a channel if a corresponding HTLC fail was sent.
1323 /// If permanent, removes a channel from the local storage.
1324 /// May cause the removal of nodes too, if this was their last channel.
1325 /// If not permanent, makes channels unavailable for routing.
1327 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1328 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)
1331 /// For an already known (from announcement) channel, update info about one of the directions
1334 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1335 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1336 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1339 pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1340 let mut ret = unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(msg.get_native_ref(), secp256k1::SECP256K1);
1341 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1345 /// For an already known (from announcement) channel, update info about one of the directions
1346 /// of the channel without verifying the associated signatures. Because we aren't given the
1347 /// associated signatures here we cannot relay the channel update to any of our peers.
1350 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1351 let mut ret = unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(msg.get_native_ref());
1352 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };