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