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