Update C/C++ demos to latest upstream API
[ldk-c-bindings] / lightning-c-bindings / src / lightning / 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 alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
18
19
20 use lightning::routing::network_graph::NodeId as nativeNodeIdImport;
21 pub(crate) type nativeNodeId = nativeNodeIdImport;
22
23 /// Represents the compressed public key of a node
24 #[must_use]
25 #[repr(C)]
26 pub struct NodeId {
27         /// A pointer to the opaque Rust object.
28
29         /// Nearly everywhere, inner must be non-null, however in places where
30         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
31         pub inner: *mut nativeNodeId,
32         /// Indicates that this is the only struct which contains the same pointer.
33
34         /// Rust functions which take ownership of an object provided via an argument require
35         /// this to be true and invalidate the object pointed to by inner.
36         pub is_owned: bool,
37 }
38
39 impl Drop for NodeId {
40         fn drop(&mut self) {
41                 if self.is_owned && !<*mut nativeNodeId>::is_null(self.inner) {
42                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
43                 }
44         }
45 }
46 /// Frees any resources used by the NodeId, if is_owned is set and inner is non-NULL.
47 #[no_mangle]
48 pub extern "C" fn NodeId_free(this_obj: NodeId) { }
49 #[allow(unused)]
50 /// Used only if an object of this type is returned as a trait impl by a method
51 pub(crate) extern "C" fn NodeId_free_void(this_ptr: *mut c_void) {
52         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeId); }
53 }
54 #[allow(unused)]
55 impl NodeId {
56         pub(crate) fn get_native_ref(&self) -> &'static nativeNodeId {
57                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
58         }
59         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeId {
60                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
61         }
62         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
63         pub(crate) fn take_inner(mut self) -> *mut nativeNodeId {
64                 assert!(self.is_owned);
65                 let ret = ObjOps::untweak_ptr(self.inner);
66                 self.inner = core::ptr::null_mut();
67                 ret
68         }
69 }
70 impl Clone for NodeId {
71         fn clone(&self) -> Self {
72                 Self {
73                         inner: if <*mut nativeNodeId>::is_null(self.inner) { core::ptr::null_mut() } else {
74                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
75                         is_owned: true,
76                 }
77         }
78 }
79 #[allow(unused)]
80 /// Used only if an object of this type is returned as a trait impl by a method
81 pub(crate) extern "C" fn NodeId_clone_void(this_ptr: *const c_void) -> *mut c_void {
82         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeId)).clone() })) as *mut c_void
83 }
84 #[no_mangle]
85 /// Creates a copy of the NodeId
86 pub extern "C" fn NodeId_clone(orig: &NodeId) -> NodeId {
87         orig.clone()
88 }
89 /// Create a new NodeId from a public key
90 #[must_use]
91 #[no_mangle]
92 pub extern "C" fn NodeId_from_pubkey(mut pubkey: crate::c_types::PublicKey) -> crate::lightning::routing::network_graph::NodeId {
93         let mut ret = lightning::routing::network_graph::NodeId::from_pubkey(&pubkey.into_rust());
94         crate::lightning::routing::network_graph::NodeId { inner: ObjOps::heap_alloc(ret), is_owned: true }
95 }
96
97 /// Get the public key slice from this NodeId
98 #[must_use]
99 #[no_mangle]
100 pub extern "C" fn NodeId_as_slice(this_arg: &crate::lightning::routing::network_graph::NodeId) -> crate::c_types::u8slice {
101         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_slice();
102         let mut local_ret = crate::c_types::u8slice::from_slice(ret);
103         local_ret
104 }
105
106 /// Checks if two NodeIds contain equal inner contents.
107 #[no_mangle]
108 pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 {
109         if o.inner.is_null() { return 0; }
110         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
111         #[allow(deprecated)]
112         let mut hasher = core::hash::SipHasher::new();
113         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
114         core::hash::Hasher::finish(&hasher)
115 }
116 #[no_mangle]
117 /// Serialize the NodeId object into a byte array which can be read by NodeId_read
118 pub extern "C" fn NodeId_write(obj: &crate::lightning::routing::network_graph::NodeId) -> crate::c_types::derived::CVec_u8Z {
119         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
120 }
121 #[no_mangle]
122 pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
123         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) })
124 }
125 #[no_mangle]
126 /// Read a NodeId from a byte array, created by NodeId_write
127 pub extern "C" fn NodeId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ {
128         let res: Result<lightning::routing::network_graph::NodeId, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
129         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
130         local_res
131 }
132
133 use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport;
134 pub(crate) type nativeNetworkGraph = nativeNetworkGraphImport;
135
136 /// Represents the network as nodes and channels between them
137 #[must_use]
138 #[repr(C)]
139 pub struct NetworkGraph {
140         /// A pointer to the opaque Rust object.
141
142         /// Nearly everywhere, inner must be non-null, however in places where
143         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
144         pub inner: *mut nativeNetworkGraph,
145         /// Indicates that this is the only struct which contains the same pointer.
146
147         /// Rust functions which take ownership of an object provided via an argument require
148         /// this to be true and invalidate the object pointed to by inner.
149         pub is_owned: bool,
150 }
151
152 impl Drop for NetworkGraph {
153         fn drop(&mut self) {
154                 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
155                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
156                 }
157         }
158 }
159 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
160 #[no_mangle]
161 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
162 #[allow(unused)]
163 /// Used only if an object of this type is returned as a trait impl by a method
164 pub(crate) extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
165         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
166 }
167 #[allow(unused)]
168 impl NetworkGraph {
169         pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
170                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
171         }
172         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
173                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
174         }
175         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
176         pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
177                 assert!(self.is_owned);
178                 let ret = ObjOps::untweak_ptr(self.inner);
179                 self.inner = core::ptr::null_mut();
180                 ret
181         }
182 }
183 impl Clone for NetworkGraph {
184         fn clone(&self) -> Self {
185                 Self {
186                         inner: if <*mut nativeNetworkGraph>::is_null(self.inner) { core::ptr::null_mut() } else {
187                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
188                         is_owned: true,
189                 }
190         }
191 }
192 #[allow(unused)]
193 /// Used only if an object of this type is returned as a trait impl by a method
194 pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void {
195         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void
196 }
197 #[no_mangle]
198 /// Creates a copy of the NetworkGraph
199 pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph {
200         orig.clone()
201 }
202
203 use lightning::routing::network_graph::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
204 pub(crate) type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
205
206 /// A read-only view of [`NetworkGraph`].
207 #[must_use]
208 #[repr(C)]
209 pub struct ReadOnlyNetworkGraph {
210         /// A pointer to the opaque Rust object.
211
212         /// Nearly everywhere, inner must be non-null, however in places where
213         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
214         pub inner: *mut nativeReadOnlyNetworkGraph,
215         /// Indicates that this is the only struct which contains the same pointer.
216
217         /// Rust functions which take ownership of an object provided via an argument require
218         /// this to be true and invalidate the object pointed to by inner.
219         pub is_owned: bool,
220 }
221
222 impl Drop for ReadOnlyNetworkGraph {
223         fn drop(&mut self) {
224                 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
225                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
226                 }
227         }
228 }
229 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
230 #[no_mangle]
231 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
232 #[allow(unused)]
233 /// Used only if an object of this type is returned as a trait impl by a method
234 pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
235         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph); }
236 }
237 #[allow(unused)]
238 impl ReadOnlyNetworkGraph {
239         pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
240                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
241         }
242         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
243                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
244         }
245         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
246         pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
247                 assert!(self.is_owned);
248                 let ret = ObjOps::untweak_ptr(self.inner);
249                 self.inner = core::ptr::null_mut();
250                 ret
251         }
252 }
253 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
254 /// return packet by a node along the route. See [BOLT #4] for details.
255 ///
256 /// [BOLT #4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
257 #[must_use]
258 #[derive(Clone)]
259 #[repr(C)]
260 pub enum NetworkUpdate {
261         /// An error indicating a `channel_update` messages should be applied via
262         /// [`NetworkGraph::update_channel`].
263         ChannelUpdateMessage {
264                 /// The update to apply via [`NetworkGraph::update_channel`].
265                 msg: crate::lightning::ln::msgs::ChannelUpdate,
266         },
267         /// An error indicating only that a channel has been closed, which should be applied via
268         /// [`NetworkGraph::close_channel_from_update`].
269         ChannelClosed {
270                 /// The short channel id of the closed channel.
271                 short_channel_id: u64,
272                 /// Whether the channel should be permanently removed or temporarily disabled until a new
273                 /// `channel_update` message is received.
274                 is_permanent: bool,
275         },
276         /// An error indicating only that a node has failed, which should be applied via
277         /// [`NetworkGraph::fail_node`].
278         NodeFailure {
279                 /// The node id of the failed node.
280                 node_id: crate::c_types::PublicKey,
281                 /// Whether the node should be permanently removed from consideration or can be restored
282                 /// when a new `channel_update` message is received.
283                 is_permanent: bool,
284         },
285 }
286 use lightning::routing::network_graph::NetworkUpdate as nativeNetworkUpdate;
287 impl NetworkUpdate {
288         #[allow(unused)]
289         pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
290                 match self {
291                         NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
292                                 let mut msg_nonref = (*msg).clone();
293                                 nativeNetworkUpdate::ChannelUpdateMessage {
294                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
295                                 }
296                         },
297                         NetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
298                                 let mut short_channel_id_nonref = (*short_channel_id).clone();
299                                 let mut is_permanent_nonref = (*is_permanent).clone();
300                                 nativeNetworkUpdate::ChannelClosed {
301                                         short_channel_id: short_channel_id_nonref,
302                                         is_permanent: is_permanent_nonref,
303                                 }
304                         },
305                         NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
306                                 let mut node_id_nonref = (*node_id).clone();
307                                 let mut is_permanent_nonref = (*is_permanent).clone();
308                                 nativeNetworkUpdate::NodeFailure {
309                                         node_id: node_id_nonref.into_rust(),
310                                         is_permanent: is_permanent_nonref,
311                                 }
312                         },
313                 }
314         }
315         #[allow(unused)]
316         pub(crate) fn into_native(self) -> nativeNetworkUpdate {
317                 match self {
318                         NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
319                                 nativeNetworkUpdate::ChannelUpdateMessage {
320                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
321                                 }
322                         },
323                         NetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
324                                 nativeNetworkUpdate::ChannelClosed {
325                                         short_channel_id: short_channel_id,
326                                         is_permanent: is_permanent,
327                                 }
328                         },
329                         NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
330                                 nativeNetworkUpdate::NodeFailure {
331                                         node_id: node_id.into_rust(),
332                                         is_permanent: is_permanent,
333                                 }
334                         },
335                 }
336         }
337         #[allow(unused)]
338         pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
339                 match native {
340                         nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
341                                 let mut msg_nonref = (*msg).clone();
342                                 NetworkUpdate::ChannelUpdateMessage {
343                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
344                                 }
345                         },
346                         nativeNetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
347                                 let mut short_channel_id_nonref = (*short_channel_id).clone();
348                                 let mut is_permanent_nonref = (*is_permanent).clone();
349                                 NetworkUpdate::ChannelClosed {
350                                         short_channel_id: short_channel_id_nonref,
351                                         is_permanent: is_permanent_nonref,
352                                 }
353                         },
354                         nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
355                                 let mut node_id_nonref = (*node_id).clone();
356                                 let mut is_permanent_nonref = (*is_permanent).clone();
357                                 NetworkUpdate::NodeFailure {
358                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
359                                         is_permanent: is_permanent_nonref,
360                                 }
361                         },
362                 }
363         }
364         #[allow(unused)]
365         pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
366                 match native {
367                         nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
368                                 NetworkUpdate::ChannelUpdateMessage {
369                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
370                                 }
371                         },
372                         nativeNetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
373                                 NetworkUpdate::ChannelClosed {
374                                         short_channel_id: short_channel_id,
375                                         is_permanent: is_permanent,
376                                 }
377                         },
378                         nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
379                                 NetworkUpdate::NodeFailure {
380                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
381                                         is_permanent: is_permanent,
382                                 }
383                         },
384                 }
385         }
386 }
387 /// Frees any resources used by the NetworkUpdate
388 #[no_mangle]
389 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
390 /// Creates a copy of the NetworkUpdate
391 #[no_mangle]
392 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
393         orig.clone()
394 }
395 #[no_mangle]
396 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
397 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
398         NetworkUpdate::ChannelUpdateMessage {
399                 msg,
400         }
401 }
402 #[no_mangle]
403 /// Utility method to constructs a new ChannelClosed-variant NetworkUpdate
404 pub extern "C" fn NetworkUpdate_channel_closed(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
405         NetworkUpdate::ChannelClosed {
406                 short_channel_id,
407                 is_permanent,
408         }
409 }
410 #[no_mangle]
411 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
412 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
413         NetworkUpdate::NodeFailure {
414                 node_id,
415                 is_permanent,
416         }
417 }
418 #[no_mangle]
419 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
420 pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::network_graph::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
421         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
422 }
423 #[no_mangle]
424 /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
425 pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ {
426         let res: Result<Option<lightning::routing::network_graph::NetworkUpdate>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
427         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::network_graph::NetworkUpdate::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
428         local_res
429 }
430 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::EventHandler {
431         fn from(obj: nativeNetGraphMsgHandler) -> Self {
432                 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
433                 let mut ret = NetGraphMsgHandler_as_EventHandler(&rust_obj);
434                 // 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
435                 rust_obj.inner = core::ptr::null_mut();
436                 ret.free = Some(NetGraphMsgHandler_free_void);
437                 ret
438         }
439 }
440 /// Constructs a new EventHandler which calls the relevant methods on this_arg.
441 /// This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
442 #[no_mangle]
443 pub extern "C" fn NetGraphMsgHandler_as_EventHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::EventHandler {
444         crate::lightning::util::events::EventHandler {
445                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
446                 free: None,
447                 handle_event: NetGraphMsgHandler_EventHandler_handle_event,
448         }
449 }
450
451 extern "C" fn NetGraphMsgHandler_EventHandler_handle_event(this_arg: *const c_void, event: &crate::lightning::util::events::Event) {
452         <nativeNetGraphMsgHandler as lightning::util::events::EventHandler<>>::handle_event(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &event.to_native())
453 }
454
455
456 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
457 pub(crate) type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<&'static lightning::routing::network_graph::NetworkGraph, crate::lightning::chain::Access, crate::lightning::util::logger::Logger>;
458
459 /// Receives and validates network updates from peers,
460 /// stores authentic and relevant data as a network graph.
461 /// This network graph is then used for routing payments.
462 /// Provides interface to help with initial routing sync by
463 /// serving historical announcements.
464 ///
465 /// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
466 /// [`NetworkGraph`].
467 #[must_use]
468 #[repr(C)]
469 pub struct NetGraphMsgHandler {
470         /// A pointer to the opaque Rust object.
471
472         /// Nearly everywhere, inner must be non-null, however in places where
473         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
474         pub inner: *mut nativeNetGraphMsgHandler,
475         /// Indicates that this is the only struct which contains the same pointer.
476
477         /// Rust functions which take ownership of an object provided via an argument require
478         /// this to be true and invalidate the object pointed to by inner.
479         pub is_owned: bool,
480 }
481
482 impl Drop for NetGraphMsgHandler {
483         fn drop(&mut self) {
484                 if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) {
485                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
486                 }
487         }
488 }
489 /// Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL.
490 #[no_mangle]
491 pub extern "C" fn NetGraphMsgHandler_free(this_obj: NetGraphMsgHandler) { }
492 #[allow(unused)]
493 /// Used only if an object of this type is returned as a trait impl by a method
494 pub(crate) extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
495         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
496 }
497 #[allow(unused)]
498 impl NetGraphMsgHandler {
499         pub(crate) fn get_native_ref(&self) -> &'static nativeNetGraphMsgHandler {
500                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
501         }
502         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetGraphMsgHandler {
503                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
504         }
505         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
506         pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
507                 assert!(self.is_owned);
508                 let ret = ObjOps::untweak_ptr(self.inner);
509                 self.inner = core::ptr::null_mut();
510                 ret
511         }
512 }
513 /// Creates a new tracker of the actual state of the network of channels and nodes,
514 /// assuming an existing Network Graph.
515 /// Chain monitor is used to make sure announced channels exist on-chain,
516 /// channel data is correct, and that the announcement is signed with
517 /// channel owners' keys.
518 #[must_use]
519 #[no_mangle]
520 pub extern "C" fn NetGraphMsgHandler_new(network_graph: &crate::lightning::routing::network_graph::NetworkGraph, mut chain_access: crate::c_types::derived::COption_AccessZ, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::network_graph::NetGraphMsgHandler {
521         let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
522         let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(network_graph.get_native_ref(), local_chain_access, logger);
523         crate::lightning::routing::network_graph::NetGraphMsgHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
524 }
525
526 /// Adds a provider used to check new announcements. Does not affect
527 /// existing announcements unless they are updated.
528 /// Add, update or remove the provider would replace the current one.
529 #[no_mangle]
530 pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut crate::lightning::routing::network_graph::NetGraphMsgHandler, mut chain_access: crate::c_types::derived::COption_AccessZ) {
531         let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
532         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::network_graph::nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access)
533 }
534
535 impl From<nativeNetGraphMsgHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
536         fn from(obj: nativeNetGraphMsgHandler) -> Self {
537                 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
538                 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
539                 // 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
540                 rust_obj.inner = core::ptr::null_mut();
541                 ret.free = Some(NetGraphMsgHandler_free_void);
542                 ret
543         }
544 }
545 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
546 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
547 #[no_mangle]
548 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
549         crate::lightning::ln::msgs::RoutingMessageHandler {
550                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
551                 free: None,
552                 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
553                 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
554                 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
555                 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
556                 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
557                 peer_connected: NetGraphMsgHandler_RoutingMessageHandler_peer_connected,
558                 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
559                 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
560                 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
561                 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
562                 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
563                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
564                         free: None,
565                         get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
566                 },
567         }
568 }
569
570 #[must_use]
571 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
572         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
573         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
574         local_ret
575 }
576 #[must_use]
577 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
578         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
579         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
580         local_ret
581 }
582 #[must_use]
583 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
584         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
585         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
586         local_ret
587 }
588 #[must_use]
589 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 {
590         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount);
591         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_1 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((orig_ret_0_1.unwrap())) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(orig_ret_0_0), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); };
592         local_ret.into()
593 }
594 #[must_use]
595 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 {
596         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();
597         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);
598         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
599         local_ret.into()
600 }
601 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init_msg: &crate::lightning::ln::msgs::Init) {
602         <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), init_msg.get_native_ref())
603 }
604 #[must_use]
605 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::lightning::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
606         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()) });
607         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
608         local_ret
609 }
610 #[must_use]
611 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::lightning::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
612         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()) });
613         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
614         local_ret
615 }
616 #[must_use]
617 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
618         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()) });
619         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
620         local_ret
621 }
622 #[must_use]
623 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
624         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()) });
625         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
626         local_ret
627 }
628
629 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::MessageSendEventsProvider {
630         fn from(obj: nativeNetGraphMsgHandler) -> Self {
631                 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
632                 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
633                 // 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
634                 rust_obj.inner = core::ptr::null_mut();
635                 ret.free = Some(NetGraphMsgHandler_free_void);
636                 ret
637         }
638 }
639 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
640 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
641 #[no_mangle]
642 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
643         crate::lightning::util::events::MessageSendEventsProvider {
644                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
645                 free: None,
646                 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
647         }
648 }
649
650 #[must_use]
651 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
652         let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
653         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
654         local_ret.into()
655 }
656
657
658 use lightning::routing::network_graph::ChannelUpdateInfo as nativeChannelUpdateInfoImport;
659 pub(crate) type nativeChannelUpdateInfo = nativeChannelUpdateInfoImport;
660
661 /// Details about one direction of a channel as received within a [`ChannelUpdate`].
662 #[must_use]
663 #[repr(C)]
664 pub struct ChannelUpdateInfo {
665         /// A pointer to the opaque Rust object.
666
667         /// Nearly everywhere, inner must be non-null, however in places where
668         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
669         pub inner: *mut nativeChannelUpdateInfo,
670         /// Indicates that this is the only struct which contains the same pointer.
671
672         /// Rust functions which take ownership of an object provided via an argument require
673         /// this to be true and invalidate the object pointed to by inner.
674         pub is_owned: bool,
675 }
676
677 impl Drop for ChannelUpdateInfo {
678         fn drop(&mut self) {
679                 if self.is_owned && !<*mut nativeChannelUpdateInfo>::is_null(self.inner) {
680                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
681                 }
682         }
683 }
684 /// Frees any resources used by the ChannelUpdateInfo, if is_owned is set and inner is non-NULL.
685 #[no_mangle]
686 pub extern "C" fn ChannelUpdateInfo_free(this_obj: ChannelUpdateInfo) { }
687 #[allow(unused)]
688 /// Used only if an object of this type is returned as a trait impl by a method
689 pub(crate) extern "C" fn ChannelUpdateInfo_free_void(this_ptr: *mut c_void) {
690         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo); }
691 }
692 #[allow(unused)]
693 impl ChannelUpdateInfo {
694         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUpdateInfo {
695                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
696         }
697         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUpdateInfo {
698                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
699         }
700         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
701         pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdateInfo {
702                 assert!(self.is_owned);
703                 let ret = ObjOps::untweak_ptr(self.inner);
704                 self.inner = core::ptr::null_mut();
705                 ret
706         }
707 }
708 /// When the last update to the channel direction was issued.
709 /// Value is opaque, as set in the announcement.
710 #[no_mangle]
711 pub extern "C" fn ChannelUpdateInfo_get_last_update(this_ptr: &ChannelUpdateInfo) -> u32 {
712         let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
713         *inner_val
714 }
715 /// When the last update to the channel direction was issued.
716 /// Value is opaque, as set in the announcement.
717 #[no_mangle]
718 pub extern "C" fn ChannelUpdateInfo_set_last_update(this_ptr: &mut ChannelUpdateInfo, mut val: u32) {
719         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
720 }
721 /// Whether the channel can be currently used for payments (in this one direction).
722 #[no_mangle]
723 pub extern "C" fn ChannelUpdateInfo_get_enabled(this_ptr: &ChannelUpdateInfo) -> bool {
724         let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
725         *inner_val
726 }
727 /// Whether the channel can be currently used for payments (in this one direction).
728 #[no_mangle]
729 pub extern "C" fn ChannelUpdateInfo_set_enabled(this_ptr: &mut ChannelUpdateInfo, mut val: bool) {
730         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
731 }
732 /// The difference in CLTV values that you must have when routing through this channel.
733 #[no_mangle]
734 pub extern "C" fn ChannelUpdateInfo_get_cltv_expiry_delta(this_ptr: &ChannelUpdateInfo) -> u16 {
735         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
736         *inner_val
737 }
738 /// The difference in CLTV values that you must have when routing through this channel.
739 #[no_mangle]
740 pub extern "C" fn ChannelUpdateInfo_set_cltv_expiry_delta(this_ptr: &mut ChannelUpdateInfo, mut val: u16) {
741         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
742 }
743 /// The minimum value, which must be relayed to the next hop via the channel
744 #[no_mangle]
745 pub extern "C" fn ChannelUpdateInfo_get_htlc_minimum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
746         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
747         *inner_val
748 }
749 /// The minimum value, which must be relayed to the next hop via the channel
750 #[no_mangle]
751 pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
752         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
753 }
754 /// The maximum value which may be relayed to the next hop via the channel.
755 #[no_mangle]
756 pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> crate::c_types::derived::COption_u64Z {
757         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
758         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() }) };
759         local_inner_val
760 }
761 /// The maximum value which may be relayed to the next hop via the channel.
762 #[no_mangle]
763 pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: crate::c_types::derived::COption_u64Z) {
764         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
765         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
766 }
767 /// Fees charged when the channel is used for routing
768 #[no_mangle]
769 pub extern "C" fn ChannelUpdateInfo_get_fees(this_ptr: &ChannelUpdateInfo) -> crate::lightning::routing::network_graph::RoutingFees {
770         let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
771         crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::network_graph::RoutingFees<>) as *mut _) }, is_owned: false }
772 }
773 /// Fees charged when the channel is used for routing
774 #[no_mangle]
775 pub extern "C" fn ChannelUpdateInfo_set_fees(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
776         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
777 }
778 /// Most recent update for the channel received from the network
779 /// Mostly redundant with the data we store in fields explicitly.
780 /// Everything else is useful only for sending out for initial routing sync.
781 /// Not stored if contains excess data to prevent DoS.
782 ///
783 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
784 #[no_mangle]
785 pub extern "C" fn ChannelUpdateInfo_get_last_update_message(this_ptr: &ChannelUpdateInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
786         let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
787         let mut local_inner_val = crate::lightning::ln::msgs::ChannelUpdate { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::msgs::ChannelUpdate<>) as *mut _ }, is_owned: false };
788         local_inner_val
789 }
790 /// Most recent update for the channel received from the network
791 /// Mostly redundant with the data we store in fields explicitly.
792 /// Everything else is useful only for sending out for initial routing sync.
793 /// Not stored if contains excess data to prevent DoS.
794 ///
795 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
796 #[no_mangle]
797 pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
798         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
799         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
800 }
801 /// Constructs a new ChannelUpdateInfo given each field
802 #[must_use]
803 #[no_mangle]
804 pub extern "C" fn ChannelUpdateInfo_new(mut last_update_arg: u32, mut enabled_arg: bool, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z, mut fees_arg: crate::lightning::routing::network_graph::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> ChannelUpdateInfo {
805         let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
806         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()) } }) };
807         ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo {
808                 last_update: last_update_arg,
809                 enabled: enabled_arg,
810                 cltv_expiry_delta: cltv_expiry_delta_arg,
811                 htlc_minimum_msat: htlc_minimum_msat_arg,
812                 htlc_maximum_msat: local_htlc_maximum_msat_arg,
813                 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
814                 last_update_message: local_last_update_message_arg,
815         }), is_owned: true }
816 }
817 impl Clone for ChannelUpdateInfo {
818         fn clone(&self) -> Self {
819                 Self {
820                         inner: if <*mut nativeChannelUpdateInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
821                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
822                         is_owned: true,
823                 }
824         }
825 }
826 #[allow(unused)]
827 /// Used only if an object of this type is returned as a trait impl by a method
828 pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
829         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdateInfo)).clone() })) as *mut c_void
830 }
831 #[no_mangle]
832 /// Creates a copy of the ChannelUpdateInfo
833 pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo {
834         orig.clone()
835 }
836 #[no_mangle]
837 /// Serialize the ChannelUpdateInfo object into a byte array which can be read by ChannelUpdateInfo_read
838 pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::network_graph::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z {
839         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
840 }
841 #[no_mangle]
842 pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
843         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) })
844 }
845 #[no_mangle]
846 /// Read a ChannelUpdateInfo from a byte array, created by ChannelUpdateInfo_write
847 pub extern "C" fn ChannelUpdateInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateInfoDecodeErrorZ {
848         let res: Result<lightning::routing::network_graph::ChannelUpdateInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
849         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::ChannelUpdateInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
850         local_res
851 }
852
853 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
854 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
855
856 /// Details about a channel (both directions).
857 /// Received within a channel announcement.
858 #[must_use]
859 #[repr(C)]
860 pub struct ChannelInfo {
861         /// A pointer to the opaque Rust object.
862
863         /// Nearly everywhere, inner must be non-null, however in places where
864         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
865         pub inner: *mut nativeChannelInfo,
866         /// Indicates that this is the only struct which contains the same pointer.
867
868         /// Rust functions which take ownership of an object provided via an argument require
869         /// this to be true and invalidate the object pointed to by inner.
870         pub is_owned: bool,
871 }
872
873 impl Drop for ChannelInfo {
874         fn drop(&mut self) {
875                 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
876                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
877                 }
878         }
879 }
880 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
881 #[no_mangle]
882 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
883 #[allow(unused)]
884 /// Used only if an object of this type is returned as a trait impl by a method
885 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
886         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
887 }
888 #[allow(unused)]
889 impl ChannelInfo {
890         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
891                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
892         }
893         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
894                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
895         }
896         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
897         pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
898                 assert!(self.is_owned);
899                 let ret = ObjOps::untweak_ptr(self.inner);
900                 self.inner = core::ptr::null_mut();
901                 ret
902         }
903 }
904 /// Protocol features of a channel communicated during its announcement
905 #[no_mangle]
906 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
907         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
908         crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::ChannelFeatures<>) as *mut _) }, is_owned: false }
909 }
910 /// Protocol features of a channel communicated during its announcement
911 #[no_mangle]
912 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
913         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
914 }
915 /// Source node of the first direction of a channel
916 #[no_mangle]
917 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::NodeId {
918         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
919         crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }
920 }
921 /// Source node of the first direction of a channel
922 #[no_mangle]
923 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::NodeId) {
924         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
925 }
926 /// Details about the first direction of a channel
927 ///
928 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
929 #[no_mangle]
930 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::ChannelUpdateInfo {
931         let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
932         let mut local_inner_val = crate::lightning::routing::network_graph::ChannelUpdateInfo { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::network_graph::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
933         local_inner_val
934 }
935 /// Details about the first direction of a channel
936 ///
937 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
938 #[no_mangle]
939 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::ChannelUpdateInfo) {
940         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
941         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
942 }
943 /// Source node of the second direction of a channel
944 #[no_mangle]
945 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::NodeId {
946         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
947         crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }
948 }
949 /// Source node of the second direction of a channel
950 #[no_mangle]
951 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::NodeId) {
952         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
953 }
954 /// Details about the second direction of a channel
955 ///
956 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
957 #[no_mangle]
958 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::ChannelUpdateInfo {
959         let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
960         let mut local_inner_val = crate::lightning::routing::network_graph::ChannelUpdateInfo { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::network_graph::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
961         local_inner_val
962 }
963 /// Details about the second direction of a channel
964 ///
965 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
966 #[no_mangle]
967 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::ChannelUpdateInfo) {
968         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
969         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
970 }
971 /// The channel capacity as seen on-chain, if chain lookup is available.
972 #[no_mangle]
973 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
974         let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
975         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() }) };
976         local_inner_val
977 }
978 /// The channel capacity as seen on-chain, if chain lookup is available.
979 #[no_mangle]
980 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
981         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
982         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
983 }
984 /// An initial announcement of the channel
985 /// Mostly redundant with the data we store in fields explicitly.
986 /// Everything else is useful only for sending out for initial routing sync.
987 /// Not stored if contains excess data to prevent DoS.
988 ///
989 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
990 #[no_mangle]
991 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
992         let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
993         let mut local_inner_val = crate::lightning::ln::msgs::ChannelAnnouncement { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::msgs::ChannelAnnouncement<>) as *mut _ }, is_owned: false };
994         local_inner_val
995 }
996 /// An initial announcement of the channel
997 /// Mostly redundant with the data we store in fields explicitly.
998 /// Everything else is useful only for sending out for initial routing sync.
999 /// Not stored if contains excess data to prevent DoS.
1000 ///
1001 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1002 #[no_mangle]
1003 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
1004         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1005         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1006 }
1007 impl Clone for ChannelInfo {
1008         fn clone(&self) -> Self {
1009                 Self {
1010                         inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1011                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1012                         is_owned: true,
1013                 }
1014         }
1015 }
1016 #[allow(unused)]
1017 /// Used only if an object of this type is returned as a trait impl by a method
1018 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1019         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
1020 }
1021 #[no_mangle]
1022 /// Creates a copy of the ChannelInfo
1023 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1024         orig.clone()
1025 }
1026 #[no_mangle]
1027 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1028 pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::network_graph::ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1029         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1030 }
1031 #[no_mangle]
1032 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1033         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1034 }
1035 #[no_mangle]
1036 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1037 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1038         let res: Result<lightning::routing::network_graph::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1039         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::ChannelInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1040         local_res
1041 }
1042
1043 use lightning::routing::network_graph::DirectedChannelInfo as nativeDirectedChannelInfoImport;
1044 pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static>;
1045
1046 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
1047 /// source node to a target node.
1048 #[must_use]
1049 #[repr(C)]
1050 pub struct DirectedChannelInfo {
1051         /// A pointer to the opaque Rust object.
1052
1053         /// Nearly everywhere, inner must be non-null, however in places where
1054         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1055         pub inner: *mut nativeDirectedChannelInfo,
1056         /// Indicates that this is the only struct which contains the same pointer.
1057
1058         /// Rust functions which take ownership of an object provided via an argument require
1059         /// this to be true and invalidate the object pointed to by inner.
1060         pub is_owned: bool,
1061 }
1062
1063 impl Drop for DirectedChannelInfo {
1064         fn drop(&mut self) {
1065                 if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
1066                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1067                 }
1068         }
1069 }
1070 /// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
1071 #[no_mangle]
1072 pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
1073 #[allow(unused)]
1074 /// Used only if an object of this type is returned as a trait impl by a method
1075 pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
1076         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo); }
1077 }
1078 #[allow(unused)]
1079 impl DirectedChannelInfo {
1080         pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
1081                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1082         }
1083         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
1084                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1085         }
1086         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1087         pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelInfo {
1088                 assert!(self.is_owned);
1089                 let ret = ObjOps::untweak_ptr(self.inner);
1090                 self.inner = core::ptr::null_mut();
1091                 ret
1092         }
1093 }
1094 impl Clone for DirectedChannelInfo {
1095         fn clone(&self) -> Self {
1096                 Self {
1097                         inner: if <*mut nativeDirectedChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1098                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1099                         is_owned: true,
1100                 }
1101         }
1102 }
1103 #[allow(unused)]
1104 /// Used only if an object of this type is returned as a trait impl by a method
1105 pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1106         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void
1107 }
1108 #[no_mangle]
1109 /// Creates a copy of the DirectedChannelInfo
1110 pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
1111         orig.clone()
1112 }
1113 /// Returns information for the channel.
1114 #[must_use]
1115 #[no_mangle]
1116 pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routing::network_graph::DirectedChannelInfo) -> crate::lightning::routing::network_graph::ChannelInfo {
1117         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
1118         crate::lightning::routing::network_graph::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::network_graph::ChannelInfo<>) as *mut _) }, is_owned: false }
1119 }
1120
1121 /// Returns information for the direction.
1122 ///
1123 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1124 #[must_use]
1125 #[no_mangle]
1126 pub extern "C" fn DirectedChannelInfo_direction(this_arg: &crate::lightning::routing::network_graph::DirectedChannelInfo) -> crate::lightning::routing::network_graph::ChannelUpdateInfo {
1127         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.direction();
1128         let mut local_ret = crate::lightning::routing::network_graph::ChannelUpdateInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::network_graph::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
1129         local_ret
1130 }
1131
1132 /// Returns the [`EffectiveCapacity`] of the channel in the direction.
1133 ///
1134 /// This is either the total capacity from the funding transaction, if known, or the
1135 /// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
1136 /// whichever is smaller.
1137 #[must_use]
1138 #[no_mangle]
1139 pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::lightning::routing::network_graph::DirectedChannelInfo) -> crate::lightning::routing::network_graph::EffectiveCapacity {
1140         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
1141         crate::lightning::routing::network_graph::EffectiveCapacity::native_into(ret)
1142 }
1143
1144 /// The effective capacity of a channel for routing purposes.
1145 ///
1146 /// While this may be smaller than the actual channel capacity, amounts greater than
1147 /// [`Self::as_msat`] should not be routed through the channel.
1148 #[must_use]
1149 #[derive(Clone)]
1150 #[repr(C)]
1151 pub enum EffectiveCapacity {
1152         /// The available liquidity in the channel known from being a channel counterparty, and thus a
1153         /// direct hop.
1154         ExactLiquidity {
1155                 /// Either the inbound or outbound liquidity depending on the direction, denominated in
1156                 /// millisatoshi.
1157                 liquidity_msat: u64,
1158         },
1159         /// The maximum HTLC amount in one direction as advertised on the gossip network.
1160         MaximumHTLC {
1161                 /// The maximum HTLC amount denominated in millisatoshi.
1162                 amount_msat: u64,
1163         },
1164         /// The total capacity of the channel as determined by the funding transaction.
1165         Total {
1166                 /// The funding amount denominated in millisatoshi.
1167                 capacity_msat: u64,
1168         },
1169         /// A capacity sufficient to route any payment, typically used for private channels provided by
1170         /// an invoice.
1171         Infinite,
1172         /// A capacity that is unknown possibly because either the chain state is unavailable to know
1173         /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
1174         Unknown,
1175 }
1176 use lightning::routing::network_graph::EffectiveCapacity as nativeEffectiveCapacity;
1177 impl EffectiveCapacity {
1178         #[allow(unused)]
1179         pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
1180                 match self {
1181                         EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1182                                 let mut liquidity_msat_nonref = (*liquidity_msat).clone();
1183                                 nativeEffectiveCapacity::ExactLiquidity {
1184                                         liquidity_msat: liquidity_msat_nonref,
1185                                 }
1186                         },
1187                         EffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1188                                 let mut amount_msat_nonref = (*amount_msat).clone();
1189                                 nativeEffectiveCapacity::MaximumHTLC {
1190                                         amount_msat: amount_msat_nonref,
1191                                 }
1192                         },
1193                         EffectiveCapacity::Total {ref capacity_msat, } => {
1194                                 let mut capacity_msat_nonref = (*capacity_msat).clone();
1195                                 nativeEffectiveCapacity::Total {
1196                                         capacity_msat: capacity_msat_nonref,
1197                                 }
1198                         },
1199                         EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1200                         EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1201                 }
1202         }
1203         #[allow(unused)]
1204         pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
1205                 match self {
1206                         EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1207                                 nativeEffectiveCapacity::ExactLiquidity {
1208                                         liquidity_msat: liquidity_msat,
1209                                 }
1210                         },
1211                         EffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1212                                 nativeEffectiveCapacity::MaximumHTLC {
1213                                         amount_msat: amount_msat,
1214                                 }
1215                         },
1216                         EffectiveCapacity::Total {mut capacity_msat, } => {
1217                                 nativeEffectiveCapacity::Total {
1218                                         capacity_msat: capacity_msat,
1219                                 }
1220                         },
1221                         EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1222                         EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1223                 }
1224         }
1225         #[allow(unused)]
1226         pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self {
1227                 match native {
1228                         nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1229                                 let mut liquidity_msat_nonref = (*liquidity_msat).clone();
1230                                 EffectiveCapacity::ExactLiquidity {
1231                                         liquidity_msat: liquidity_msat_nonref,
1232                                 }
1233                         },
1234                         nativeEffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1235                                 let mut amount_msat_nonref = (*amount_msat).clone();
1236                                 EffectiveCapacity::MaximumHTLC {
1237                                         amount_msat: amount_msat_nonref,
1238                                 }
1239                         },
1240                         nativeEffectiveCapacity::Total {ref capacity_msat, } => {
1241                                 let mut capacity_msat_nonref = (*capacity_msat).clone();
1242                                 EffectiveCapacity::Total {
1243                                         capacity_msat: capacity_msat_nonref,
1244                                 }
1245                         },
1246                         nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1247                         nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1248                 }
1249         }
1250         #[allow(unused)]
1251         pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
1252                 match native {
1253                         nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1254                                 EffectiveCapacity::ExactLiquidity {
1255                                         liquidity_msat: liquidity_msat,
1256                                 }
1257                         },
1258                         nativeEffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1259                                 EffectiveCapacity::MaximumHTLC {
1260                                         amount_msat: amount_msat,
1261                                 }
1262                         },
1263                         nativeEffectiveCapacity::Total {mut capacity_msat, } => {
1264                                 EffectiveCapacity::Total {
1265                                         capacity_msat: capacity_msat,
1266                                 }
1267                         },
1268                         nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1269                         nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1270                 }
1271         }
1272 }
1273 /// Frees any resources used by the EffectiveCapacity
1274 #[no_mangle]
1275 pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
1276 /// Creates a copy of the EffectiveCapacity
1277 #[no_mangle]
1278 pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
1279         orig.clone()
1280 }
1281 #[no_mangle]
1282 /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
1283 pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
1284         EffectiveCapacity::ExactLiquidity {
1285                 liquidity_msat,
1286         }
1287 }
1288 #[no_mangle]
1289 /// Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity
1290 pub extern "C" fn EffectiveCapacity_maximum_htlc(amount_msat: u64) -> EffectiveCapacity {
1291         EffectiveCapacity::MaximumHTLC {
1292                 amount_msat,
1293         }
1294 }
1295 #[no_mangle]
1296 /// Utility method to constructs a new Total-variant EffectiveCapacity
1297 pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64) -> EffectiveCapacity {
1298         EffectiveCapacity::Total {
1299                 capacity_msat,
1300         }
1301 }
1302 #[no_mangle]
1303 /// Utility method to constructs a new Infinite-variant EffectiveCapacity
1304 pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
1305         EffectiveCapacity::Infinite}
1306 #[no_mangle]
1307 /// Utility method to constructs a new Unknown-variant EffectiveCapacity
1308 pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
1309         EffectiveCapacity::Unknown}
1310 /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
1311 /// use when making routing decisions.
1312
1313 #[no_mangle]
1314 pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::network_graph::UNKNOWN_CHANNEL_CAPACITY_MSAT;
1315 /// Returns the effective capacity denominated in millisatoshi.
1316 #[must_use]
1317 #[no_mangle]
1318 pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &crate::lightning::routing::network_graph::EffectiveCapacity) -> u64 {
1319         let mut ret = this_arg.to_native().as_msat();
1320         ret
1321 }
1322
1323
1324 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
1325 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1326
1327 /// Fees for routing via a given channel or a node
1328 #[must_use]
1329 #[repr(C)]
1330 pub struct RoutingFees {
1331         /// A pointer to the opaque Rust object.
1332
1333         /// Nearly everywhere, inner must be non-null, however in places where
1334         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1335         pub inner: *mut nativeRoutingFees,
1336         /// Indicates that this is the only struct which contains the same pointer.
1337
1338         /// Rust functions which take ownership of an object provided via an argument require
1339         /// this to be true and invalidate the object pointed to by inner.
1340         pub is_owned: bool,
1341 }
1342
1343 impl Drop for RoutingFees {
1344         fn drop(&mut self) {
1345                 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
1346                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1347                 }
1348         }
1349 }
1350 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
1351 #[no_mangle]
1352 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
1353 #[allow(unused)]
1354 /// Used only if an object of this type is returned as a trait impl by a method
1355 pub(crate) extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
1356         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
1357 }
1358 #[allow(unused)]
1359 impl RoutingFees {
1360         pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1361                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1362         }
1363         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
1364                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1365         }
1366         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1367         pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
1368                 assert!(self.is_owned);
1369                 let ret = ObjOps::untweak_ptr(self.inner);
1370                 self.inner = core::ptr::null_mut();
1371                 ret
1372         }
1373 }
1374 /// Flat routing fee in satoshis
1375 #[no_mangle]
1376 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1377         let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1378         *inner_val
1379 }
1380 /// Flat routing fee in satoshis
1381 #[no_mangle]
1382 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1383         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1384 }
1385 /// Liquidity-based routing fee in millionths of a routed amount.
1386 /// In other words, 10000 is 1%.
1387 #[no_mangle]
1388 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1389         let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1390         *inner_val
1391 }
1392 /// Liquidity-based routing fee in millionths of a routed amount.
1393 /// In other words, 10000 is 1%.
1394 #[no_mangle]
1395 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1396         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1397 }
1398 /// Constructs a new RoutingFees given each field
1399 #[must_use]
1400 #[no_mangle]
1401 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1402         RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1403                 base_msat: base_msat_arg,
1404                 proportional_millionths: proportional_millionths_arg,
1405         }), is_owned: true }
1406 }
1407 /// Checks if two RoutingFeess contain equal inner contents.
1408 /// This ignores pointers and is_owned flags and looks at the values in fields.
1409 /// Two objects with NULL inner values will be considered "equal" here.
1410 #[no_mangle]
1411 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1412         if a.inner == b.inner { return true; }
1413         if a.inner.is_null() || b.inner.is_null() { return false; }
1414         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1415 }
1416 impl Clone for RoutingFees {
1417         fn clone(&self) -> Self {
1418                 Self {
1419                         inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1420                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1421                         is_owned: true,
1422                 }
1423         }
1424 }
1425 #[allow(unused)]
1426 /// Used only if an object of this type is returned as a trait impl by a method
1427 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1428         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1429 }
1430 #[no_mangle]
1431 /// Creates a copy of the RoutingFees
1432 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1433         orig.clone()
1434 }
1435 /// Checks if two RoutingFeess contain equal inner contents.
1436 #[no_mangle]
1437 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1438         if o.inner.is_null() { return 0; }
1439         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1440         #[allow(deprecated)]
1441         let mut hasher = core::hash::SipHasher::new();
1442         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1443         core::hash::Hasher::finish(&hasher)
1444 }
1445 #[no_mangle]
1446 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1447 pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::network_graph::RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1448         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1449 }
1450 #[no_mangle]
1451 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1452         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1453 }
1454 #[no_mangle]
1455 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1456 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1457         let res: Result<lightning::routing::network_graph::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1458         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::RoutingFees { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1459         local_res
1460 }
1461
1462 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1463 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1464
1465 /// Information received in the latest node_announcement from this node.
1466 #[must_use]
1467 #[repr(C)]
1468 pub struct NodeAnnouncementInfo {
1469         /// A pointer to the opaque Rust object.
1470
1471         /// Nearly everywhere, inner must be non-null, however in places where
1472         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1473         pub inner: *mut nativeNodeAnnouncementInfo,
1474         /// Indicates that this is the only struct which contains the same pointer.
1475
1476         /// Rust functions which take ownership of an object provided via an argument require
1477         /// this to be true and invalidate the object pointed to by inner.
1478         pub is_owned: bool,
1479 }
1480
1481 impl Drop for NodeAnnouncementInfo {
1482         fn drop(&mut self) {
1483                 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1484                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1485                 }
1486         }
1487 }
1488 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1489 #[no_mangle]
1490 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1491 #[allow(unused)]
1492 /// Used only if an object of this type is returned as a trait impl by a method
1493 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1494         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
1495 }
1496 #[allow(unused)]
1497 impl NodeAnnouncementInfo {
1498         pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1499                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1500         }
1501         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1502                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1503         }
1504         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1505         pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1506                 assert!(self.is_owned);
1507                 let ret = ObjOps::untweak_ptr(self.inner);
1508                 self.inner = core::ptr::null_mut();
1509                 ret
1510         }
1511 }
1512 /// Protocol features the node announced support for
1513 #[no_mangle]
1514 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1515         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1516         crate::lightning::ln::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::NodeFeatures<>) as *mut _) }, is_owned: false }
1517 }
1518 /// Protocol features the node announced support for
1519 #[no_mangle]
1520 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1521         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1522 }
1523 /// When the last known update to the node state was issued.
1524 /// Value is opaque, as set in the announcement.
1525 #[no_mangle]
1526 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1527         let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1528         *inner_val
1529 }
1530 /// When the last known update to the node state was issued.
1531 /// Value is opaque, as set in the announcement.
1532 #[no_mangle]
1533 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1534         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1535 }
1536 /// Color assigned to the node
1537 #[no_mangle]
1538 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1539         let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1540         inner_val
1541 }
1542 /// Color assigned to the node
1543 #[no_mangle]
1544 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1545         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1546 }
1547 /// Moniker assigned to the node.
1548 /// May be invalid or malicious (eg control chars),
1549 /// should not be exposed to the user.
1550 #[no_mangle]
1551 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
1552         let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1553         inner_val
1554 }
1555 /// Moniker assigned to the node.
1556 /// May be invalid or malicious (eg control chars),
1557 /// should not be exposed to the user.
1558 #[no_mangle]
1559 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
1560         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = val.data;
1561 }
1562 /// Internet-level addresses via which one can connect to the node
1563 #[no_mangle]
1564 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
1565         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
1566         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val;
1567 }
1568 /// An initial announcement of the node
1569 /// Mostly redundant with the data we store in fields explicitly.
1570 /// Everything else is useful only for sending out for initial routing sync.
1571 /// Not stored if contains excess data to prevent DoS.
1572 ///
1573 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1574 #[no_mangle]
1575 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1576         let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1577         let mut local_inner_val = crate::lightning::ln::msgs::NodeAnnouncement { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::msgs::NodeAnnouncement<>) as *mut _ }, is_owned: false };
1578         local_inner_val
1579 }
1580 /// An initial announcement of the node
1581 /// Mostly redundant with the data we store in fields explicitly.
1582 /// Everything else is useful only for sending out for initial routing sync.
1583 /// Not stored if contains excess data to prevent DoS.
1584 ///
1585 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1586 #[no_mangle]
1587 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1588         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1589         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1590 }
1591 /// Constructs a new NodeAnnouncementInfo given each field
1592 #[must_use]
1593 #[no_mangle]
1594 pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::lightning::ln::features::NodeFeatures, mut last_update_arg: u32, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::c_types::ThirtyTwoBytes, mut addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo {
1595         let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
1596         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()) } }) };
1597         NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1598                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1599                 last_update: last_update_arg,
1600                 rgb: rgb_arg.data,
1601                 alias: alias_arg.data,
1602                 addresses: local_addresses_arg,
1603                 announcement_message: local_announcement_message_arg,
1604         }), is_owned: true }
1605 }
1606 impl Clone for NodeAnnouncementInfo {
1607         fn clone(&self) -> Self {
1608                 Self {
1609                         inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1610                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1611                         is_owned: true,
1612                 }
1613         }
1614 }
1615 #[allow(unused)]
1616 /// Used only if an object of this type is returned as a trait impl by a method
1617 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1618         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1619 }
1620 #[no_mangle]
1621 /// Creates a copy of the NodeAnnouncementInfo
1622 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1623         orig.clone()
1624 }
1625 #[no_mangle]
1626 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1627 pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::network_graph::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1628         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1629 }
1630 #[no_mangle]
1631 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1632         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1633 }
1634 #[no_mangle]
1635 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1636 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1637         let res: Result<lightning::routing::network_graph::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1638         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeAnnouncementInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1639         local_res
1640 }
1641
1642 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
1643 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1644
1645 /// Details about a node in the network, known from the network announcement.
1646 #[must_use]
1647 #[repr(C)]
1648 pub struct NodeInfo {
1649         /// A pointer to the opaque Rust object.
1650
1651         /// Nearly everywhere, inner must be non-null, however in places where
1652         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1653         pub inner: *mut nativeNodeInfo,
1654         /// Indicates that this is the only struct which contains the same pointer.
1655
1656         /// Rust functions which take ownership of an object provided via an argument require
1657         /// this to be true and invalidate the object pointed to by inner.
1658         pub is_owned: bool,
1659 }
1660
1661 impl Drop for NodeInfo {
1662         fn drop(&mut self) {
1663                 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1664                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1665                 }
1666         }
1667 }
1668 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1669 #[no_mangle]
1670 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1671 #[allow(unused)]
1672 /// Used only if an object of this type is returned as a trait impl by a method
1673 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1674         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1675 }
1676 #[allow(unused)]
1677 impl NodeInfo {
1678         pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1679                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1680         }
1681         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1682                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1683         }
1684         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1685         pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1686                 assert!(self.is_owned);
1687                 let ret = ObjOps::untweak_ptr(self.inner);
1688                 self.inner = core::ptr::null_mut();
1689                 ret
1690         }
1691 }
1692 /// All valid channels a node has announced
1693 #[no_mangle]
1694 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1695         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1696         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1697 }
1698 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1699 /// The two fields (flat and proportional fee) are independent,
1700 /// meaning they don't have to refer to the same channel.
1701 ///
1702 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1703 #[no_mangle]
1704 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::RoutingFees {
1705         let mut inner_val = &mut this_ptr.get_native_mut_ref().lowest_inbound_channel_fees;
1706         let mut local_inner_val = crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::network_graph::RoutingFees<>) as *mut _ }, is_owned: false };
1707         local_inner_val
1708 }
1709 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1710 /// The two fields (flat and proportional fee) are independent,
1711 /// meaning they don't have to refer to the same channel.
1712 ///
1713 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1714 #[no_mangle]
1715 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
1716         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1717         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.lowest_inbound_channel_fees = local_val;
1718 }
1719 /// More information about a node from node_announcement.
1720 /// Optional because we store a Node entry after learning about it from
1721 /// a channel announcement, but before receiving a node announcement.
1722 ///
1723 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1724 #[no_mangle]
1725 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::NodeAnnouncementInfo {
1726         let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1727         let mut local_inner_val = crate::lightning::routing::network_graph::NodeAnnouncementInfo { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::network_graph::NodeAnnouncementInfo<>) as *mut _ }, is_owned: false };
1728         local_inner_val
1729 }
1730 /// More information about a node from node_announcement.
1731 /// Optional because we store a Node entry after learning about it from
1732 /// a channel announcement, but before receiving a node announcement.
1733 ///
1734 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1735 #[no_mangle]
1736 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::NodeAnnouncementInfo) {
1737         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1738         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1739 }
1740 /// Constructs a new NodeInfo given each field
1741 #[must_use]
1742 #[no_mangle]
1743 pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::lightning::routing::network_graph::RoutingFees, mut announcement_info_arg: crate::lightning::routing::network_graph::NodeAnnouncementInfo) -> NodeInfo {
1744         let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1745         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()) } }) };
1746         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()) } }) };
1747         NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1748                 channels: local_channels_arg,
1749                 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1750                 announcement_info: local_announcement_info_arg,
1751         }), is_owned: true }
1752 }
1753 impl Clone for NodeInfo {
1754         fn clone(&self) -> Self {
1755                 Self {
1756                         inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1757                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1758                         is_owned: true,
1759                 }
1760         }
1761 }
1762 #[allow(unused)]
1763 /// Used only if an object of this type is returned as a trait impl by a method
1764 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1765         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1766 }
1767 #[no_mangle]
1768 /// Creates a copy of the NodeInfo
1769 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1770         orig.clone()
1771 }
1772 #[no_mangle]
1773 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1774 pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::network_graph::NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1775         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1776 }
1777 #[no_mangle]
1778 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1779         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1780 }
1781 #[no_mangle]
1782 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1783 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1784         let res: Result<lightning::routing::network_graph::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1785         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1786         local_res
1787 }
1788 #[no_mangle]
1789 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1790 pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::network_graph::NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1791         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1792 }
1793 #[no_mangle]
1794 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1795         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1796 }
1797 #[no_mangle]
1798 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1799 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1800         let res: Result<lightning::routing::network_graph::NetworkGraph, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1801         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NetworkGraph { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1802         local_res
1803 }
1804 /// Creates a new, empty, network graph.
1805 #[must_use]
1806 #[no_mangle]
1807 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::lightning::routing::network_graph::NetworkGraph {
1808         let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1809         crate::lightning::routing::network_graph::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1810 }
1811
1812 /// Returns a read-only view of the network graph.
1813 #[must_use]
1814 #[no_mangle]
1815 pub extern "C" fn NetworkGraph_read_only(this_arg: &crate::lightning::routing::network_graph::NetworkGraph) -> crate::lightning::routing::network_graph::ReadOnlyNetworkGraph {
1816         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
1817         crate::lightning::routing::network_graph::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1818 }
1819
1820 /// For an already known node (from channel announcements), update its stored properties from a
1821 /// given node announcement.
1822 ///
1823 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1824 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1825 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1826 #[must_use]
1827 #[no_mangle]
1828 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &crate::lightning::routing::network_graph::NetworkGraph, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1829         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref(), secp256k1::SECP256K1);
1830         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1831         local_ret
1832 }
1833
1834 /// For an already known node (from channel announcements), update its stored properties from a
1835 /// given node announcement without verifying the associated signatures. Because we aren't
1836 /// given the associated signatures here we cannot relay the node announcement to any of our
1837 /// peers.
1838 #[must_use]
1839 #[no_mangle]
1840 pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &crate::lightning::routing::network_graph::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1841         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
1842         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1843         local_ret
1844 }
1845
1846 /// Store or update channel info from a channel announcement.
1847 ///
1848 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1849 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1850 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1851 ///
1852 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1853 /// the corresponding UTXO exists on chain and is correctly-formatted.
1854 #[must_use]
1855 #[no_mangle]
1856 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &crate::lightning::routing::network_graph::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1857         let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
1858         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_chain_access, secp256k1::SECP256K1);
1859         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1860         local_ret
1861 }
1862
1863 /// Store or update channel info from a channel announcement without verifying the associated
1864 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1865 /// channel announcement to any of our peers.
1866 ///
1867 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1868 /// the corresponding UTXO exists on chain and is correctly-formatted.
1869 #[must_use]
1870 #[no_mangle]
1871 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &crate::lightning::routing::network_graph::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1872         let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
1873         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_chain_access);
1874         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1875         local_ret
1876 }
1877
1878 /// Close a channel if a corresponding HTLC fail was sent.
1879 /// If permanent, removes a channel from the local storage.
1880 /// May cause the removal of nodes too, if this was their last channel.
1881 /// If not permanent, makes channels unavailable for routing.
1882 #[no_mangle]
1883 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &crate::lightning::routing::network_graph::NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1884         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_from_update(short_channel_id, is_permanent)
1885 }
1886
1887 /// Marks a node in the graph as failed.
1888 #[no_mangle]
1889 pub extern "C" fn NetworkGraph_fail_node(this_arg: &crate::lightning::routing::network_graph::NetworkGraph, mut _node_id: crate::c_types::PublicKey, mut is_permanent: bool) {
1890         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_node(&_node_id.into_rust(), is_permanent)
1891 }
1892
1893 /// Removes information about channels that we haven't heard any updates about in some time.
1894 /// This can be used regularly to prune the network graph of channels that likely no longer
1895 /// exist.
1896 ///
1897 /// While there is no formal requirement that nodes regularly re-broadcast their channel
1898 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
1899 /// pruning occur for updates which are at least two weeks old, which we implement here.
1900 ///
1901 /// Note that for users of the `lightning-background-processor` crate this method may be
1902 /// automatically called regularly for you.
1903 ///
1904 /// This method is only available with the `std` feature. See
1905 /// [`NetworkGraph::remove_stale_channels_with_time`] for `no-std` use.
1906 #[no_mangle]
1907 pub extern "C" fn NetworkGraph_remove_stale_channels(this_arg: &crate::lightning::routing::network_graph::NetworkGraph) {
1908         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels()
1909 }
1910
1911 /// Removes information about channels that we haven't heard any updates about in some time.
1912 /// This can be used regularly to prune the network graph of channels that likely no longer
1913 /// exist.
1914 ///
1915 /// While there is no formal requirement that nodes regularly re-broadcast their channel
1916 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
1917 /// pruning occur for updates which are at least two weeks old, which we implement here.
1918 ///
1919 /// This function takes the current unix time as an argument. For users with the `std` feature
1920 /// enabled, [`NetworkGraph::remove_stale_channels`] may be preferable.
1921 #[no_mangle]
1922 pub extern "C" fn NetworkGraph_remove_stale_channels_with_time(this_arg: &crate::lightning::routing::network_graph::NetworkGraph, mut current_time_unix: u64) {
1923         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_with_time(current_time_unix)
1924 }
1925
1926 /// For an already known (from announcement) channel, update info about one of the directions
1927 /// of the channel.
1928 ///
1929 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1930 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1931 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1932 ///
1933 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1934 /// materially in the future will be rejected.
1935 #[must_use]
1936 #[no_mangle]
1937 pub extern "C" fn NetworkGraph_update_channel(this_arg: &crate::lightning::routing::network_graph::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1938         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref(), secp256k1::SECP256K1);
1939         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1940         local_ret
1941 }
1942
1943 /// For an already known (from announcement) channel, update info about one of the directions
1944 /// of the channel without verifying the associated signatures. Because we aren't given the
1945 /// associated signatures here we cannot relay the channel update to any of our peers.
1946 ///
1947 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1948 /// materially in the future will be rejected.
1949 #[must_use]
1950 #[no_mangle]
1951 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &crate::lightning::routing::network_graph::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1952         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
1953         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1954         local_ret
1955 }
1956
1957 /// Get network addresses by node id.
1958 /// Returns None if the requested node is completely unknown,
1959 /// or if node announcement for the node was never received.
1960 #[must_use]
1961 #[no_mangle]
1962 pub extern "C" fn ReadOnlyNetworkGraph_get_addresses(this_arg: &crate::lightning::routing::network_graph::ReadOnlyNetworkGraph, mut pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::COption_CVec_NetAddressZZ {
1963         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust());
1964         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_NetAddressZZ::None } else { crate::c_types::derived::COption_CVec_NetAddressZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); }; local_ret_0.into() }) };
1965         local_ret
1966 }
1967