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