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