11eb92a363a1dca996418ee29399361feb3ab7a0
[rust-lightning] / lightning-c-bindings / src / routing / network_graph.rs
1 //! The top-level network map tracking logic lives here.
2
3 use std::ffi::c_void;
4 use bitcoin::hashes::Hash;
5 use crate::c_types::*;
6
7
8 use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport;
9 type nativeNetworkGraph = nativeNetworkGraphImport;
10
11 /// Represents the network as nodes and channels between them
12 #[must_use]
13 #[repr(C)]
14 pub struct NetworkGraph {
15         /// Nearly everywhere, inner must be non-null, however in places where
16         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
17         pub inner: *mut nativeNetworkGraph,
18         pub is_owned: bool,
19 }
20
21 impl Drop for NetworkGraph {
22         fn drop(&mut self) {
23                 if self.is_owned && !self.inner.is_null() {
24                         let _ = unsafe { Box::from_raw(self.inner) };
25                 }
26         }
27 }
28 #[no_mangle]
29 pub extern "C" fn NetworkGraph_free(this_ptr: NetworkGraph) { }
30 #[allow(unused)]
31 /// Used only if an object of this type is returned as a trait impl by a method
32 extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
33         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
34 }
35 #[allow(unused)]
36 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
37 impl NetworkGraph {
38         pub(crate) fn take_ptr(mut self) -> *mut nativeNetworkGraph {
39                 assert!(self.is_owned);
40                 let ret = self.inner;
41                 self.inner = std::ptr::null_mut();
42                 ret
43         }
44 }
45
46 use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport;
47 type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>;
48
49 /// A simple newtype for RwLockReadGuard<'a, NetworkGraph>.
50 /// This exists only to make accessing a RwLock<NetworkGraph> possible from
51 /// the C bindings, as it can be done directly in Rust code.
52 #[must_use]
53 #[repr(C)]
54 pub struct LockedNetworkGraph {
55         /// Nearly everywhere, inner must be non-null, however in places where
56         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
57         pub inner: *mut nativeLockedNetworkGraph,
58         pub is_owned: bool,
59 }
60
61 impl Drop for LockedNetworkGraph {
62         fn drop(&mut self) {
63                 if self.is_owned && !self.inner.is_null() {
64                         let _ = unsafe { Box::from_raw(self.inner) };
65                 }
66         }
67 }
68 #[no_mangle]
69 pub extern "C" fn LockedNetworkGraph_free(this_ptr: LockedNetworkGraph) { }
70 #[allow(unused)]
71 /// Used only if an object of this type is returned as a trait impl by a method
72 extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) {
73         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedNetworkGraph); }
74 }
75 #[allow(unused)]
76 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
77 impl LockedNetworkGraph {
78         pub(crate) fn take_ptr(mut self) -> *mut nativeLockedNetworkGraph {
79                 assert!(self.is_owned);
80                 let ret = self.inner;
81                 self.inner = std::ptr::null_mut();
82                 ret
83         }
84 }
85
86 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
87 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::chain::Access, crate::util::logger::Logger>;
88
89 /// Receives and validates network updates from peers,
90 /// stores authentic and relevant data as a network graph.
91 /// This network graph is then used for routing payments.
92 /// Provides interface to help with initial routing sync by
93 /// serving historical announcements.
94 #[must_use]
95 #[repr(C)]
96 pub struct NetGraphMsgHandler {
97         /// Nearly everywhere, inner must be non-null, however in places where
98         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
99         pub inner: *mut nativeNetGraphMsgHandler,
100         pub is_owned: bool,
101 }
102
103 impl Drop for NetGraphMsgHandler {
104         fn drop(&mut self) {
105                 if self.is_owned && !self.inner.is_null() {
106                         let _ = unsafe { Box::from_raw(self.inner) };
107                 }
108         }
109 }
110 #[no_mangle]
111 pub extern "C" fn NetGraphMsgHandler_free(this_ptr: NetGraphMsgHandler) { }
112 #[allow(unused)]
113 /// Used only if an object of this type is returned as a trait impl by a method
114 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
115         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
116 }
117 #[allow(unused)]
118 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
119 impl NetGraphMsgHandler {
120         pub(crate) fn take_ptr(mut self) -> *mut nativeNetGraphMsgHandler {
121                 assert!(self.is_owned);
122                 let ret = self.inner;
123                 self.inner = std::ptr::null_mut();
124                 ret
125         }
126 }
127 /// Creates a new tracker of the actual state of the network of channels and nodes,
128 /// assuming a fresh network graph.
129 /// Chain monitor is used to make sure announced channels exist on-chain,
130 /// channel data is correct, and that the announcement is signed with
131 /// channel owners' keys.
132 #[must_use]
133 #[no_mangle]
134 pub extern "C" fn NetGraphMsgHandler_new(chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler {
135         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
136         let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(local_chain_access, logger);
137         NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
138 }
139
140 /// Creates a new tracker of the actual state of the network of channels and nodes,
141 /// assuming an existing Network Graph.
142 #[must_use]
143 #[no_mangle]
144 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 {
145         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
146         let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_ptr()) });
147         NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
148 }
149
150 /// Take a read lock on the network_graph and return it in the C-bindings
151 /// newtype helper. This is likely only useful when called via the C
152 /// bindings as you can call `self.network_graph.read().unwrap()` in Rust
153 /// yourself.
154 #[must_use]
155 #[no_mangle]
156 pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::routing::network_graph::LockedNetworkGraph {
157         let mut ret = unsafe { &*this_arg.inner }.read_locked_graph();
158         crate::routing::network_graph::LockedNetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
159 }
160
161 /// Get a reference to the NetworkGraph which this read-lock contains.
162 #[must_use]
163 #[no_mangle]
164 pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::routing::network_graph::NetworkGraph {
165         let mut ret = unsafe { &*this_arg.inner }.graph();
166         crate::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
167 }
168
169 #[no_mangle]
170 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: *const NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler {
171         crate::ln::msgs::RoutingMessageHandler {
172                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
173                 free: None,
174                 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
175                 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
176                 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
177                 handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
178                 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
179                 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
180                 should_request_full_sync: NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync,
181         }
182 }
183 use lightning::ln::msgs::RoutingMessageHandler as RoutingMessageHandlerTraitImport;
184 #[must_use]
185 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
186         let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_node_announcement(unsafe { &*msg.inner });
187         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
188         local_ret
189 }
190 #[must_use]
191 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
192         let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_announcement(unsafe { &*msg.inner });
193         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
194         local_ret
195 }
196 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) {
197         unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_htlc_fail_channel_update(&update.to_native())
198 }
199 #[must_use]
200 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
201         let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_update(unsafe { &*msg.inner });
202         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
203         local_ret
204 }
205 #[must_use]
206 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 {
207         let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_next_channel_announcements(starting_point, batch_amount);
208         let mut local_ret = Vec::new(); for 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 }); };
209         local_ret.into()
210 }
211 #[must_use]
212 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 {
213         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();
214         let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_next_node_announcements(local_starting_point, batch_amount);
215         let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
216         local_ret.into()
217 }
218 #[must_use]
219 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync(this_arg: *const c_void, mut _node_id: crate::c_types::PublicKey) -> bool {
220         let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.should_request_full_sync(&_node_id.into_rust());
221         ret
222 }
223
224
225 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
226 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
227
228 /// Details about one direction of a channel. Received
229 /// within a channel update.
230 #[must_use]
231 #[repr(C)]
232 pub struct DirectionalChannelInfo {
233         /// Nearly everywhere, inner must be non-null, however in places where
234         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
235         pub inner: *mut nativeDirectionalChannelInfo,
236         pub is_owned: bool,
237 }
238
239 impl Drop for DirectionalChannelInfo {
240         fn drop(&mut self) {
241                 if self.is_owned && !self.inner.is_null() {
242                         let _ = unsafe { Box::from_raw(self.inner) };
243                 }
244         }
245 }
246 #[no_mangle]
247 pub extern "C" fn DirectionalChannelInfo_free(this_ptr: DirectionalChannelInfo) { }
248 #[allow(unused)]
249 /// Used only if an object of this type is returned as a trait impl by a method
250 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
251         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
252 }
253 #[allow(unused)]
254 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
255 impl DirectionalChannelInfo {
256         pub(crate) fn take_ptr(mut self) -> *mut nativeDirectionalChannelInfo {
257                 assert!(self.is_owned);
258                 let ret = self.inner;
259                 self.inner = std::ptr::null_mut();
260                 ret
261         }
262 }
263 /// When the last update to the channel direction was issued.
264 /// Value is opaque, as set in the announcement.
265 #[no_mangle]
266 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
267         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
268         (*inner_val)
269 }
270 /// When the last update to the channel direction was issued.
271 /// Value is opaque, as set in the announcement.
272 #[no_mangle]
273 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
274         unsafe { &mut *this_ptr.inner }.last_update = val;
275 }
276 /// Whether the channel can be currently used for payments (in this one direction).
277 #[no_mangle]
278 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
279         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.enabled;
280         (*inner_val)
281 }
282 /// Whether the channel can be currently used for payments (in this one direction).
283 #[no_mangle]
284 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
285         unsafe { &mut *this_ptr.inner }.enabled = val;
286 }
287 /// The difference in CLTV values that you must have when routing through this channel.
288 #[no_mangle]
289 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
290         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
291         (*inner_val)
292 }
293 /// The difference in CLTV values that you must have when routing through this channel.
294 #[no_mangle]
295 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
296         unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
297 }
298 /// The minimum value, which must be relayed to the next hop via the channel
299 #[no_mangle]
300 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
301         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
302         (*inner_val)
303 }
304 /// The minimum value, which must be relayed to the next hop via the channel
305 #[no_mangle]
306 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
307         unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val;
308 }
309 /// Most recent update for the channel received from the network
310 /// Mostly redundant with the data we store in fields explicitly.
311 /// Everything else is useful only for sending out for initial routing sync.
312 /// Not stored if contains excess data to prevent DoS.
313 #[no_mangle]
314 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::ln::msgs::ChannelUpdate {
315         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update_message;
316         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 };
317         local_inner_val
318 }
319 /// Most recent update for the channel received from the network
320 /// Mostly redundant with the data we store in fields explicitly.
321 /// Everything else is useful only for sending out for initial routing sync.
322 /// Not stored if contains excess data to prevent DoS.
323 #[no_mangle]
324 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::ln::msgs::ChannelUpdate) {
325         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
326         unsafe { &mut *this_ptr.inner }.last_update_message = local_val;
327 }
328 #[no_mangle]
329 pub extern "C" fn DirectionalChannelInfo_write(obj: *const DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
330         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
331 }
332 #[no_mangle]
333 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> DirectionalChannelInfo {
334         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
335                 DirectionalChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
336         } else {
337                 DirectionalChannelInfo { inner: std::ptr::null_mut(), is_owned: true }
338         }
339 }
340
341 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
342 type nativeChannelInfo = nativeChannelInfoImport;
343
344 /// Details about a channel (both directions).
345 /// Received within a channel announcement.
346 #[must_use]
347 #[repr(C)]
348 pub struct ChannelInfo {
349         /// Nearly everywhere, inner must be non-null, however in places where
350         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
351         pub inner: *mut nativeChannelInfo,
352         pub is_owned: bool,
353 }
354
355 impl Drop for ChannelInfo {
356         fn drop(&mut self) {
357                 if self.is_owned && !self.inner.is_null() {
358                         let _ = unsafe { Box::from_raw(self.inner) };
359                 }
360         }
361 }
362 #[no_mangle]
363 pub extern "C" fn ChannelInfo_free(this_ptr: ChannelInfo) { }
364 #[allow(unused)]
365 /// Used only if an object of this type is returned as a trait impl by a method
366 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
367         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
368 }
369 #[allow(unused)]
370 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
371 impl ChannelInfo {
372         pub(crate) fn take_ptr(mut self) -> *mut nativeChannelInfo {
373                 assert!(self.is_owned);
374                 let ret = self.inner;
375                 self.inner = std::ptr::null_mut();
376                 ret
377         }
378 }
379 /// Protocol features of a channel communicated during its announcement
380 #[no_mangle]
381 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::ln::features::ChannelFeatures {
382         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
383         crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
384 }
385 /// Protocol features of a channel communicated during its announcement
386 #[no_mangle]
387 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::ln::features::ChannelFeatures) {
388         unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_ptr()) };
389 }
390 /// Source node of the first direction of a channel
391 #[no_mangle]
392 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
393         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_one;
394         crate::c_types::PublicKey::from_rust(&(*inner_val))
395 }
396 /// Source node of the first direction of a channel
397 #[no_mangle]
398 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
399         unsafe { &mut *this_ptr.inner }.node_one = val.into_rust();
400 }
401 /// Details about the first direction of a channel
402 #[no_mangle]
403 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
404         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.one_to_two;
405         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 };
406         local_inner_val
407 }
408 /// Details about the first direction of a channel
409 #[no_mangle]
410 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
411         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
412         unsafe { &mut *this_ptr.inner }.one_to_two = local_val;
413 }
414 /// Source node of the second direction of a channel
415 #[no_mangle]
416 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
417         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_two;
418         crate::c_types::PublicKey::from_rust(&(*inner_val))
419 }
420 /// Source node of the second direction of a channel
421 #[no_mangle]
422 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
423         unsafe { &mut *this_ptr.inner }.node_two = val.into_rust();
424 }
425 /// Details about the second direction of a channel
426 #[no_mangle]
427 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
428         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.two_to_one;
429         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 };
430         local_inner_val
431 }
432 /// Details about the second direction of a channel
433 #[no_mangle]
434 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
435         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
436         unsafe { &mut *this_ptr.inner }.two_to_one = local_val;
437 }
438 /// An initial announcement of the channel
439 /// Mostly redundant with the data we store in fields explicitly.
440 /// Everything else is useful only for sending out for initial routing sync.
441 /// Not stored if contains excess data to prevent DoS.
442 #[no_mangle]
443 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::ln::msgs::ChannelAnnouncement {
444         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
445         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 };
446         local_inner_val
447 }
448 /// An initial announcement of the channel
449 /// Mostly redundant with the data we store in fields explicitly.
450 /// Everything else is useful only for sending out for initial routing sync.
451 /// Not stored if contains excess data to prevent DoS.
452 #[no_mangle]
453 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::ln::msgs::ChannelAnnouncement) {
454         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
455         unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
456 }
457 #[no_mangle]
458 pub extern "C" fn ChannelInfo_write(obj: *const ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
459         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
460 }
461 #[no_mangle]
462 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> ChannelInfo {
463         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
464                 ChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
465         } else {
466                 ChannelInfo { inner: std::ptr::null_mut(), is_owned: true }
467         }
468 }
469
470 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
471 type nativeRoutingFees = nativeRoutingFeesImport;
472
473 /// Fees for routing via a given channel or a node
474 #[must_use]
475 #[repr(C)]
476 pub struct RoutingFees {
477         /// Nearly everywhere, inner must be non-null, however in places where
478         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
479         pub inner: *mut nativeRoutingFees,
480         pub is_owned: bool,
481 }
482
483 impl Drop for RoutingFees {
484         fn drop(&mut self) {
485                 if self.is_owned && !self.inner.is_null() {
486                         let _ = unsafe { Box::from_raw(self.inner) };
487                 }
488         }
489 }
490 #[no_mangle]
491 pub extern "C" fn RoutingFees_free(this_ptr: RoutingFees) { }
492 #[allow(unused)]
493 /// Used only if an object of this type is returned as a trait impl by a method
494 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
495         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
496 }
497 #[allow(unused)]
498 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
499 impl RoutingFees {
500         pub(crate) fn take_ptr(mut self) -> *mut nativeRoutingFees {
501                 assert!(self.is_owned);
502                 let ret = self.inner;
503                 self.inner = std::ptr::null_mut();
504                 ret
505         }
506 }
507 impl Clone for RoutingFees {
508         fn clone(&self) -> Self {
509                 Self {
510                         inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
511                         is_owned: true,
512                 }
513         }
514 }
515 #[allow(unused)]
516 /// Used only if an object of this type is returned as a trait impl by a method
517 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
518         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
519 }
520 #[no_mangle]
521 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
522         RoutingFees { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
523 }
524 /// Flat routing fee in satoshis
525 #[no_mangle]
526 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
527         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat;
528         (*inner_val)
529 }
530 /// Flat routing fee in satoshis
531 #[no_mangle]
532 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
533         unsafe { &mut *this_ptr.inner }.base_msat = val;
534 }
535 /// Liquidity-based routing fee in millionths of a routed amount.
536 /// In other words, 10000 is 1%.
537 #[no_mangle]
538 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
539         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths;
540         (*inner_val)
541 }
542 /// Liquidity-based routing fee in millionths of a routed amount.
543 /// In other words, 10000 is 1%.
544 #[no_mangle]
545 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
546         unsafe { &mut *this_ptr.inner }.proportional_millionths = val;
547 }
548 #[must_use]
549 #[no_mangle]
550 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
551         RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees {
552                 base_msat: base_msat_arg,
553                 proportional_millionths: proportional_millionths_arg,
554         })), is_owned: true }
555 }
556 #[no_mangle]
557 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> RoutingFees {
558         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
559                 RoutingFees { inner: Box::into_raw(Box::new(res)), is_owned: true }
560         } else {
561                 RoutingFees { inner: std::ptr::null_mut(), is_owned: true }
562         }
563 }
564 #[no_mangle]
565 pub extern "C" fn RoutingFees_write(obj: *const RoutingFees) -> crate::c_types::derived::CVec_u8Z {
566         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
567 }
568
569 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
570 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
571
572 /// Information received in the latest node_announcement from this node.
573 #[must_use]
574 #[repr(C)]
575 pub struct NodeAnnouncementInfo {
576         /// Nearly everywhere, inner must be non-null, however in places where
577         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
578         pub inner: *mut nativeNodeAnnouncementInfo,
579         pub is_owned: bool,
580 }
581
582 impl Drop for NodeAnnouncementInfo {
583         fn drop(&mut self) {
584                 if self.is_owned && !self.inner.is_null() {
585                         let _ = unsafe { Box::from_raw(self.inner) };
586                 }
587         }
588 }
589 #[no_mangle]
590 pub extern "C" fn NodeAnnouncementInfo_free(this_ptr: NodeAnnouncementInfo) { }
591 #[allow(unused)]
592 /// Used only if an object of this type is returned as a trait impl by a method
593 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
594         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
595 }
596 #[allow(unused)]
597 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
598 impl NodeAnnouncementInfo {
599         pub(crate) fn take_ptr(mut self) -> *mut nativeNodeAnnouncementInfo {
600                 assert!(self.is_owned);
601                 let ret = self.inner;
602                 self.inner = std::ptr::null_mut();
603                 ret
604         }
605 }
606 /// Protocol features the node announced support for
607 #[no_mangle]
608 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures {
609         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
610         crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
611 }
612 /// Protocol features the node announced support for
613 #[no_mangle]
614 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::features::NodeFeatures) {
615         unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_ptr()) };
616 }
617 /// When the last known update to the node state was issued.
618 /// Value is opaque, as set in the announcement.
619 #[no_mangle]
620 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
621         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
622         (*inner_val)
623 }
624 /// When the last known update to the node state was issued.
625 /// Value is opaque, as set in the announcement.
626 #[no_mangle]
627 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
628         unsafe { &mut *this_ptr.inner }.last_update = val;
629 }
630 /// Color assigned to the node
631 #[no_mangle]
632 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
633         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
634         &(*inner_val)
635 }
636 /// Color assigned to the node
637 #[no_mangle]
638 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
639         unsafe { &mut *this_ptr.inner }.rgb = val.data;
640 }
641 /// Moniker assigned to the node.
642 /// May be invalid or malicious (eg control chars),
643 /// should not be exposed to the user.
644 #[no_mangle]
645 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
646         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
647         &(*inner_val)
648 }
649 /// Moniker assigned to the node.
650 /// May be invalid or malicious (eg control chars),
651 /// should not be exposed to the user.
652 #[no_mangle]
653 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
654         unsafe { &mut *this_ptr.inner }.alias = val.data;
655 }
656 /// Internet-level addresses via which one can connect to the node
657 #[no_mangle]
658 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
659         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
660         unsafe { &mut *this_ptr.inner }.addresses = local_val;
661 }
662 /// An initial announcement of the node
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 NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::ln::msgs::NodeAnnouncement {
668         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
669         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 };
670         local_inner_val
671 }
672 /// An initial announcement of the node
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 NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::msgs::NodeAnnouncement) {
678         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
679         unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
680 }
681 #[must_use]
682 #[no_mangle]
683 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 {
684         let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
685         let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_ptr()) } }) };
686         NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo {
687                 features: *unsafe { Box::from_raw(features_arg.take_ptr()) },
688                 last_update: last_update_arg,
689                 rgb: rgb_arg.data,
690                 alias: alias_arg.data,
691                 addresses: local_addresses_arg,
692                 announcement_message: local_announcement_message_arg,
693         })), is_owned: true }
694 }
695 #[no_mangle]
696 pub extern "C" fn NodeAnnouncementInfo_write(obj: *const NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
697         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
698 }
699 #[no_mangle]
700 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> NodeAnnouncementInfo {
701         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
702                 NodeAnnouncementInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
703         } else {
704                 NodeAnnouncementInfo { inner: std::ptr::null_mut(), is_owned: true }
705         }
706 }
707
708 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
709 type nativeNodeInfo = nativeNodeInfoImport;
710
711 /// Details about a node in the network, known from the network announcement.
712 #[must_use]
713 #[repr(C)]
714 pub struct NodeInfo {
715         /// Nearly everywhere, inner must be non-null, however in places where
716         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
717         pub inner: *mut nativeNodeInfo,
718         pub is_owned: bool,
719 }
720
721 impl Drop for NodeInfo {
722         fn drop(&mut self) {
723                 if self.is_owned && !self.inner.is_null() {
724                         let _ = unsafe { Box::from_raw(self.inner) };
725                 }
726         }
727 }
728 #[no_mangle]
729 pub extern "C" fn NodeInfo_free(this_ptr: NodeInfo) { }
730 #[allow(unused)]
731 /// Used only if an object of this type is returned as a trait impl by a method
732 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
733         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
734 }
735 #[allow(unused)]
736 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
737 impl NodeInfo {
738         pub(crate) fn take_ptr(mut self) -> *mut nativeNodeInfo {
739                 assert!(self.is_owned);
740                 let ret = self.inner;
741                 self.inner = std::ptr::null_mut();
742                 ret
743         }
744 }
745 /// All valid channels a node has announced
746 #[no_mangle]
747 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
748         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
749         unsafe { &mut *this_ptr.inner }.channels = local_val;
750 }
751 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
752 /// The two fields (flat and proportional fee) are independent,
753 /// meaning they don't have to refer to the same channel.
754 #[no_mangle]
755 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::routing::network_graph::RoutingFees {
756         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
757         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 };
758         local_inner_val
759 }
760 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
761 /// The two fields (flat and proportional fee) are independent,
762 /// meaning they don't have to refer to the same channel.
763 #[no_mangle]
764 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::RoutingFees) {
765         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
766         unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val;
767 }
768 /// More information about a node from node_announcement.
769 /// Optional because we store a Node entry after learning about it from
770 /// a channel announcement, but before receiving a node announcement.
771 #[no_mangle]
772 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::routing::network_graph::NodeAnnouncementInfo {
773         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
774         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 };
775         local_inner_val
776 }
777 /// More information about a node from node_announcement.
778 /// Optional because we store a Node entry after learning about it from
779 /// a channel announcement, but before receiving a node announcement.
780 #[no_mangle]
781 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::NodeAnnouncementInfo) {
782         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
783         unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
784 }
785 #[must_use]
786 #[no_mangle]
787 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 {
788         let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
789         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_ptr()) } }) };
790         let mut local_announcement_info_arg = if announcement_info_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_info_arg.take_ptr()) } }) };
791         NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
792                 channels: local_channels_arg,
793                 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
794                 announcement_info: local_announcement_info_arg,
795         })), is_owned: true }
796 }
797 #[no_mangle]
798 pub extern "C" fn NodeInfo_write(obj: *const NodeInfo) -> crate::c_types::derived::CVec_u8Z {
799         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
800 }
801 #[no_mangle]
802 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> NodeInfo {
803         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
804                 NodeInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
805         } else {
806                 NodeInfo { inner: std::ptr::null_mut(), is_owned: true }
807         }
808 }
809 #[no_mangle]
810 pub extern "C" fn NetworkGraph_write(obj: *const NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
811         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
812 }
813 #[no_mangle]
814 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> NetworkGraph {
815         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
816                 NetworkGraph { inner: Box::into_raw(Box::new(res)), is_owned: true }
817         } else {
818                 NetworkGraph { inner: std::ptr::null_mut(), is_owned: true }
819         }
820 }
821 /// Creates a new, empty, network graph.
822 #[must_use]
823 #[no_mangle]
824 pub extern "C" fn NetworkGraph_new() -> crate::routing::network_graph::NetworkGraph {
825         let mut ret = lightning::routing::network_graph::NetworkGraph::new();
826         crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
827 }
828
829 /// Close a channel if a corresponding HTLC fail was sent.
830 /// If permanent, removes a channel from the local storage.
831 /// May cause the removal of nodes too, if this was their last channel.
832 /// If not permanent, makes channels unavailable for routing.
833 #[no_mangle]
834 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
835         unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)
836 }
837