7947ac628b0d34b0ad439fc484ddec49b501e204
[ldk-c-bindings] / lightning-c-bindings / src / routing / network_graph.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! The top-level network map tracking logic lives here.
10
11 use std::ffi::c_void;
12 use bitcoin::hashes::Hash;
13 use crate::c_types::*;
14
15
16 use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport;
17 type nativeNetworkGraph = nativeNetworkGraphImport;
18
19 /// Represents the network as nodes and channels between them
20 #[must_use]
21 #[repr(C)]
22 pub struct NetworkGraph {
23         /// A pointer to the opaque Rust object.
24
25         /// Nearly everywhere, inner must be non-null, however in places where
26         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
27         pub inner: *mut nativeNetworkGraph,
28         /// Indicates that this is the only struct which contains the same pointer.
29
30         /// Rust functions which take ownership of an object provided via an argument require
31         /// this to be true and invalidate the object pointed to by inner.
32         pub is_owned: bool,
33 }
34
35 impl Drop for NetworkGraph {
36         fn drop(&mut self) {
37                 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
38                         let _ = unsafe { Box::from_raw(self.inner) };
39                 }
40         }
41 }
42 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
43 #[no_mangle]
44 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
45 #[allow(unused)]
46 /// Used only if an object of this type is returned as a trait impl by a method
47 extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
48         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
49 }
50 #[allow(unused)]
51 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
52 impl NetworkGraph {
53         pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
54                 assert!(self.is_owned);
55                 let ret = self.inner;
56                 self.inner = std::ptr::null_mut();
57                 ret
58         }
59 }
60 impl Clone for NetworkGraph {
61         fn clone(&self) -> Self {
62                 Self {
63                         inner: if <*mut nativeNetworkGraph>::is_null(self.inner) { std::ptr::null_mut() } else {
64                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
65                         is_owned: true,
66                 }
67         }
68 }
69 #[allow(unused)]
70 /// Used only if an object of this type is returned as a trait impl by a method
71 pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void {
72         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void
73 }
74 #[no_mangle]
75 /// Creates a copy of the NetworkGraph
76 pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph {
77         orig.clone()
78 }
79
80 use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport;
81 type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>;
82
83 /// A simple newtype for RwLockReadGuard<'a, NetworkGraph>.
84 /// This exists only to make accessing a RwLock<NetworkGraph> possible from
85 /// the C bindings, as it can be done directly in Rust code.
86 #[must_use]
87 #[repr(C)]
88 pub struct LockedNetworkGraph {
89         /// A pointer to the opaque Rust object.
90
91         /// Nearly everywhere, inner must be non-null, however in places where
92         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
93         pub inner: *mut nativeLockedNetworkGraph,
94         /// Indicates that this is the only struct which contains the same pointer.
95
96         /// Rust functions which take ownership of an object provided via an argument require
97         /// this to be true and invalidate the object pointed to by inner.
98         pub is_owned: bool,
99 }
100
101 impl Drop for LockedNetworkGraph {
102         fn drop(&mut self) {
103                 if self.is_owned && !<*mut nativeLockedNetworkGraph>::is_null(self.inner) {
104                         let _ = unsafe { Box::from_raw(self.inner) };
105                 }
106         }
107 }
108 /// Frees any resources used by the LockedNetworkGraph, if is_owned is set and inner is non-NULL.
109 #[no_mangle]
110 pub extern "C" fn LockedNetworkGraph_free(this_obj: LockedNetworkGraph) { }
111 #[allow(unused)]
112 /// Used only if an object of this type is returned as a trait impl by a method
113 extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) {
114         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedNetworkGraph); }
115 }
116 #[allow(unused)]
117 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
118 impl LockedNetworkGraph {
119         pub(crate) fn take_inner(mut self) -> *mut nativeLockedNetworkGraph {
120                 assert!(self.is_owned);
121                 let ret = self.inner;
122                 self.inner = std::ptr::null_mut();
123                 ret
124         }
125 }
126
127 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
128 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::chain::Access, crate::util::logger::Logger>;
129
130 /// Receives and validates network updates from peers,
131 /// stores authentic and relevant data as a network graph.
132 /// This network graph is then used for routing payments.
133 /// Provides interface to help with initial routing sync by
134 /// serving historical announcements.
135 #[must_use]
136 #[repr(C)]
137 pub struct NetGraphMsgHandler {
138         /// A pointer to the opaque Rust object.
139
140         /// Nearly everywhere, inner must be non-null, however in places where
141         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
142         pub inner: *mut nativeNetGraphMsgHandler,
143         /// Indicates that this is the only struct which contains the same pointer.
144
145         /// Rust functions which take ownership of an object provided via an argument require
146         /// this to be true and invalidate the object pointed to by inner.
147         pub is_owned: bool,
148 }
149
150 impl Drop for NetGraphMsgHandler {
151         fn drop(&mut self) {
152                 if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) {
153                         let _ = unsafe { Box::from_raw(self.inner) };
154                 }
155         }
156 }
157 /// Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL.
158 #[no_mangle]
159 pub extern "C" fn NetGraphMsgHandler_free(this_obj: NetGraphMsgHandler) { }
160 #[allow(unused)]
161 /// Used only if an object of this type is returned as a trait impl by a method
162 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
163         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
164 }
165 #[allow(unused)]
166 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
167 impl NetGraphMsgHandler {
168         pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
169                 assert!(self.is_owned);
170                 let ret = self.inner;
171                 self.inner = std::ptr::null_mut();
172                 ret
173         }
174 }
175 /// Creates a new tracker of the actual state of the network of channels and nodes,
176 /// assuming a fresh network graph.
177 /// Chain monitor is used to make sure announced channels exist on-chain,
178 /// channel data is correct, and that the announcement is signed with
179 /// channel owners' keys.
180 #[must_use]
181 #[no_mangle]
182 pub extern "C" fn NetGraphMsgHandler_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler {
183         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
184         let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), local_chain_access, logger);
185         NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
186 }
187
188 /// Creates a new tracker of the actual state of the network of channels and nodes,
189 /// assuming an existing Network Graph.
190 #[must_use]
191 #[no_mangle]
192 pub extern "C" fn NetGraphMsgHandler_from_net_graph(chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger, mut network_graph: crate::routing::network_graph::NetworkGraph) -> NetGraphMsgHandler {
193         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
194         let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_inner()) });
195         NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
196 }
197
198 /// Adds a provider used to check new announcements. Does not affect
199 /// existing announcements unless they are updated.
200 /// Add, update or remove the provider would replace the current one.
201 #[no_mangle]
202 pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut NetGraphMsgHandler, chain_access: *mut crate::chain::Access) {
203         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
204         unsafe { &mut (*(this_arg.inner as *mut nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access)
205 }
206
207 /// Take a read lock on the network_graph and return it in the C-bindings
208 /// newtype helper. This is likely only useful when called via the C
209 /// bindings as you can call `self.network_graph.read().unwrap()` in Rust
210 /// yourself.
211 #[must_use]
212 #[no_mangle]
213 pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::routing::network_graph::LockedNetworkGraph {
214         let mut ret = unsafe { &*this_arg.inner }.read_locked_graph();
215         crate::routing::network_graph::LockedNetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
216 }
217
218 /// Get a reference to the NetworkGraph which this read-lock contains.
219 #[must_use]
220 #[no_mangle]
221 pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::routing::network_graph::NetworkGraph {
222         let mut ret = unsafe { &*this_arg.inner }.graph();
223         crate::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
224 }
225
226 impl From<nativeNetGraphMsgHandler> for crate::ln::msgs::RoutingMessageHandler {
227         fn from(obj: nativeNetGraphMsgHandler) -> Self {
228                 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
229                 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
230                 // 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
231                 rust_obj.inner = std::ptr::null_mut();
232                 ret.free = Some(NetGraphMsgHandler_free_void);
233                 ret
234         }
235 }
236 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
237 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
238 #[no_mangle]
239 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler {
240         crate::ln::msgs::RoutingMessageHandler {
241                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
242                 free: None,
243                 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
244                 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
245                 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
246                 handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
247                 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
248                 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
249                 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
250                 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
251                 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
252                 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
253                 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
254                 MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider {
255                         this_arg: unsafe { (*this_arg).inner as *mut c_void },
256                         free: None,
257                         get_and_clear_pending_msg_events: NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events,
258                 },
259         }
260 }
261
262 #[must_use]
263 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
264         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
265         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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
266         local_ret
267 }
268 #[must_use]
269 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
270         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
271         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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
272         local_ret
273 }
274 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) {
275         <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_htlc_fail_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &update.to_native())
276 }
277 #[must_use]
278 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
279         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
280         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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
281         local_ret
282 }
283 #[must_use]
284 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 {
285         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount);
286         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::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::ptr::null_mut() } else {  { Box::into_raw(Box::new((orig_ret_0_1.unwrap()))) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { std::ptr::null_mut() } else {  { Box::into_raw(Box::new((orig_ret_0_2.unwrap()))) } }, is_owned: true }; let mut local_ret_0 = (crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(orig_ret_0_0)), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); };
287         local_ret.into()
288 }
289 #[must_use]
290 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 {
291         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();
292         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);
293         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
294         local_ret.into()
295 }
296 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init_msg: &crate::ln::msgs::Init) {
297         <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::sync_routing_table(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), unsafe { &*init_msg.inner })
298 }
299 #[must_use]
300 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::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
301         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()) });
302         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() };
303         local_ret
304 }
305 #[must_use]
306 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::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
307         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()) });
308         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() };
309         local_ret
310 }
311 #[must_use]
312 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 {
313         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()) });
314         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() };
315         local_ret
316 }
317 #[must_use]
318 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::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
319         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()) });
320         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() };
321         local_ret
322 }
323 #[must_use]
324 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
325         let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
326         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
327         local_ret.into()
328 }
329
330 impl From<nativeNetGraphMsgHandler> for crate::util::events::MessageSendEventsProvider {
331         fn from(obj: nativeNetGraphMsgHandler) -> Self {
332                 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
333                 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
334                 // 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
335                 rust_obj.inner = std::ptr::null_mut();
336                 ret.free = Some(NetGraphMsgHandler_free_void);
337                 ret
338         }
339 }
340 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
341 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
342 #[no_mangle]
343 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::util::events::MessageSendEventsProvider {
344         crate::util::events::MessageSendEventsProvider {
345                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
346                 free: None,
347                 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
348         }
349 }
350
351 #[must_use]
352 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
353         let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
354         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
355         local_ret.into()
356 }
357
358
359 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
360 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
361
362 /// Details about one direction of a channel. Received
363 /// within a channel update.
364 #[must_use]
365 #[repr(C)]
366 pub struct DirectionalChannelInfo {
367         /// A pointer to the opaque Rust object.
368
369         /// Nearly everywhere, inner must be non-null, however in places where
370         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
371         pub inner: *mut nativeDirectionalChannelInfo,
372         /// Indicates that this is the only struct which contains the same pointer.
373
374         /// Rust functions which take ownership of an object provided via an argument require
375         /// this to be true and invalidate the object pointed to by inner.
376         pub is_owned: bool,
377 }
378
379 impl Drop for DirectionalChannelInfo {
380         fn drop(&mut self) {
381                 if self.is_owned && !<*mut nativeDirectionalChannelInfo>::is_null(self.inner) {
382                         let _ = unsafe { Box::from_raw(self.inner) };
383                 }
384         }
385 }
386 /// Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL.
387 #[no_mangle]
388 pub extern "C" fn DirectionalChannelInfo_free(this_obj: DirectionalChannelInfo) { }
389 #[allow(unused)]
390 /// Used only if an object of this type is returned as a trait impl by a method
391 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
392         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
393 }
394 #[allow(unused)]
395 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
396 impl DirectionalChannelInfo {
397         pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo {
398                 assert!(self.is_owned);
399                 let ret = self.inner;
400                 self.inner = std::ptr::null_mut();
401                 ret
402         }
403 }
404 /// When the last update to the channel direction was issued.
405 /// Value is opaque, as set in the announcement.
406 #[no_mangle]
407 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
408         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
409         (*inner_val)
410 }
411 /// When the last update to the channel direction was issued.
412 /// Value is opaque, as set in the announcement.
413 #[no_mangle]
414 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
415         unsafe { &mut *this_ptr.inner }.last_update = val;
416 }
417 /// Whether the channel can be currently used for payments (in this one direction).
418 #[no_mangle]
419 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
420         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.enabled;
421         (*inner_val)
422 }
423 /// Whether the channel can be currently used for payments (in this one direction).
424 #[no_mangle]
425 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
426         unsafe { &mut *this_ptr.inner }.enabled = val;
427 }
428 /// The difference in CLTV values that you must have when routing through this channel.
429 #[no_mangle]
430 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
431         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
432         (*inner_val)
433 }
434 /// The difference in CLTV values that you must have when routing through this channel.
435 #[no_mangle]
436 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
437         unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
438 }
439 /// The minimum value, which must be relayed to the next hop via the channel
440 #[no_mangle]
441 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
442         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
443         (*inner_val)
444 }
445 /// The minimum value, which must be relayed to the next hop via the channel
446 #[no_mangle]
447 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
448         unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val;
449 }
450 /// The maximum value which may be relayed to the next hop via the channel.
451 #[no_mangle]
452 pub extern "C" fn DirectionalChannelInfo_get_htlc_maximum_msat(this_ptr: &DirectionalChannelInfo) -> crate::c_types::derived::COption_u64Z {
453         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_maximum_msat;
454         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()) } };
455         local_inner_val
456 }
457 /// The maximum value which may be relayed to the next hop via the channel.
458 #[no_mangle]
459 pub extern "C" fn DirectionalChannelInfo_set_htlc_maximum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
460         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
461         unsafe { &mut *this_ptr.inner }.htlc_maximum_msat = local_val;
462 }
463 /// Fees charged when the channel is used for routing
464 #[no_mangle]
465 pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::routing::network_graph::RoutingFees {
466         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fees;
467         crate::routing::network_graph::RoutingFees { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
468 }
469 /// Fees charged when the channel is used for routing
470 #[no_mangle]
471 pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::routing::network_graph::RoutingFees) {
472         unsafe { &mut *this_ptr.inner }.fees = *unsafe { Box::from_raw(val.take_inner()) };
473 }
474 /// Most recent update for the channel received from the network
475 /// Mostly redundant with the data we store in fields explicitly.
476 /// Everything else is useful only for sending out for initial routing sync.
477 /// Not stored if contains excess data to prevent DoS.
478 #[no_mangle]
479 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::ln::msgs::ChannelUpdate {
480         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update_message;
481         let mut local_inner_val = crate::ln::msgs::ChannelUpdate { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
482         local_inner_val
483 }
484 /// Most recent update for the channel received from the network
485 /// Mostly redundant with the data we store in fields explicitly.
486 /// Everything else is useful only for sending out for initial routing sync.
487 /// Not stored if contains excess data to prevent DoS.
488 #[no_mangle]
489 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::ln::msgs::ChannelUpdate) {
490         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
491         unsafe { &mut *this_ptr.inner }.last_update_message = local_val;
492 }
493 /// Constructs a new DirectionalChannelInfo given each field
494 #[must_use]
495 #[no_mangle]
496 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 {
497         let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
498         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()) } }) };
499         DirectionalChannelInfo { inner: Box::into_raw(Box::new(nativeDirectionalChannelInfo {
500                 last_update: last_update_arg,
501                 enabled: enabled_arg,
502                 cltv_expiry_delta: cltv_expiry_delta_arg,
503                 htlc_minimum_msat: htlc_minimum_msat_arg,
504                 htlc_maximum_msat: local_htlc_maximum_msat_arg,
505                 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
506                 last_update_message: local_last_update_message_arg,
507         })), is_owned: true }
508 }
509 impl Clone for DirectionalChannelInfo {
510         fn clone(&self) -> Self {
511                 Self {
512                         inner: if <*mut nativeDirectionalChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
513                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
514                         is_owned: true,
515                 }
516         }
517 }
518 #[allow(unused)]
519 /// Used only if an object of this type is returned as a trait impl by a method
520 pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
521         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
522 }
523 #[no_mangle]
524 /// Creates a copy of the DirectionalChannelInfo
525 pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
526         orig.clone()
527 }
528 #[no_mangle]
529 /// Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read
530 pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
531         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
532 }
533 #[no_mangle]
534 pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
535         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) })
536 }
537 #[no_mangle]
538 /// Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write
539 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ {
540         let res = crate::c_types::deserialize_obj(ser);
541         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() };
542         local_res
543 }
544
545 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
546 type nativeChannelInfo = nativeChannelInfoImport;
547
548 /// Details about a channel (both directions).
549 /// Received within a channel announcement.
550 #[must_use]
551 #[repr(C)]
552 pub struct ChannelInfo {
553         /// A pointer to the opaque Rust object.
554
555         /// Nearly everywhere, inner must be non-null, however in places where
556         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
557         pub inner: *mut nativeChannelInfo,
558         /// Indicates that this is the only struct which contains the same pointer.
559
560         /// Rust functions which take ownership of an object provided via an argument require
561         /// this to be true and invalidate the object pointed to by inner.
562         pub is_owned: bool,
563 }
564
565 impl Drop for ChannelInfo {
566         fn drop(&mut self) {
567                 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
568                         let _ = unsafe { Box::from_raw(self.inner) };
569                 }
570         }
571 }
572 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
573 #[no_mangle]
574 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
575 #[allow(unused)]
576 /// Used only if an object of this type is returned as a trait impl by a method
577 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
578         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
579 }
580 #[allow(unused)]
581 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
582 impl ChannelInfo {
583         pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
584                 assert!(self.is_owned);
585                 let ret = self.inner;
586                 self.inner = std::ptr::null_mut();
587                 ret
588         }
589 }
590 /// Protocol features of a channel communicated during its announcement
591 #[no_mangle]
592 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::ln::features::ChannelFeatures {
593         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
594         crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
595 }
596 /// Protocol features of a channel communicated during its announcement
597 #[no_mangle]
598 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::ln::features::ChannelFeatures) {
599         unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
600 }
601 /// Source node of the first direction of a channel
602 #[no_mangle]
603 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
604         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_one;
605         crate::c_types::PublicKey::from_rust(&(*inner_val))
606 }
607 /// Source node of the first direction of a channel
608 #[no_mangle]
609 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
610         unsafe { &mut *this_ptr.inner }.node_one = val.into_rust();
611 }
612 /// Details about the first direction of a channel
613 #[no_mangle]
614 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
615         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.one_to_two;
616         let mut local_inner_val = crate::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
617         local_inner_val
618 }
619 /// Details about the first direction of a channel
620 #[no_mangle]
621 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
622         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
623         unsafe { &mut *this_ptr.inner }.one_to_two = local_val;
624 }
625 /// Source node of the second direction of a channel
626 #[no_mangle]
627 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
628         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_two;
629         crate::c_types::PublicKey::from_rust(&(*inner_val))
630 }
631 /// Source node of the second direction of a channel
632 #[no_mangle]
633 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
634         unsafe { &mut *this_ptr.inner }.node_two = val.into_rust();
635 }
636 /// Details about the second direction of a channel
637 #[no_mangle]
638 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
639         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.two_to_one;
640         let mut local_inner_val = crate::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
641         local_inner_val
642 }
643 /// Details about the second direction of a channel
644 #[no_mangle]
645 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
646         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
647         unsafe { &mut *this_ptr.inner }.two_to_one = local_val;
648 }
649 /// The channel capacity as seen on-chain, if chain lookup is available.
650 #[no_mangle]
651 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
652         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.capacity_sats;
653         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()) } };
654         local_inner_val
655 }
656 /// The channel capacity as seen on-chain, if chain lookup is available.
657 #[no_mangle]
658 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
659         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
660         unsafe { &mut *this_ptr.inner }.capacity_sats = local_val;
661 }
662 /// An initial announcement of the channel
663 /// Mostly redundant with the data we store in fields explicitly.
664 /// Everything else is useful only for sending out for initial routing sync.
665 /// Not stored if contains excess data to prevent DoS.
666 #[no_mangle]
667 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::ln::msgs::ChannelAnnouncement {
668         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
669         let mut local_inner_val = crate::ln::msgs::ChannelAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
670         local_inner_val
671 }
672 /// An initial announcement of the channel
673 /// Mostly redundant with the data we store in fields explicitly.
674 /// Everything else is useful only for sending out for initial routing sync.
675 /// Not stored if contains excess data to prevent DoS.
676 #[no_mangle]
677 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::ln::msgs::ChannelAnnouncement) {
678         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
679         unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
680 }
681 /// Constructs a new ChannelInfo given each field
682 #[must_use]
683 #[no_mangle]
684 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 {
685         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()) } }) };
686         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()) } }) };
687         let mut local_capacity_sats_arg = if capacity_sats_arg.is_some() { Some( { capacity_sats_arg.take() }) } else { None };
688         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()) } }) };
689         ChannelInfo { inner: Box::into_raw(Box::new(nativeChannelInfo {
690                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
691                 node_one: node_one_arg.into_rust(),
692                 one_to_two: local_one_to_two_arg,
693                 node_two: node_two_arg.into_rust(),
694                 two_to_one: local_two_to_one_arg,
695                 capacity_sats: local_capacity_sats_arg,
696                 announcement_message: local_announcement_message_arg,
697         })), is_owned: true }
698 }
699 impl Clone for ChannelInfo {
700         fn clone(&self) -> Self {
701                 Self {
702                         inner: if <*mut nativeChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
703                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
704                         is_owned: true,
705                 }
706         }
707 }
708 #[allow(unused)]
709 /// Used only if an object of this type is returned as a trait impl by a method
710 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
711         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
712 }
713 #[no_mangle]
714 /// Creates a copy of the ChannelInfo
715 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
716         orig.clone()
717 }
718 #[no_mangle]
719 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
720 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
721         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
722 }
723 #[no_mangle]
724 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
725         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
726 }
727 #[no_mangle]
728 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
729 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
730         let res = crate::c_types::deserialize_obj(ser);
731         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() };
732         local_res
733 }
734
735 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
736 type nativeRoutingFees = nativeRoutingFeesImport;
737
738 /// Fees for routing via a given channel or a node
739 #[must_use]
740 #[repr(C)]
741 pub struct RoutingFees {
742         /// A pointer to the opaque Rust object.
743
744         /// Nearly everywhere, inner must be non-null, however in places where
745         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
746         pub inner: *mut nativeRoutingFees,
747         /// Indicates that this is the only struct which contains the same pointer.
748
749         /// Rust functions which take ownership of an object provided via an argument require
750         /// this to be true and invalidate the object pointed to by inner.
751         pub is_owned: bool,
752 }
753
754 impl Drop for RoutingFees {
755         fn drop(&mut self) {
756                 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
757                         let _ = unsafe { Box::from_raw(self.inner) };
758                 }
759         }
760 }
761 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
762 #[no_mangle]
763 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
764 #[allow(unused)]
765 /// Used only if an object of this type is returned as a trait impl by a method
766 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
767         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
768 }
769 #[allow(unused)]
770 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
771 impl RoutingFees {
772         pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
773                 assert!(self.is_owned);
774                 let ret = self.inner;
775                 self.inner = std::ptr::null_mut();
776                 ret
777         }
778 }
779 /// Flat routing fee in satoshis
780 #[no_mangle]
781 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
782         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat;
783         (*inner_val)
784 }
785 /// Flat routing fee in satoshis
786 #[no_mangle]
787 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
788         unsafe { &mut *this_ptr.inner }.base_msat = val;
789 }
790 /// Liquidity-based routing fee in millionths of a routed amount.
791 /// In other words, 10000 is 1%.
792 #[no_mangle]
793 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
794         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths;
795         (*inner_val)
796 }
797 /// Liquidity-based routing fee in millionths of a routed amount.
798 /// In other words, 10000 is 1%.
799 #[no_mangle]
800 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
801         unsafe { &mut *this_ptr.inner }.proportional_millionths = val;
802 }
803 /// Constructs a new RoutingFees given each field
804 #[must_use]
805 #[no_mangle]
806 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
807         RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees {
808                 base_msat: base_msat_arg,
809                 proportional_millionths: proportional_millionths_arg,
810         })), is_owned: true }
811 }
812 impl Clone for RoutingFees {
813         fn clone(&self) -> Self {
814                 Self {
815                         inner: if <*mut nativeRoutingFees>::is_null(self.inner) { std::ptr::null_mut() } else {
816                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
817                         is_owned: true,
818                 }
819         }
820 }
821 #[allow(unused)]
822 /// Used only if an object of this type is returned as a trait impl by a method
823 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
824         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
825 }
826 #[no_mangle]
827 /// Creates a copy of the RoutingFees
828 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
829         orig.clone()
830 }
831 #[no_mangle]
832 /// Read a RoutingFees from a byte array, created by RoutingFees_write
833 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
834         let res = crate::c_types::deserialize_obj(ser);
835         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() };
836         local_res
837 }
838 #[no_mangle]
839 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
840 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
841         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
842 }
843 #[no_mangle]
844 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
845         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
846 }
847
848 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
849 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
850
851 /// Information received in the latest node_announcement from this node.
852 #[must_use]
853 #[repr(C)]
854 pub struct NodeAnnouncementInfo {
855         /// A pointer to the opaque Rust object.
856
857         /// Nearly everywhere, inner must be non-null, however in places where
858         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
859         pub inner: *mut nativeNodeAnnouncementInfo,
860         /// Indicates that this is the only struct which contains the same pointer.
861
862         /// Rust functions which take ownership of an object provided via an argument require
863         /// this to be true and invalidate the object pointed to by inner.
864         pub is_owned: bool,
865 }
866
867 impl Drop for NodeAnnouncementInfo {
868         fn drop(&mut self) {
869                 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
870                         let _ = unsafe { Box::from_raw(self.inner) };
871                 }
872         }
873 }
874 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
875 #[no_mangle]
876 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
877 #[allow(unused)]
878 /// Used only if an object of this type is returned as a trait impl by a method
879 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
880         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
881 }
882 #[allow(unused)]
883 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
884 impl NodeAnnouncementInfo {
885         pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
886                 assert!(self.is_owned);
887                 let ret = self.inner;
888                 self.inner = std::ptr::null_mut();
889                 ret
890         }
891 }
892 /// Protocol features the node announced support for
893 #[no_mangle]
894 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures {
895         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
896         crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
897 }
898 /// Protocol features the node announced support for
899 #[no_mangle]
900 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::features::NodeFeatures) {
901         unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
902 }
903 /// When the last known update to the node state was issued.
904 /// Value is opaque, as set in the announcement.
905 #[no_mangle]
906 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
907         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
908         (*inner_val)
909 }
910 /// When the last known update to the node state was issued.
911 /// Value is opaque, as set in the announcement.
912 #[no_mangle]
913 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
914         unsafe { &mut *this_ptr.inner }.last_update = val;
915 }
916 /// Color assigned to the node
917 #[no_mangle]
918 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
919         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
920         &(*inner_val)
921 }
922 /// Color assigned to the node
923 #[no_mangle]
924 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
925         unsafe { &mut *this_ptr.inner }.rgb = val.data;
926 }
927 /// Moniker assigned to the node.
928 /// May be invalid or malicious (eg control chars),
929 /// should not be exposed to the user.
930 #[no_mangle]
931 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
932         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
933         &(*inner_val)
934 }
935 /// Moniker assigned to the node.
936 /// May be invalid or malicious (eg control chars),
937 /// should not be exposed to the user.
938 #[no_mangle]
939 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
940         unsafe { &mut *this_ptr.inner }.alias = val.data;
941 }
942 /// Internet-level addresses via which one can connect to the node
943 #[no_mangle]
944 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
945         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
946         unsafe { &mut *this_ptr.inner }.addresses = local_val;
947 }
948 /// An initial announcement of the node
949 /// Mostly redundant with the data we store in fields explicitly.
950 /// Everything else is useful only for sending out for initial routing sync.
951 /// Not stored if contains excess data to prevent DoS.
952 #[no_mangle]
953 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::ln::msgs::NodeAnnouncement {
954         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
955         let mut local_inner_val = crate::ln::msgs::NodeAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
956         local_inner_val
957 }
958 /// An initial announcement of the node
959 /// Mostly redundant with the data we store in fields explicitly.
960 /// Everything else is useful only for sending out for initial routing sync.
961 /// Not stored if contains excess data to prevent DoS.
962 #[no_mangle]
963 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::msgs::NodeAnnouncement) {
964         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
965         unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
966 }
967 /// Constructs a new NodeAnnouncementInfo given each field
968 #[must_use]
969 #[no_mangle]
970 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 {
971         let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
972         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()) } }) };
973         NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo {
974                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
975                 last_update: last_update_arg,
976                 rgb: rgb_arg.data,
977                 alias: alias_arg.data,
978                 addresses: local_addresses_arg,
979                 announcement_message: local_announcement_message_arg,
980         })), is_owned: true }
981 }
982 impl Clone for NodeAnnouncementInfo {
983         fn clone(&self) -> Self {
984                 Self {
985                         inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
986                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
987                         is_owned: true,
988                 }
989         }
990 }
991 #[allow(unused)]
992 /// Used only if an object of this type is returned as a trait impl by a method
993 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
994         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
995 }
996 #[no_mangle]
997 /// Creates a copy of the NodeAnnouncementInfo
998 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
999         orig.clone()
1000 }
1001 #[no_mangle]
1002 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1003 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1004         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1005 }
1006 #[no_mangle]
1007 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1008         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1009 }
1010 #[no_mangle]
1011 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1012 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1013         let res = crate::c_types::deserialize_obj(ser);
1014         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() };
1015         local_res
1016 }
1017
1018 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
1019 type nativeNodeInfo = nativeNodeInfoImport;
1020
1021 /// Details about a node in the network, known from the network announcement.
1022 #[must_use]
1023 #[repr(C)]
1024 pub struct NodeInfo {
1025         /// A pointer to the opaque Rust object.
1026
1027         /// Nearly everywhere, inner must be non-null, however in places where
1028         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1029         pub inner: *mut nativeNodeInfo,
1030         /// Indicates that this is the only struct which contains the same pointer.
1031
1032         /// Rust functions which take ownership of an object provided via an argument require
1033         /// this to be true and invalidate the object pointed to by inner.
1034         pub is_owned: bool,
1035 }
1036
1037 impl Drop for NodeInfo {
1038         fn drop(&mut self) {
1039                 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1040                         let _ = unsafe { Box::from_raw(self.inner) };
1041                 }
1042         }
1043 }
1044 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1045 #[no_mangle]
1046 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1047 #[allow(unused)]
1048 /// Used only if an object of this type is returned as a trait impl by a method
1049 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1050         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1051 }
1052 #[allow(unused)]
1053 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1054 impl NodeInfo {
1055         pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1056                 assert!(self.is_owned);
1057                 let ret = self.inner;
1058                 self.inner = std::ptr::null_mut();
1059                 ret
1060         }
1061 }
1062 /// All valid channels a node has announced
1063 #[no_mangle]
1064 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1065         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1066         unsafe { &mut *this_ptr.inner }.channels = local_val;
1067 }
1068 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1069 /// The two fields (flat and proportional fee) are independent,
1070 /// meaning they don't have to refer to the same channel.
1071 #[no_mangle]
1072 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::routing::network_graph::RoutingFees {
1073         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
1074         let mut local_inner_val = crate::routing::network_graph::RoutingFees { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1075         local_inner_val
1076 }
1077 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1078 /// The two fields (flat and proportional fee) are independent,
1079 /// meaning they don't have to refer to the same channel.
1080 #[no_mangle]
1081 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::RoutingFees) {
1082         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1083         unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val;
1084 }
1085 /// More information about a node from node_announcement.
1086 /// Optional because we store a Node entry after learning about it from
1087 /// a channel announcement, but before receiving a node announcement.
1088 #[no_mangle]
1089 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::routing::network_graph::NodeAnnouncementInfo {
1090         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
1091         let mut local_inner_val = crate::routing::network_graph::NodeAnnouncementInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1092         local_inner_val
1093 }
1094 /// More information about a node from node_announcement.
1095 /// Optional because we store a Node entry after learning about it from
1096 /// a channel announcement, but before receiving a node announcement.
1097 #[no_mangle]
1098 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::NodeAnnouncementInfo) {
1099         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1100         unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
1101 }
1102 /// Constructs a new NodeInfo given each field
1103 #[must_use]
1104 #[no_mangle]
1105 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 {
1106         let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1107         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()) } }) };
1108         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()) } }) };
1109         NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
1110                 channels: local_channels_arg,
1111                 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1112                 announcement_info: local_announcement_info_arg,
1113         })), is_owned: true }
1114 }
1115 impl Clone for NodeInfo {
1116         fn clone(&self) -> Self {
1117                 Self {
1118                         inner: if <*mut nativeNodeInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1119                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1120                         is_owned: true,
1121                 }
1122         }
1123 }
1124 #[allow(unused)]
1125 /// Used only if an object of this type is returned as a trait impl by a method
1126 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1127         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1128 }
1129 #[no_mangle]
1130 /// Creates a copy of the NodeInfo
1131 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1132         orig.clone()
1133 }
1134 #[no_mangle]
1135 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1136 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1137         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1138 }
1139 #[no_mangle]
1140 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1141         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1142 }
1143 #[no_mangle]
1144 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1145 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1146         let res = crate::c_types::deserialize_obj(ser);
1147         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() };
1148         local_res
1149 }
1150 #[no_mangle]
1151 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1152 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1153         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1154 }
1155 #[no_mangle]
1156 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1157         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1158 }
1159 #[no_mangle]
1160 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1161 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1162         let res = crate::c_types::deserialize_obj(ser);
1163         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() };
1164         local_res
1165 }
1166 /// Creates a new, empty, network graph.
1167 #[must_use]
1168 #[no_mangle]
1169 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::routing::network_graph::NetworkGraph {
1170         let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1171         crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1172 }
1173
1174 /// For an already known node (from channel announcements), update its stored properties from a
1175 /// given node announcement.
1176 ///
1177 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1178 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1179 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1180 #[must_use]
1181 #[no_mangle]
1182 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1183         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1184         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() };
1185         local_ret
1186 }
1187
1188 /// For an already known node (from channel announcements), update its stored properties from a
1189 /// given node announcement without verifying the associated signatures. Because we aren't
1190 /// given the associated signatures here we cannot relay the node announcement to any of our
1191 /// peers.
1192 #[must_use]
1193 #[no_mangle]
1194 pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1195         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(unsafe { &*msg.inner });
1196         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() };
1197         local_ret
1198 }
1199
1200 /// Store or update channel info from a channel announcement.
1201 ///
1202 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1203 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1204 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1205 ///
1206 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1207 /// the corresponding UTXO exists on chain and is correctly-formatted.
1208 #[must_use]
1209 #[no_mangle]
1210 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1211         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1212         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, secp256k1::SECP256K1);
1213         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() };
1214         local_ret
1215 }
1216
1217 /// Store or update channel info from a channel announcement without verifying the associated
1218 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1219 /// channel announcement to any of our peers.
1220 ///
1221 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1222 /// the corresponding UTXO exists on chain and is correctly-formatted.
1223 #[must_use]
1224 #[no_mangle]
1225 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1226         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1227         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(unsafe { &*msg.inner }, &local_chain_access);
1228         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() };
1229         local_ret
1230 }
1231
1232 /// Close a channel if a corresponding HTLC fail was sent.
1233 /// If permanent, removes a channel from the local storage.
1234 /// May cause the removal of nodes too, if this was their last channel.
1235 /// If not permanent, makes channels unavailable for routing.
1236 #[no_mangle]
1237 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1238         unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)
1239 }
1240
1241 /// For an already known (from announcement) channel, update info about one of the directions
1242 /// of the channel.
1243 ///
1244 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1245 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1246 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1247 #[must_use]
1248 #[no_mangle]
1249 pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1250         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1251         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() };
1252         local_ret
1253 }
1254
1255 /// For an already known (from announcement) channel, update info about one of the directions
1256 /// of the channel without verifying the associated signatures. Because we aren't given the
1257 /// associated signatures here we cannot relay the channel update to any of our peers.
1258 #[must_use]
1259 #[no_mangle]
1260 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1261         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(unsafe { &*msg.inner });
1262         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() };
1263         local_ret
1264 }
1265