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