Update auto-generated bindings
[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) -> NodeId {
93         let mut ret = lightning::routing::network_graph::NodeId::from_pubkey(&pubkey.into_rust());
94         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: &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: &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: &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) -> 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         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 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 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                 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
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_sync_routing_table(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<>>::sync_routing_table(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::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
659 pub(crate) type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
660
661 /// Details about one direction of a channel. Received
662 /// within a channel update.
663 #[must_use]
664 #[repr(C)]
665 pub struct DirectionalChannelInfo {
666         /// A pointer to the opaque Rust object.
667
668         /// Nearly everywhere, inner must be non-null, however in places where
669         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
670         pub inner: *mut nativeDirectionalChannelInfo,
671         /// Indicates that this is the only struct which contains the same pointer.
672
673         /// Rust functions which take ownership of an object provided via an argument require
674         /// this to be true and invalidate the object pointed to by inner.
675         pub is_owned: bool,
676 }
677
678 impl Drop for DirectionalChannelInfo {
679         fn drop(&mut self) {
680                 if self.is_owned && !<*mut nativeDirectionalChannelInfo>::is_null(self.inner) {
681                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
682                 }
683         }
684 }
685 /// Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL.
686 #[no_mangle]
687 pub extern "C" fn DirectionalChannelInfo_free(this_obj: DirectionalChannelInfo) { }
688 #[allow(unused)]
689 /// Used only if an object of this type is returned as a trait impl by a method
690 pub(crate) extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
691         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
692 }
693 #[allow(unused)]
694 impl DirectionalChannelInfo {
695         pub(crate) fn get_native_ref(&self) -> &'static nativeDirectionalChannelInfo {
696                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
697         }
698         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectionalChannelInfo {
699                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
700         }
701         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
702         pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo {
703                 assert!(self.is_owned);
704                 let ret = ObjOps::untweak_ptr(self.inner);
705                 self.inner = core::ptr::null_mut();
706                 ret
707         }
708 }
709 /// When the last update to the channel direction was issued.
710 /// Value is opaque, as set in the announcement.
711 #[no_mangle]
712 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
713         let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
714         *inner_val
715 }
716 /// When the last update to the channel direction was issued.
717 /// Value is opaque, as set in the announcement.
718 #[no_mangle]
719 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
720         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
721 }
722 /// Whether the channel can be currently used for payments (in this one direction).
723 #[no_mangle]
724 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
725         let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
726         *inner_val
727 }
728 /// Whether the channel can be currently used for payments (in this one direction).
729 #[no_mangle]
730 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
731         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
732 }
733 /// The difference in CLTV values that you must have when routing through this channel.
734 #[no_mangle]
735 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
736         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
737         *inner_val
738 }
739 /// The difference in CLTV values that you must have when routing through this channel.
740 #[no_mangle]
741 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
742         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
743 }
744 /// The minimum value, which must be relayed to the next hop via the channel
745 #[no_mangle]
746 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
747         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
748         *inner_val
749 }
750 /// The minimum value, which must be relayed to the next hop via the channel
751 #[no_mangle]
752 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
753         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
754 }
755 /// The maximum value which may be relayed to the next hop via the channel.
756 #[no_mangle]
757 pub extern "C" fn DirectionalChannelInfo_get_htlc_maximum_msat(this_ptr: &DirectionalChannelInfo) -> crate::c_types::derived::COption_u64Z {
758         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
759         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() }) };
760         local_inner_val
761 }
762 /// The maximum value which may be relayed to the next hop via the channel.
763 #[no_mangle]
764 pub extern "C" fn DirectionalChannelInfo_set_htlc_maximum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
765         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
766         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
767 }
768 /// Fees charged when the channel is used for routing
769 #[no_mangle]
770 pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::lightning::routing::network_graph::RoutingFees {
771         let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
772         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 }
773 }
774 /// Fees charged when the channel is used for routing
775 #[no_mangle]
776 pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
777         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
778 }
779 /// Most recent update for the channel received from the network
780 /// Mostly redundant with the data we store in fields explicitly.
781 /// Everything else is useful only for sending out for initial routing sync.
782 /// Not stored if contains excess data to prevent DoS.
783 ///
784 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
785 #[no_mangle]
786 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
787         let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
788         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 };
789         local_inner_val
790 }
791 /// Most recent update for the channel received from the network
792 /// Mostly redundant with the data we store in fields explicitly.
793 /// Everything else is useful only for sending out for initial routing sync.
794 /// Not stored if contains excess data to prevent DoS.
795 ///
796 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
797 #[no_mangle]
798 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
799         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
800         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
801 }
802 /// Constructs a new DirectionalChannelInfo given each field
803 #[must_use]
804 #[no_mangle]
805 pub extern "C" fn DirectionalChannelInfo_new(mut last_update_arg: u32, mut enabled_arg: bool, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z, mut fees_arg: crate::lightning::routing::network_graph::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> DirectionalChannelInfo {
806         let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
807         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()) } }) };
808         DirectionalChannelInfo { inner: ObjOps::heap_alloc(nativeDirectionalChannelInfo {
809                 last_update: last_update_arg,
810                 enabled: enabled_arg,
811                 cltv_expiry_delta: cltv_expiry_delta_arg,
812                 htlc_minimum_msat: htlc_minimum_msat_arg,
813                 htlc_maximum_msat: local_htlc_maximum_msat_arg,
814                 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
815                 last_update_message: local_last_update_message_arg,
816         }), is_owned: true }
817 }
818 impl Clone for DirectionalChannelInfo {
819         fn clone(&self) -> Self {
820                 Self {
821                         inner: if <*mut nativeDirectionalChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
822                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
823                         is_owned: true,
824                 }
825         }
826 }
827 #[allow(unused)]
828 /// Used only if an object of this type is returned as a trait impl by a method
829 pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
830         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
831 }
832 #[no_mangle]
833 /// Creates a copy of the DirectionalChannelInfo
834 pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
835         orig.clone()
836 }
837 #[no_mangle]
838 /// Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read
839 pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
840         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
841 }
842 #[no_mangle]
843 pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
844         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) })
845 }
846 #[no_mangle]
847 /// Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write
848 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ {
849         let res: Result<lightning::routing::network_graph::DirectionalChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
850         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::DirectionalChannelInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
851         local_res
852 }
853
854 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
855 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
856
857 /// Details about a channel (both directions).
858 /// Received within a channel announcement.
859 #[must_use]
860 #[repr(C)]
861 pub struct ChannelInfo {
862         /// A pointer to the opaque Rust object.
863
864         /// Nearly everywhere, inner must be non-null, however in places where
865         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
866         pub inner: *mut nativeChannelInfo,
867         /// Indicates that this is the only struct which contains the same pointer.
868
869         /// Rust functions which take ownership of an object provided via an argument require
870         /// this to be true and invalidate the object pointed to by inner.
871         pub is_owned: bool,
872 }
873
874 impl Drop for ChannelInfo {
875         fn drop(&mut self) {
876                 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
877                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
878                 }
879         }
880 }
881 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
882 #[no_mangle]
883 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
884 #[allow(unused)]
885 /// Used only if an object of this type is returned as a trait impl by a method
886 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
887         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
888 }
889 #[allow(unused)]
890 impl ChannelInfo {
891         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
892                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
893         }
894         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
895                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
896         }
897         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
898         pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
899                 assert!(self.is_owned);
900                 let ret = ObjOps::untweak_ptr(self.inner);
901                 self.inner = core::ptr::null_mut();
902                 ret
903         }
904 }
905 /// Protocol features of a channel communicated during its announcement
906 #[no_mangle]
907 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
908         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
909         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 }
910 }
911 /// Protocol features of a channel communicated during its announcement
912 #[no_mangle]
913 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
914         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
915 }
916 /// Source node of the first direction of a channel
917 #[no_mangle]
918 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::NodeId {
919         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
920         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 }
921 }
922 /// Source node of the first direction of a channel
923 #[no_mangle]
924 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::NodeId) {
925         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
926 }
927 /// Details about the first direction of a channel
928 ///
929 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
930 #[no_mangle]
931 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
932         let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
933         let mut local_inner_val = crate::lightning::routing::network_graph::DirectionalChannelInfo { 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::DirectionalChannelInfo<>) as *mut _ }, is_owned: false };
934         local_inner_val
935 }
936 /// Details about the first direction of a channel
937 ///
938 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
939 #[no_mangle]
940 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
941         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
942         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
943 }
944 /// Source node of the second direction of a channel
945 #[no_mangle]
946 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::NodeId {
947         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
948         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 }
949 }
950 /// Source node of the second direction of a channel
951 #[no_mangle]
952 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::NodeId) {
953         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
954 }
955 /// Details about the second direction of a channel
956 ///
957 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
958 #[no_mangle]
959 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
960         let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
961         let mut local_inner_val = crate::lightning::routing::network_graph::DirectionalChannelInfo { 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::DirectionalChannelInfo<>) as *mut _ }, is_owned: false };
962         local_inner_val
963 }
964 /// Details about the second direction of a channel
965 ///
966 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
967 #[no_mangle]
968 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
969         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
970         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
971 }
972 /// The channel capacity as seen on-chain, if chain lookup is available.
973 #[no_mangle]
974 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
975         let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
976         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() }) };
977         local_inner_val
978 }
979 /// The channel capacity as seen on-chain, if chain lookup is available.
980 #[no_mangle]
981 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
982         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
983         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
984 }
985 /// An initial announcement of the channel
986 /// Mostly redundant with the data we store in fields explicitly.
987 /// Everything else is useful only for sending out for initial routing sync.
988 /// Not stored if contains excess data to prevent DoS.
989 ///
990 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
991 #[no_mangle]
992 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
993         let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
994         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 };
995         local_inner_val
996 }
997 /// An initial announcement of the channel
998 /// Mostly redundant with the data we store in fields explicitly.
999 /// Everything else is useful only for sending out for initial routing sync.
1000 /// Not stored if contains excess data to prevent DoS.
1001 ///
1002 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1003 #[no_mangle]
1004 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
1005         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1006         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1007 }
1008 impl Clone for ChannelInfo {
1009         fn clone(&self) -> Self {
1010                 Self {
1011                         inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1012                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1013                         is_owned: true,
1014                 }
1015         }
1016 }
1017 #[allow(unused)]
1018 /// Used only if an object of this type is returned as a trait impl by a method
1019 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1020         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
1021 }
1022 #[no_mangle]
1023 /// Creates a copy of the ChannelInfo
1024 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1025         orig.clone()
1026 }
1027 #[no_mangle]
1028 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1029 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1030         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1031 }
1032 #[no_mangle]
1033 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1034         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1035 }
1036 #[no_mangle]
1037 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1038 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1039         let res: Result<lightning::routing::network_graph::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1040         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() };
1041         local_res
1042 }
1043
1044 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
1045 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1046
1047 /// Fees for routing via a given channel or a node
1048 #[must_use]
1049 #[repr(C)]
1050 pub struct RoutingFees {
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 nativeRoutingFees,
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 RoutingFees {
1064         fn drop(&mut self) {
1065                 if self.is_owned && !<*mut nativeRoutingFees>::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 RoutingFees, if is_owned is set and inner is non-NULL.
1071 #[no_mangle]
1072 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
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 RoutingFees_free_void(this_ptr: *mut c_void) {
1076         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
1077 }
1078 #[allow(unused)]
1079 impl RoutingFees {
1080         pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1081                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1082         }
1083         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
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 nativeRoutingFees {
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 /// Flat routing fee in satoshis
1095 #[no_mangle]
1096 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1097         let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1098         *inner_val
1099 }
1100 /// Flat routing fee in satoshis
1101 #[no_mangle]
1102 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1103         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1104 }
1105 /// Liquidity-based routing fee in millionths of a routed amount.
1106 /// In other words, 10000 is 1%.
1107 #[no_mangle]
1108 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1109         let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1110         *inner_val
1111 }
1112 /// Liquidity-based routing fee in millionths of a routed amount.
1113 /// In other words, 10000 is 1%.
1114 #[no_mangle]
1115 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1116         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1117 }
1118 /// Constructs a new RoutingFees given each field
1119 #[must_use]
1120 #[no_mangle]
1121 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1122         RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1123                 base_msat: base_msat_arg,
1124                 proportional_millionths: proportional_millionths_arg,
1125         }), is_owned: true }
1126 }
1127 /// Checks if two RoutingFeess contain equal inner contents.
1128 /// This ignores pointers and is_owned flags and looks at the values in fields.
1129 /// Two objects with NULL inner values will be considered "equal" here.
1130 #[no_mangle]
1131 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1132         if a.inner == b.inner { return true; }
1133         if a.inner.is_null() || b.inner.is_null() { return false; }
1134         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1135 }
1136 impl Clone for RoutingFees {
1137         fn clone(&self) -> Self {
1138                 Self {
1139                         inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1140                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1141                         is_owned: true,
1142                 }
1143         }
1144 }
1145 #[allow(unused)]
1146 /// Used only if an object of this type is returned as a trait impl by a method
1147 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1148         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1149 }
1150 #[no_mangle]
1151 /// Creates a copy of the RoutingFees
1152 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1153         orig.clone()
1154 }
1155 /// Checks if two RoutingFeess contain equal inner contents.
1156 #[no_mangle]
1157 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1158         if o.inner.is_null() { return 0; }
1159         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1160         #[allow(deprecated)]
1161         let mut hasher = core::hash::SipHasher::new();
1162         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1163         core::hash::Hasher::finish(&hasher)
1164 }
1165 #[no_mangle]
1166 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1167 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1168         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1169 }
1170 #[no_mangle]
1171 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1172         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1173 }
1174 #[no_mangle]
1175 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1176 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1177         let res: Result<lightning::routing::network_graph::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1178         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() };
1179         local_res
1180 }
1181
1182 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1183 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1184
1185 /// Information received in the latest node_announcement from this node.
1186 #[must_use]
1187 #[repr(C)]
1188 pub struct NodeAnnouncementInfo {
1189         /// A pointer to the opaque Rust object.
1190
1191         /// Nearly everywhere, inner must be non-null, however in places where
1192         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1193         pub inner: *mut nativeNodeAnnouncementInfo,
1194         /// Indicates that this is the only struct which contains the same pointer.
1195
1196         /// Rust functions which take ownership of an object provided via an argument require
1197         /// this to be true and invalidate the object pointed to by inner.
1198         pub is_owned: bool,
1199 }
1200
1201 impl Drop for NodeAnnouncementInfo {
1202         fn drop(&mut self) {
1203                 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1204                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1205                 }
1206         }
1207 }
1208 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1209 #[no_mangle]
1210 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1211 #[allow(unused)]
1212 /// Used only if an object of this type is returned as a trait impl by a method
1213 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1214         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
1215 }
1216 #[allow(unused)]
1217 impl NodeAnnouncementInfo {
1218         pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1219                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1220         }
1221         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1222                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1223         }
1224         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1225         pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1226                 assert!(self.is_owned);
1227                 let ret = ObjOps::untweak_ptr(self.inner);
1228                 self.inner = core::ptr::null_mut();
1229                 ret
1230         }
1231 }
1232 /// Protocol features the node announced support for
1233 #[no_mangle]
1234 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1235         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1236         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 }
1237 }
1238 /// Protocol features the node announced support for
1239 #[no_mangle]
1240 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1241         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1242 }
1243 /// When the last known update to the node state was issued.
1244 /// Value is opaque, as set in the announcement.
1245 #[no_mangle]
1246 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1247         let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1248         *inner_val
1249 }
1250 /// When the last known update to the node state was issued.
1251 /// Value is opaque, as set in the announcement.
1252 #[no_mangle]
1253 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1254         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1255 }
1256 /// Color assigned to the node
1257 #[no_mangle]
1258 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1259         let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1260         inner_val
1261 }
1262 /// Color assigned to the node
1263 #[no_mangle]
1264 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1265         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1266 }
1267 /// Moniker assigned to the node.
1268 /// May be invalid or malicious (eg control chars),
1269 /// should not be exposed to the user.
1270 #[no_mangle]
1271 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
1272         let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1273         inner_val
1274 }
1275 /// Moniker assigned to the node.
1276 /// May be invalid or malicious (eg control chars),
1277 /// should not be exposed to the user.
1278 #[no_mangle]
1279 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
1280         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = val.data;
1281 }
1282 /// Internet-level addresses via which one can connect to the node
1283 #[no_mangle]
1284 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
1285         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
1286         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val;
1287 }
1288 /// An initial announcement of the node
1289 /// Mostly redundant with the data we store in fields explicitly.
1290 /// Everything else is useful only for sending out for initial routing sync.
1291 /// Not stored if contains excess data to prevent DoS.
1292 ///
1293 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1294 #[no_mangle]
1295 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1296         let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1297         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 };
1298         local_inner_val
1299 }
1300 /// An initial announcement of the node
1301 /// Mostly redundant with the data we store in fields explicitly.
1302 /// Everything else is useful only for sending out for initial routing sync.
1303 /// Not stored if contains excess data to prevent DoS.
1304 ///
1305 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1306 #[no_mangle]
1307 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1308         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1309         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1310 }
1311 /// Constructs a new NodeAnnouncementInfo given each field
1312 #[must_use]
1313 #[no_mangle]
1314 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 {
1315         let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
1316         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()) } }) };
1317         NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1318                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1319                 last_update: last_update_arg,
1320                 rgb: rgb_arg.data,
1321                 alias: alias_arg.data,
1322                 addresses: local_addresses_arg,
1323                 announcement_message: local_announcement_message_arg,
1324         }), is_owned: true }
1325 }
1326 impl Clone for NodeAnnouncementInfo {
1327         fn clone(&self) -> Self {
1328                 Self {
1329                         inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1330                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1331                         is_owned: true,
1332                 }
1333         }
1334 }
1335 #[allow(unused)]
1336 /// Used only if an object of this type is returned as a trait impl by a method
1337 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1338         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1339 }
1340 #[no_mangle]
1341 /// Creates a copy of the NodeAnnouncementInfo
1342 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1343         orig.clone()
1344 }
1345 #[no_mangle]
1346 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1347 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1348         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1349 }
1350 #[no_mangle]
1351 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1352         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1353 }
1354 #[no_mangle]
1355 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1356 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1357         let res: Result<lightning::routing::network_graph::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1358         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() };
1359         local_res
1360 }
1361
1362 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
1363 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1364
1365 /// Details about a node in the network, known from the network announcement.
1366 #[must_use]
1367 #[repr(C)]
1368 pub struct NodeInfo {
1369         /// A pointer to the opaque Rust object.
1370
1371         /// Nearly everywhere, inner must be non-null, however in places where
1372         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1373         pub inner: *mut nativeNodeInfo,
1374         /// Indicates that this is the only struct which contains the same pointer.
1375
1376         /// Rust functions which take ownership of an object provided via an argument require
1377         /// this to be true and invalidate the object pointed to by inner.
1378         pub is_owned: bool,
1379 }
1380
1381 impl Drop for NodeInfo {
1382         fn drop(&mut self) {
1383                 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1384                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1385                 }
1386         }
1387 }
1388 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1389 #[no_mangle]
1390 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1391 #[allow(unused)]
1392 /// Used only if an object of this type is returned as a trait impl by a method
1393 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1394         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1395 }
1396 #[allow(unused)]
1397 impl NodeInfo {
1398         pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1399                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1400         }
1401         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1402                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1403         }
1404         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1405         pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1406                 assert!(self.is_owned);
1407                 let ret = ObjOps::untweak_ptr(self.inner);
1408                 self.inner = core::ptr::null_mut();
1409                 ret
1410         }
1411 }
1412 /// All valid channels a node has announced
1413 #[no_mangle]
1414 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1415         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1416         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1417 }
1418 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1419 /// The two fields (flat and proportional fee) are independent,
1420 /// meaning they don't have to refer to the same channel.
1421 ///
1422 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1423 #[no_mangle]
1424 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::RoutingFees {
1425         let mut inner_val = &mut this_ptr.get_native_mut_ref().lowest_inbound_channel_fees;
1426         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 };
1427         local_inner_val
1428 }
1429 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1430 /// The two fields (flat and proportional fee) are independent,
1431 /// meaning they don't have to refer to the same channel.
1432 ///
1433 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1434 #[no_mangle]
1435 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
1436         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1437         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.lowest_inbound_channel_fees = local_val;
1438 }
1439 /// More information about a node from node_announcement.
1440 /// Optional because we store a Node entry after learning about it from
1441 /// a channel announcement, but before receiving a node announcement.
1442 ///
1443 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1444 #[no_mangle]
1445 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::NodeAnnouncementInfo {
1446         let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1447         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 };
1448         local_inner_val
1449 }
1450 /// More information about a node from node_announcement.
1451 /// Optional because we store a Node entry after learning about it from
1452 /// a channel announcement, but before receiving a node announcement.
1453 ///
1454 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1455 #[no_mangle]
1456 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::NodeAnnouncementInfo) {
1457         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1458         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1459 }
1460 /// Constructs a new NodeInfo given each field
1461 #[must_use]
1462 #[no_mangle]
1463 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 {
1464         let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1465         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()) } }) };
1466         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()) } }) };
1467         NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1468                 channels: local_channels_arg,
1469                 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1470                 announcement_info: local_announcement_info_arg,
1471         }), is_owned: true }
1472 }
1473 impl Clone for NodeInfo {
1474         fn clone(&self) -> Self {
1475                 Self {
1476                         inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1477                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1478                         is_owned: true,
1479                 }
1480         }
1481 }
1482 #[allow(unused)]
1483 /// Used only if an object of this type is returned as a trait impl by a method
1484 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1485         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1486 }
1487 #[no_mangle]
1488 /// Creates a copy of the NodeInfo
1489 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1490         orig.clone()
1491 }
1492 #[no_mangle]
1493 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1494 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1495         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1496 }
1497 #[no_mangle]
1498 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1499         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1500 }
1501 #[no_mangle]
1502 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1503 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1504         let res: Result<lightning::routing::network_graph::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1505         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() };
1506         local_res
1507 }
1508 #[no_mangle]
1509 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1510 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1511         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1512 }
1513 #[no_mangle]
1514 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1515         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1516 }
1517 #[no_mangle]
1518 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1519 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1520         let res: Result<lightning::routing::network_graph::NetworkGraph, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1521         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() };
1522         local_res
1523 }
1524 /// Creates a new, empty, network graph.
1525 #[must_use]
1526 #[no_mangle]
1527 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::lightning::routing::network_graph::NetworkGraph {
1528         let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1529         crate::lightning::routing::network_graph::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1530 }
1531
1532 /// Returns a read-only view of the network graph.
1533 #[must_use]
1534 #[no_mangle]
1535 pub extern "C" fn NetworkGraph_read_only(this_arg: &NetworkGraph) -> crate::lightning::routing::network_graph::ReadOnlyNetworkGraph {
1536         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
1537         crate::lightning::routing::network_graph::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1538 }
1539
1540 /// For an already known node (from channel announcements), update its stored properties from a
1541 /// given node announcement.
1542 ///
1543 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1544 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1545 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1546 #[must_use]
1547 #[no_mangle]
1548 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1549         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref(), secp256k1::SECP256K1);
1550         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() };
1551         local_ret
1552 }
1553
1554 /// For an already known node (from channel announcements), update its stored properties from a
1555 /// given node announcement without verifying the associated signatures. Because we aren't
1556 /// given the associated signatures here we cannot relay the node announcement to any of our
1557 /// peers.
1558 #[must_use]
1559 #[no_mangle]
1560 pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1561         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
1562         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() };
1563         local_ret
1564 }
1565
1566 /// Store or update channel info from a channel announcement.
1567 ///
1568 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1569 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1570 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1571 ///
1572 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1573 /// the corresponding UTXO exists on chain and is correctly-formatted.
1574 #[must_use]
1575 #[no_mangle]
1576 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1577         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() }) } };
1578         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_chain_access, secp256k1::SECP256K1);
1579         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() };
1580         local_ret
1581 }
1582
1583 /// Store or update channel info from a channel announcement without verifying the associated
1584 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1585 /// channel announcement to any of our peers.
1586 ///
1587 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1588 /// the corresponding UTXO exists on chain and is correctly-formatted.
1589 #[must_use]
1590 #[no_mangle]
1591 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1592         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() }) } };
1593         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_chain_access);
1594         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() };
1595         local_ret
1596 }
1597
1598 /// Close a channel if a corresponding HTLC fail was sent.
1599 /// If permanent, removes a channel from the local storage.
1600 /// May cause the removal of nodes too, if this was their last channel.
1601 /// If not permanent, makes channels unavailable for routing.
1602 #[no_mangle]
1603 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1604         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_from_update(short_channel_id, is_permanent)
1605 }
1606
1607 /// Marks a node in the graph as failed.
1608 #[no_mangle]
1609 pub extern "C" fn NetworkGraph_fail_node(this_arg: &NetworkGraph, mut _node_id: crate::c_types::PublicKey, mut is_permanent: bool) {
1610         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_node(&_node_id.into_rust(), is_permanent)
1611 }
1612
1613 /// Removes information about channels that we haven't heard any updates about in some time.
1614 /// This can be used regularly to prune the network graph of channels that likely no longer
1615 /// exist.
1616 ///
1617 /// While there is no formal requirement that nodes regularly re-broadcast their channel
1618 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
1619 /// pruning occur for updates which are at least two weeks old, which we implement here.
1620 ///
1621 /// This function takes the current unix time as an argument. For users with the `std` feature
1622 /// enabled, [`NetworkGraph::remove_stale_channels`] may be preferable.
1623 #[no_mangle]
1624 pub extern "C" fn NetworkGraph_remove_stale_channels_with_time(this_arg: &NetworkGraph, mut current_time_unix: u64) {
1625         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_with_time(current_time_unix)
1626 }
1627
1628 /// For an already known (from announcement) channel, update info about one of the directions
1629 /// of the channel.
1630 ///
1631 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1632 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1633 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1634 ///
1635 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1636 /// materially in the future will be rejected.
1637 #[must_use]
1638 #[no_mangle]
1639 pub extern "C" fn NetworkGraph_update_channel(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1640         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref(), secp256k1::SECP256K1);
1641         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() };
1642         local_ret
1643 }
1644
1645 /// For an already known (from announcement) channel, update info about one of the directions
1646 /// of the channel without verifying the associated signatures. Because we aren't given the
1647 /// associated signatures here we cannot relay the channel update to any of our peers.
1648 ///
1649 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1650 /// materially in the future will be rejected.
1651 #[must_use]
1652 #[no_mangle]
1653 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1654         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
1655         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() };
1656         local_ret
1657 }
1658
1659 /// Get network addresses by node id.
1660 /// Returns None if the requested node is completely unknown,
1661 /// or if node announcement for the node was never received.
1662 #[must_use]
1663 #[no_mangle]
1664 pub extern "C" fn ReadOnlyNetworkGraph_get_addresses(this_arg: &ReadOnlyNetworkGraph, mut pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::COption_CVec_NetAddressZZ {
1665         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust());
1666         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() }) };
1667         local_ret
1668 }
1669