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