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