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