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