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