1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! The [`NetworkGraph`] stores the network gossip and [`P2PGossipSync`] fetches it from peers
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
21 use lightning::routing::gossip::NodeId as nativeNodeIdImport;
22 pub(crate) type nativeNodeId = nativeNodeIdImport;
24 /// Represents the compressed public key of a node
28 /// A pointer to the opaque Rust object.
30 /// Nearly everywhere, inner must be non-null, however in places where
31 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
32 pub inner: *mut nativeNodeId,
33 /// Indicates that this is the only struct which contains the same pointer.
35 /// Rust functions which take ownership of an object provided via an argument require
36 /// this to be true and invalidate the object pointed to by inner.
40 impl Drop for NodeId {
42 if self.is_owned && !<*mut nativeNodeId>::is_null(self.inner) {
43 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
47 /// Frees any resources used by the NodeId, if is_owned is set and inner is non-NULL.
49 pub extern "C" fn NodeId_free(this_obj: NodeId) { }
51 /// Used only if an object of this type is returned as a trait impl by a method
52 pub(crate) extern "C" fn NodeId_free_void(this_ptr: *mut c_void) {
53 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeId) };
57 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeId {
58 unsafe { &*ObjOps::untweak_ptr(self.inner) }
60 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeId {
61 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
63 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
64 pub(crate) fn take_inner(mut self) -> *mut nativeNodeId {
65 assert!(self.is_owned);
66 let ret = ObjOps::untweak_ptr(self.inner);
67 self.inner = core::ptr::null_mut();
71 impl Clone for NodeId {
72 fn clone(&self) -> Self {
74 inner: if <*mut nativeNodeId>::is_null(self.inner) { core::ptr::null_mut() } else {
75 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
81 /// Used only if an object of this type is returned as a trait impl by a method
82 pub(crate) extern "C" fn NodeId_clone_void(this_ptr: *const c_void) -> *mut c_void {
83 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeId)).clone() })) as *mut c_void
86 /// Creates a copy of the NodeId
87 pub extern "C" fn NodeId_clone(orig: &NodeId) -> NodeId {
90 /// Create a new NodeId from a public key
93 pub extern "C" fn NodeId_from_pubkey(mut pubkey: crate::c_types::PublicKey) -> crate::lightning::routing::gossip::NodeId {
94 let mut ret = lightning::routing::gossip::NodeId::from_pubkey(&pubkey.into_rust());
95 crate::lightning::routing::gossip::NodeId { inner: ObjOps::heap_alloc(ret), is_owned: true }
98 /// Create a new NodeId from a slice of bytes
101 pub extern "C" fn NodeId_from_slice(mut bytes: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ {
102 let mut ret = lightning::routing::gossip::NodeId::from_slice(bytes.to_slice());
103 let mut local_ret = match ret { 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() };
107 /// Get the public key slice from this NodeId
110 pub extern "C" fn NodeId_as_slice(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::u8slice {
111 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_slice();
112 let mut local_ret = crate::c_types::u8slice::from_slice(ret);
116 /// Get the public key as an array from this NodeId
119 pub extern "C" fn NodeId_as_array(this_arg: &crate::lightning::routing::gossip::NodeId) -> *const [u8; 33] {
120 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_array();
124 /// Get the public key from this NodeId
127 pub extern "C" fn NodeId_as_pubkey(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CResult_PublicKeySecp256k1ErrorZ {
128 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_pubkey();
129 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() };
133 /// Get a string which allows debug introspection of a NodeId object
134 pub extern "C" fn NodeId_debug_str_void(o: *const c_void) -> Str {
135 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeId }).into()}
136 /// Generates a non-cryptographic 64-bit hash of the NodeId.
138 pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 {
139 if o.inner.is_null() { return 0; }
140 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
142 let mut hasher = core::hash::SipHasher::new();
143 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
144 core::hash::Hasher::finish(&hasher)
147 /// Serialize the NodeId object into a byte array which can be read by NodeId_read
148 pub extern "C" fn NodeId_write(obj: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CVec_u8Z {
149 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
152 pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
153 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) })
156 /// Read a NodeId from a byte array, created by NodeId_write
157 pub extern "C" fn NodeId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ {
158 let res: Result<lightning::routing::gossip::NodeId, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
159 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() };
163 use lightning::routing::gossip::NetworkGraph as nativeNetworkGraphImport;
164 pub(crate) type nativeNetworkGraph = nativeNetworkGraphImport<crate::lightning::util::logger::Logger, >;
166 /// Represents the network as nodes and channels between them
169 pub struct NetworkGraph {
170 /// A pointer to the opaque Rust object.
172 /// Nearly everywhere, inner must be non-null, however in places where
173 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
174 pub inner: *mut nativeNetworkGraph,
175 /// Indicates that this is the only struct which contains the same pointer.
177 /// Rust functions which take ownership of an object provided via an argument require
178 /// this to be true and invalidate the object pointed to by inner.
182 impl Drop for NetworkGraph {
184 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
185 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
189 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
191 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
193 /// Used only if an object of this type is returned as a trait impl by a method
194 pub(crate) extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
195 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNetworkGraph) };
199 pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
200 unsafe { &*ObjOps::untweak_ptr(self.inner) }
202 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
203 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
205 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
206 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
207 assert!(self.is_owned);
208 let ret = ObjOps::untweak_ptr(self.inner);
209 self.inner = core::ptr::null_mut();
214 use lightning::routing::gossip::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
215 pub(crate) type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static, >;
217 /// A read-only view of [`NetworkGraph`].
220 pub struct ReadOnlyNetworkGraph {
221 /// A pointer to the opaque Rust object.
223 /// Nearly everywhere, inner must be non-null, however in places where
224 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
225 pub inner: *mut nativeReadOnlyNetworkGraph,
226 /// Indicates that this is the only struct which contains the same pointer.
228 /// Rust functions which take ownership of an object provided via an argument require
229 /// this to be true and invalidate the object pointed to by inner.
233 impl Drop for ReadOnlyNetworkGraph {
235 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
236 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
240 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
242 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
244 /// Used only if an object of this type is returned as a trait impl by a method
245 pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
246 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph) };
249 impl ReadOnlyNetworkGraph {
250 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
251 unsafe { &*ObjOps::untweak_ptr(self.inner) }
253 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
254 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
256 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
257 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
258 assert!(self.is_owned);
259 let ret = ObjOps::untweak_ptr(self.inner);
260 self.inner = core::ptr::null_mut();
264 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
265 /// return packet by a node along the route. See [BOLT #4] for details.
267 /// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
271 pub enum NetworkUpdate {
272 /// An error indicating a `channel_update` messages should be applied via
273 /// [`NetworkGraph::update_channel`].
274 ChannelUpdateMessage {
275 /// The update to apply via [`NetworkGraph::update_channel`].
276 msg: crate::lightning::ln::msgs::ChannelUpdate,
278 /// An error indicating that a channel failed to route a payment, which should be applied via
279 /// [`NetworkGraph::channel_failed_permanent`] if permanent.
281 /// The short channel id of the closed channel.
282 short_channel_id: u64,
283 /// Whether the channel should be permanently removed or temporarily disabled until a new
284 /// `channel_update` message is received.
287 /// An error indicating that a node failed to route a payment, which should be applied via
288 /// [`NetworkGraph::node_failed_permanent`] if permanent.
290 /// The node id of the failed node.
291 node_id: crate::c_types::PublicKey,
292 /// Whether the node should be permanently removed from consideration or can be restored
293 /// when a new `channel_update` message is received.
297 use lightning::routing::gossip::NetworkUpdate as NetworkUpdateImport;
298 pub(crate) type nativeNetworkUpdate = NetworkUpdateImport;
302 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
304 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
305 let mut msg_nonref = Clone::clone(msg);
306 nativeNetworkUpdate::ChannelUpdateMessage {
307 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
310 NetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
311 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
312 let mut is_permanent_nonref = Clone::clone(is_permanent);
313 nativeNetworkUpdate::ChannelFailure {
314 short_channel_id: short_channel_id_nonref,
315 is_permanent: is_permanent_nonref,
318 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
319 let mut node_id_nonref = Clone::clone(node_id);
320 let mut is_permanent_nonref = Clone::clone(is_permanent);
321 nativeNetworkUpdate::NodeFailure {
322 node_id: node_id_nonref.into_rust(),
323 is_permanent: is_permanent_nonref,
329 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
331 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
332 nativeNetworkUpdate::ChannelUpdateMessage {
333 msg: *unsafe { Box::from_raw(msg.take_inner()) },
336 NetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
337 nativeNetworkUpdate::ChannelFailure {
338 short_channel_id: short_channel_id,
339 is_permanent: is_permanent,
342 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
343 nativeNetworkUpdate::NodeFailure {
344 node_id: node_id.into_rust(),
345 is_permanent: is_permanent,
351 pub(crate) fn from_native(native: &NetworkUpdateImport) -> Self {
352 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeNetworkUpdate) };
354 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
355 let mut msg_nonref = Clone::clone(msg);
356 NetworkUpdate::ChannelUpdateMessage {
357 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
360 nativeNetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
361 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
362 let mut is_permanent_nonref = Clone::clone(is_permanent);
363 NetworkUpdate::ChannelFailure {
364 short_channel_id: short_channel_id_nonref,
365 is_permanent: is_permanent_nonref,
368 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
369 let mut node_id_nonref = Clone::clone(node_id);
370 let mut is_permanent_nonref = Clone::clone(is_permanent);
371 NetworkUpdate::NodeFailure {
372 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
373 is_permanent: is_permanent_nonref,
379 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
381 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
382 NetworkUpdate::ChannelUpdateMessage {
383 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
386 nativeNetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
387 NetworkUpdate::ChannelFailure {
388 short_channel_id: short_channel_id,
389 is_permanent: is_permanent,
392 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
393 NetworkUpdate::NodeFailure {
394 node_id: crate::c_types::PublicKey::from_rust(&node_id),
395 is_permanent: is_permanent,
401 /// Frees any resources used by the NetworkUpdate
403 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
404 /// Creates a copy of the NetworkUpdate
406 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
410 /// Used only if an object of this type is returned as a trait impl by a method
411 pub(crate) extern "C" fn NetworkUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
412 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const NetworkUpdate)).clone() })) as *mut c_void
415 /// Used only if an object of this type is returned as a trait impl by a method
416 pub(crate) extern "C" fn NetworkUpdate_free_void(this_ptr: *mut c_void) {
417 let _ = unsafe { Box::from_raw(this_ptr as *mut NetworkUpdate) };
420 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
421 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
422 NetworkUpdate::ChannelUpdateMessage {
427 /// Utility method to constructs a new ChannelFailure-variant NetworkUpdate
428 pub extern "C" fn NetworkUpdate_channel_failure(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
429 NetworkUpdate::ChannelFailure {
435 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
436 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
437 NetworkUpdate::NodeFailure {
442 /// Get a string which allows debug introspection of a NetworkUpdate object
443 pub extern "C" fn NetworkUpdate_debug_str_void(o: *const c_void) -> Str {
444 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NetworkUpdate }).into()}
445 /// Checks if two NetworkUpdates contain equal inner contents.
446 /// This ignores pointers and is_owned flags and looks at the values in fields.
448 pub extern "C" fn NetworkUpdate_eq(a: &NetworkUpdate, b: &NetworkUpdate) -> bool {
449 if &a.to_native() == &b.to_native() { true } else { false }
452 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
453 pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::gossip::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
454 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
457 pub(crate) extern "C" fn NetworkUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
458 NetworkUpdate_write(unsafe { &*(obj as *const NetworkUpdate) })
461 /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
462 pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ {
463 let res: Result<Option<lightning::routing::gossip::NetworkUpdate>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
464 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() };
468 use lightning::routing::gossip::P2PGossipSync as nativeP2PGossipSyncImport;
469 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, >;
471 /// Receives and validates network updates from peers,
472 /// stores authentic and relevant data as a network graph.
473 /// This network graph is then used for routing payments.
474 /// Provides interface to help with initial routing sync by
475 /// serving historical announcements.
478 pub struct P2PGossipSync {
479 /// A pointer to the opaque Rust object.
481 /// Nearly everywhere, inner must be non-null, however in places where
482 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
483 pub inner: *mut nativeP2PGossipSync,
484 /// Indicates that this is the only struct which contains the same pointer.
486 /// Rust functions which take ownership of an object provided via an argument require
487 /// this to be true and invalidate the object pointed to by inner.
491 impl Drop for P2PGossipSync {
493 if self.is_owned && !<*mut nativeP2PGossipSync>::is_null(self.inner) {
494 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
498 /// Frees any resources used by the P2PGossipSync, if is_owned is set and inner is non-NULL.
500 pub extern "C" fn P2PGossipSync_free(this_obj: P2PGossipSync) { }
502 /// Used only if an object of this type is returned as a trait impl by a method
503 pub(crate) extern "C" fn P2PGossipSync_free_void(this_ptr: *mut c_void) {
504 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeP2PGossipSync) };
508 pub(crate) fn get_native_ref(&self) -> &'static nativeP2PGossipSync {
509 unsafe { &*ObjOps::untweak_ptr(self.inner) }
511 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeP2PGossipSync {
512 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
514 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
515 pub(crate) fn take_inner(mut self) -> *mut nativeP2PGossipSync {
516 assert!(self.is_owned);
517 let ret = ObjOps::untweak_ptr(self.inner);
518 self.inner = core::ptr::null_mut();
522 /// Creates a new tracker of the actual state of the network of channels and nodes,
523 /// assuming an existing [`NetworkGraph`].
524 /// UTXO lookup is used to make sure announced channels exist on-chain, channel data is
525 /// correct, and the announcement is signed with channel owners' keys.
528 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 {
529 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() } }})} };
530 let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_utxo_lookup, logger);
531 crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(ret), is_owned: true }
534 /// Adds a provider used to check new announcements. Does not affect
535 /// existing announcements unless they are updated.
536 /// Add, update or remove the provider would replace the current one.
538 pub extern "C" fn P2PGossipSync_add_utxo_lookup(this_arg: &crate::lightning::routing::gossip::P2PGossipSync, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) {
539 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() } }})} };
540 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.add_utxo_lookup(local_utxo_lookup)
543 /// Handles any network updates originating from [`Event`]s.
544 /// Note that this will skip applying any [`NetworkUpdate::ChannelUpdateMessage`] to avoid
545 /// leaking possibly identifying information of the sender to the public network.
547 /// [`Event`]: crate::events::Event
549 pub extern "C" fn NetworkGraph_handle_network_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, network_update: &crate::lightning::routing::gossip::NetworkUpdate) {
550 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_network_update(&network_update.to_native())
553 /// Gets the chain hash for this network graph.
556 pub extern "C" fn NetworkGraph_get_chain_hash(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::ThirtyTwoBytes {
557 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_chain_hash();
558 crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
561 /// Verifies the signature of a [`NodeAnnouncement`].
563 /// Returns an error if it is invalid.
565 pub extern "C" fn verify_node_announcement(msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
566 let mut ret = lightning::routing::gossip::verify_node_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1);
567 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
571 /// Verifies all signatures included in a [`ChannelAnnouncement`].
573 /// Returns an error if one of the signatures is invalid.
575 pub extern "C" fn verify_channel_announcement(msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
576 let mut ret = lightning::routing::gossip::verify_channel_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1);
577 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() };
581 impl From<nativeP2PGossipSync> for crate::lightning::ln::msgs::RoutingMessageHandler {
582 fn from(obj: nativeP2PGossipSync) -> Self {
583 let rust_obj = crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
584 let mut ret = P2PGossipSync_as_RoutingMessageHandler(&rust_obj);
585 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
586 core::mem::forget(rust_obj);
587 ret.free = Some(P2PGossipSync_free_void);
591 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
592 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
594 pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSync) -> crate::lightning::ln::msgs::RoutingMessageHandler {
595 crate::lightning::ln::msgs::RoutingMessageHandler {
596 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
598 handle_node_announcement: P2PGossipSync_RoutingMessageHandler_handle_node_announcement,
599 handle_channel_announcement: P2PGossipSync_RoutingMessageHandler_handle_channel_announcement,
600 handle_channel_update: P2PGossipSync_RoutingMessageHandler_handle_channel_update,
601 get_next_channel_announcement: P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement,
602 get_next_node_announcement: P2PGossipSync_RoutingMessageHandler_get_next_node_announcement,
603 peer_connected: P2PGossipSync_RoutingMessageHandler_peer_connected,
604 handle_reply_channel_range: P2PGossipSync_RoutingMessageHandler_handle_reply_channel_range,
605 handle_reply_short_channel_ids_end: P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end,
606 handle_query_channel_range: P2PGossipSync_RoutingMessageHandler_handle_query_channel_range,
607 handle_query_short_channel_ids: P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids,
608 processing_queue_high: P2PGossipSync_RoutingMessageHandler_processing_queue_high,
609 provided_node_features: P2PGossipSync_RoutingMessageHandler_provided_node_features,
610 provided_init_features: P2PGossipSync_RoutingMessageHandler_provided_init_features,
611 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
612 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
614 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
620 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 {
621 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
622 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() };
626 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 {
627 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
628 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() };
632 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 {
633 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
634 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() };
638 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 {
639 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, starting_point);
640 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 }) };
644 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 {
645 let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
646 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, local_starting_point);
647 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 };
651 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 {
652 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);
653 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() };
657 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 {
658 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()) });
659 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() };
663 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 {
664 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()) });
665 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() };
669 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 {
670 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()) });
671 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() };
675 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 {
676 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()) });
677 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() };
681 extern "C" fn P2PGossipSync_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
682 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
686 extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
687 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
688 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
691 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 {
692 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust());
693 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
696 impl From<nativeP2PGossipSync> for crate::lightning::events::MessageSendEventsProvider {
697 fn from(obj: nativeP2PGossipSync) -> Self {
698 let rust_obj = crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
699 let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj);
700 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
701 core::mem::forget(rust_obj);
702 ret.free = Some(P2PGossipSync_free_void);
706 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
707 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
709 pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::events::MessageSendEventsProvider {
710 crate::lightning::events::MessageSendEventsProvider {
711 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
713 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
718 extern "C" fn P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
719 let mut ret = <nativeP2PGossipSync as lightning::events::MessageSendEventsProvider>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
720 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
725 use lightning::routing::gossip::ChannelUpdateInfo as nativeChannelUpdateInfoImport;
726 pub(crate) type nativeChannelUpdateInfo = nativeChannelUpdateInfoImport;
728 /// Details about one direction of a channel as received within a [`ChannelUpdate`].
731 pub struct ChannelUpdateInfo {
732 /// A pointer to the opaque Rust object.
734 /// Nearly everywhere, inner must be non-null, however in places where
735 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
736 pub inner: *mut nativeChannelUpdateInfo,
737 /// Indicates that this is the only struct which contains the same pointer.
739 /// Rust functions which take ownership of an object provided via an argument require
740 /// this to be true and invalidate the object pointed to by inner.
744 impl Drop for ChannelUpdateInfo {
746 if self.is_owned && !<*mut nativeChannelUpdateInfo>::is_null(self.inner) {
747 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
751 /// Frees any resources used by the ChannelUpdateInfo, if is_owned is set and inner is non-NULL.
753 pub extern "C" fn ChannelUpdateInfo_free(this_obj: ChannelUpdateInfo) { }
755 /// Used only if an object of this type is returned as a trait impl by a method
756 pub(crate) extern "C" fn ChannelUpdateInfo_free_void(this_ptr: *mut c_void) {
757 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo) };
760 impl ChannelUpdateInfo {
761 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUpdateInfo {
762 unsafe { &*ObjOps::untweak_ptr(self.inner) }
764 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUpdateInfo {
765 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
767 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
768 pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdateInfo {
769 assert!(self.is_owned);
770 let ret = ObjOps::untweak_ptr(self.inner);
771 self.inner = core::ptr::null_mut();
775 /// When the last update to the channel direction was issued.
776 /// Value is opaque, as set in the announcement.
778 pub extern "C" fn ChannelUpdateInfo_get_last_update(this_ptr: &ChannelUpdateInfo) -> u32 {
779 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
782 /// When the last update to the channel direction was issued.
783 /// Value is opaque, as set in the announcement.
785 pub extern "C" fn ChannelUpdateInfo_set_last_update(this_ptr: &mut ChannelUpdateInfo, mut val: u32) {
786 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
788 /// Whether the channel can be currently used for payments (in this one direction).
790 pub extern "C" fn ChannelUpdateInfo_get_enabled(this_ptr: &ChannelUpdateInfo) -> bool {
791 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
794 /// Whether the channel can be currently used for payments (in this one direction).
796 pub extern "C" fn ChannelUpdateInfo_set_enabled(this_ptr: &mut ChannelUpdateInfo, mut val: bool) {
797 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
799 /// The difference in CLTV values that you must have when routing through this channel.
801 pub extern "C" fn ChannelUpdateInfo_get_cltv_expiry_delta(this_ptr: &ChannelUpdateInfo) -> u16 {
802 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
805 /// The difference in CLTV values that you must have when routing through this channel.
807 pub extern "C" fn ChannelUpdateInfo_set_cltv_expiry_delta(this_ptr: &mut ChannelUpdateInfo, mut val: u16) {
808 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
810 /// The minimum value, which must be relayed to the next hop via the channel
812 pub extern "C" fn ChannelUpdateInfo_get_htlc_minimum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
813 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
816 /// The minimum value, which must be relayed to the next hop via the channel
818 pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
819 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
821 /// The maximum value which may be relayed to the next hop via the channel.
823 pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
824 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
827 /// The maximum value which may be relayed to the next hop via the channel.
829 pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
830 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
832 /// Fees charged when the channel is used for routing
834 pub extern "C" fn ChannelUpdateInfo_get_fees(this_ptr: &ChannelUpdateInfo) -> crate::lightning::routing::gossip::RoutingFees {
835 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
836 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 }
838 /// Fees charged when the channel is used for routing
840 pub extern "C" fn ChannelUpdateInfo_set_fees(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::routing::gossip::RoutingFees) {
841 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
843 /// Most recent update for the channel received from the network
844 /// Mostly redundant with the data we store in fields explicitly.
845 /// Everything else is useful only for sending out for initial routing sync.
846 /// Not stored if contains excess data to prevent DoS.
848 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
850 pub extern "C" fn ChannelUpdateInfo_get_last_update_message(this_ptr: &ChannelUpdateInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
851 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
852 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 };
855 /// Most recent update for the channel received from the network
856 /// Mostly redundant with the data we store in fields explicitly.
857 /// Everything else is useful only for sending out for initial routing sync.
858 /// Not stored if contains excess data to prevent DoS.
860 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
862 pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
863 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
864 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
866 /// Constructs a new ChannelUpdateInfo given each field
868 /// Note that last_update_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
871 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 {
872 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()) } }) };
873 ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo {
874 last_update: last_update_arg,
875 enabled: enabled_arg,
876 cltv_expiry_delta: cltv_expiry_delta_arg,
877 htlc_minimum_msat: htlc_minimum_msat_arg,
878 htlc_maximum_msat: htlc_maximum_msat_arg,
879 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
880 last_update_message: local_last_update_message_arg,
883 impl Clone for ChannelUpdateInfo {
884 fn clone(&self) -> Self {
886 inner: if <*mut nativeChannelUpdateInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
887 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
893 /// Used only if an object of this type is returned as a trait impl by a method
894 pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
895 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelUpdateInfo)).clone() })) as *mut c_void
898 /// Creates a copy of the ChannelUpdateInfo
899 pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo {
902 /// Get a string which allows debug introspection of a ChannelUpdateInfo object
903 pub extern "C" fn ChannelUpdateInfo_debug_str_void(o: *const c_void) -> Str {
904 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::ChannelUpdateInfo }).into()}
905 /// Checks if two ChannelUpdateInfos contain equal inner contents.
906 /// This ignores pointers and is_owned flags and looks at the values in fields.
907 /// Two objects with NULL inner values will be considered "equal" here.
909 pub extern "C" fn ChannelUpdateInfo_eq(a: &ChannelUpdateInfo, b: &ChannelUpdateInfo) -> bool {
910 if a.inner == b.inner { return true; }
911 if a.inner.is_null() || b.inner.is_null() { return false; }
912 if a.get_native_ref() == b.get_native_ref() { true } else { false }
915 /// Serialize the ChannelUpdateInfo object into a byte array which can be read by ChannelUpdateInfo_read
916 pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::gossip::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z {
917 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
920 pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
921 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) })
924 /// Read a ChannelUpdateInfo from a byte array, created by ChannelUpdateInfo_write
925 pub extern "C" fn ChannelUpdateInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateInfoDecodeErrorZ {
926 let res: Result<lightning::routing::gossip::ChannelUpdateInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
927 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() };
931 use lightning::routing::gossip::ChannelInfo as nativeChannelInfoImport;
932 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
934 /// Details about a channel (both directions).
935 /// Received within a channel announcement.
938 pub struct ChannelInfo {
939 /// A pointer to the opaque Rust object.
941 /// Nearly everywhere, inner must be non-null, however in places where
942 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
943 pub inner: *mut nativeChannelInfo,
944 /// Indicates that this is the only struct which contains the same pointer.
946 /// Rust functions which take ownership of an object provided via an argument require
947 /// this to be true and invalidate the object pointed to by inner.
951 impl Drop for ChannelInfo {
953 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
954 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
958 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
960 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
962 /// Used only if an object of this type is returned as a trait impl by a method
963 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
964 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelInfo) };
968 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
969 unsafe { &*ObjOps::untweak_ptr(self.inner) }
971 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
972 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
974 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
975 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
976 assert!(self.is_owned);
977 let ret = ObjOps::untweak_ptr(self.inner);
978 self.inner = core::ptr::null_mut();
982 /// Protocol features of a channel communicated during its announcement
984 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
985 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
986 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 }
988 /// Protocol features of a channel communicated during its announcement
990 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
991 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
993 /// Source node of the first direction of a channel
995 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
996 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
997 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 }
999 /// Source node of the first direction of a channel
1001 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
1002 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
1004 /// Details about the first direction of a channel
1006 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1008 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1009 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
1010 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 };
1013 /// Details about the first direction of a channel
1015 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1017 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
1018 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1019 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
1021 /// Source node of the second direction of a channel
1023 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
1024 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
1025 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 }
1027 /// Source node of the second direction of a channel
1029 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
1030 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
1032 /// Details about the second direction of a channel
1034 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1036 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1037 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
1038 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 };
1041 /// Details about the second direction of a channel
1043 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1045 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
1046 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1047 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
1049 /// The channel capacity as seen on-chain, if chain lookup is available.
1051 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
1052 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
1053 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() }) };
1056 /// The channel capacity as seen on-chain, if chain lookup is available.
1058 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
1059 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1060 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
1062 /// An initial announcement of the channel
1063 /// Mostly redundant with the data we store in fields explicitly.
1064 /// Everything else is useful only for sending out for initial routing sync.
1065 /// Not stored if contains excess data to prevent DoS.
1067 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1069 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
1070 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1071 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 };
1074 /// An initial announcement of the channel
1075 /// Mostly redundant with the data we store in fields explicitly.
1076 /// Everything else is useful only for sending out for initial routing sync.
1077 /// Not stored if contains excess data to prevent DoS.
1079 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1081 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
1082 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1083 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1085 impl Clone for ChannelInfo {
1086 fn clone(&self) -> Self {
1088 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1089 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1095 /// Used only if an object of this type is returned as a trait impl by a method
1096 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1097 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelInfo)).clone() })) as *mut c_void
1100 /// Creates a copy of the ChannelInfo
1101 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1104 /// Get a string which allows debug introspection of a ChannelInfo object
1105 pub extern "C" fn ChannelInfo_debug_str_void(o: *const c_void) -> Str {
1106 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::ChannelInfo }).into()}
1107 /// Checks if two ChannelInfos contain equal inner contents.
1108 /// This ignores pointers and is_owned flags and looks at the values in fields.
1109 /// Two objects with NULL inner values will be considered "equal" here.
1111 pub extern "C" fn ChannelInfo_eq(a: &ChannelInfo, b: &ChannelInfo) -> bool {
1112 if a.inner == b.inner { return true; }
1113 if a.inner.is_null() || b.inner.is_null() { return false; }
1114 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1116 /// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
1118 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1121 pub extern "C" fn ChannelInfo_get_directional_info(this_arg: &crate::lightning::routing::gossip::ChannelInfo, mut channel_flags: u8) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1122 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_directional_info(channel_flags);
1123 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 };
1128 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1129 pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::gossip::ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1130 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1133 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1134 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1137 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1138 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1139 let res: Result<lightning::routing::gossip::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1140 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() };
1144 use lightning::routing::gossip::DirectedChannelInfo as nativeDirectedChannelInfoImport;
1145 pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static, >;
1147 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
1148 /// source node to a target node.
1151 pub struct DirectedChannelInfo {
1152 /// A pointer to the opaque Rust object.
1154 /// Nearly everywhere, inner must be non-null, however in places where
1155 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1156 pub inner: *mut nativeDirectedChannelInfo,
1157 /// Indicates that this is the only struct which contains the same pointer.
1159 /// Rust functions which take ownership of an object provided via an argument require
1160 /// this to be true and invalidate the object pointed to by inner.
1164 impl Drop for DirectedChannelInfo {
1165 fn drop(&mut self) {
1166 if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
1167 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1171 /// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
1173 pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
1175 /// Used only if an object of this type is returned as a trait impl by a method
1176 pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
1177 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo) };
1180 impl DirectedChannelInfo {
1181 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
1182 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1184 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
1185 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1187 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1188 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelInfo {
1189 assert!(self.is_owned);
1190 let ret = ObjOps::untweak_ptr(self.inner);
1191 self.inner = core::ptr::null_mut();
1195 impl Clone for DirectedChannelInfo {
1196 fn clone(&self) -> Self {
1198 inner: if <*mut nativeDirectedChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1199 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1205 /// Used only if an object of this type is returned as a trait impl by a method
1206 pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1207 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDirectedChannelInfo)).clone() })) as *mut c_void
1210 /// Creates a copy of the DirectedChannelInfo
1211 pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
1214 /// Returns information for the channel.
1217 pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::ChannelInfo {
1218 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
1219 crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::ChannelInfo<>) as *mut _) }, is_owned: false }
1222 /// Returns the [`EffectiveCapacity`] of the channel in the direction.
1224 /// This is either the total capacity from the funding transaction, if known, or the
1225 /// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
1229 pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::EffectiveCapacity {
1230 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
1231 crate::lightning::routing::gossip::EffectiveCapacity::native_into(ret)
1234 /// Returns the `node_id` of the source hop.
1236 /// Refers to the `node_id` forwarding the payment to the next hop.
1239 pub extern "C" fn DirectedChannelInfo_source(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::NodeId {
1240 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.source();
1241 crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false }
1244 /// Returns the `node_id` of the target hop.
1246 /// Refers to the `node_id` receiving the payment from the previous hop.
1249 pub extern "C" fn DirectedChannelInfo_target(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::NodeId {
1250 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.target();
1251 crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false }
1254 /// Get a string which allows debug introspection of a DirectedChannelInfo object
1255 pub extern "C" fn DirectedChannelInfo_debug_str_void(o: *const c_void) -> Str {
1256 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::DirectedChannelInfo }).into()}
1257 /// The effective capacity of a channel for routing purposes.
1259 /// While this may be smaller than the actual channel capacity, amounts greater than
1260 /// [`Self::as_msat`] should not be routed through the channel.
1264 pub enum EffectiveCapacity {
1265 /// The available liquidity in the channel known from being a channel counterparty, and thus a
1268 /// Either the inbound or outbound liquidity depending on the direction, denominated in
1270 liquidity_msat: u64,
1272 /// The maximum HTLC amount in one direction as advertised on the gossip network.
1274 /// The maximum HTLC amount denominated in millisatoshi.
1277 /// The total capacity of the channel as determined by the funding transaction.
1279 /// The funding amount denominated in millisatoshi.
1281 /// The maximum HTLC amount denominated in millisatoshi.
1282 htlc_maximum_msat: u64,
1284 /// A capacity sufficient to route any payment, typically used for private channels provided by
1287 /// The maximum HTLC amount as provided by an invoice route hint.
1289 /// The maximum HTLC amount denominated in millisatoshi.
1292 /// A capacity that is unknown possibly because either the chain state is unavailable to know
1293 /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
1296 use lightning::routing::gossip::EffectiveCapacity as EffectiveCapacityImport;
1297 pub(crate) type nativeEffectiveCapacity = EffectiveCapacityImport;
1299 impl EffectiveCapacity {
1301 pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
1303 EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1304 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1305 nativeEffectiveCapacity::ExactLiquidity {
1306 liquidity_msat: liquidity_msat_nonref,
1309 EffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => {
1310 let mut amount_msat_nonref = Clone::clone(amount_msat);
1311 nativeEffectiveCapacity::AdvertisedMaxHTLC {
1312 amount_msat: amount_msat_nonref,
1315 EffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1316 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1317 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1318 nativeEffectiveCapacity::Total {
1319 capacity_msat: capacity_msat_nonref,
1320 htlc_maximum_msat: htlc_maximum_msat_nonref,
1323 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1324 EffectiveCapacity::HintMaxHTLC {ref amount_msat, } => {
1325 let mut amount_msat_nonref = Clone::clone(amount_msat);
1326 nativeEffectiveCapacity::HintMaxHTLC {
1327 amount_msat: amount_msat_nonref,
1330 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1334 pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
1336 EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1337 nativeEffectiveCapacity::ExactLiquidity {
1338 liquidity_msat: liquidity_msat,
1341 EffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => {
1342 nativeEffectiveCapacity::AdvertisedMaxHTLC {
1343 amount_msat: amount_msat,
1346 EffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1347 nativeEffectiveCapacity::Total {
1348 capacity_msat: capacity_msat,
1349 htlc_maximum_msat: htlc_maximum_msat,
1352 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1353 EffectiveCapacity::HintMaxHTLC {mut amount_msat, } => {
1354 nativeEffectiveCapacity::HintMaxHTLC {
1355 amount_msat: amount_msat,
1358 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1362 pub(crate) fn from_native(native: &EffectiveCapacityImport) -> Self {
1363 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeEffectiveCapacity) };
1365 nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1366 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1367 EffectiveCapacity::ExactLiquidity {
1368 liquidity_msat: liquidity_msat_nonref,
1371 nativeEffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => {
1372 let mut amount_msat_nonref = Clone::clone(amount_msat);
1373 EffectiveCapacity::AdvertisedMaxHTLC {
1374 amount_msat: amount_msat_nonref,
1377 nativeEffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1378 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1379 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1380 EffectiveCapacity::Total {
1381 capacity_msat: capacity_msat_nonref,
1382 htlc_maximum_msat: htlc_maximum_msat_nonref,
1385 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1386 nativeEffectiveCapacity::HintMaxHTLC {ref amount_msat, } => {
1387 let mut amount_msat_nonref = Clone::clone(amount_msat);
1388 EffectiveCapacity::HintMaxHTLC {
1389 amount_msat: amount_msat_nonref,
1392 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1396 pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
1398 nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1399 EffectiveCapacity::ExactLiquidity {
1400 liquidity_msat: liquidity_msat,
1403 nativeEffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => {
1404 EffectiveCapacity::AdvertisedMaxHTLC {
1405 amount_msat: amount_msat,
1408 nativeEffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1409 EffectiveCapacity::Total {
1410 capacity_msat: capacity_msat,
1411 htlc_maximum_msat: htlc_maximum_msat,
1414 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1415 nativeEffectiveCapacity::HintMaxHTLC {mut amount_msat, } => {
1416 EffectiveCapacity::HintMaxHTLC {
1417 amount_msat: amount_msat,
1420 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1424 /// Frees any resources used by the EffectiveCapacity
1426 pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
1427 /// Creates a copy of the EffectiveCapacity
1429 pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
1433 /// Used only if an object of this type is returned as a trait impl by a method
1434 pub(crate) extern "C" fn EffectiveCapacity_clone_void(this_ptr: *const c_void) -> *mut c_void {
1435 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const EffectiveCapacity)).clone() })) as *mut c_void
1438 /// Used only if an object of this type is returned as a trait impl by a method
1439 pub(crate) extern "C" fn EffectiveCapacity_free_void(this_ptr: *mut c_void) {
1440 let _ = unsafe { Box::from_raw(this_ptr as *mut EffectiveCapacity) };
1443 /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
1444 pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
1445 EffectiveCapacity::ExactLiquidity {
1450 /// Utility method to constructs a new AdvertisedMaxHTLC-variant EffectiveCapacity
1451 pub extern "C" fn EffectiveCapacity_advertised_max_htlc(amount_msat: u64) -> EffectiveCapacity {
1452 EffectiveCapacity::AdvertisedMaxHTLC {
1457 /// Utility method to constructs a new Total-variant EffectiveCapacity
1458 pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: u64) -> EffectiveCapacity {
1459 EffectiveCapacity::Total {
1465 /// Utility method to constructs a new Infinite-variant EffectiveCapacity
1466 pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
1467 EffectiveCapacity::Infinite}
1469 /// Utility method to constructs a new HintMaxHTLC-variant EffectiveCapacity
1470 pub extern "C" fn EffectiveCapacity_hint_max_htlc(amount_msat: u64) -> EffectiveCapacity {
1471 EffectiveCapacity::HintMaxHTLC {
1476 /// Utility method to constructs a new Unknown-variant EffectiveCapacity
1477 pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
1478 EffectiveCapacity::Unknown}
1479 /// Get a string which allows debug introspection of a EffectiveCapacity object
1480 pub extern "C" fn EffectiveCapacity_debug_str_void(o: *const c_void) -> Str {
1481 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::EffectiveCapacity }).into()}
1482 /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
1483 /// use when making routing decisions.
1486 pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::gossip::UNKNOWN_CHANNEL_CAPACITY_MSAT;
1487 /// Returns the effective capacity denominated in millisatoshi.
1490 pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &crate::lightning::routing::gossip::EffectiveCapacity) -> u64 {
1491 let mut ret = this_arg.to_native().as_msat();
1496 use lightning::routing::gossip::RoutingFees as nativeRoutingFeesImport;
1497 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1499 /// Fees for routing via a given channel or a node
1502 pub struct RoutingFees {
1503 /// A pointer to the opaque Rust object.
1505 /// Nearly everywhere, inner must be non-null, however in places where
1506 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1507 pub inner: *mut nativeRoutingFees,
1508 /// Indicates that this is the only struct which contains the same pointer.
1510 /// Rust functions which take ownership of an object provided via an argument require
1511 /// this to be true and invalidate the object pointed to by inner.
1515 impl Drop for RoutingFees {
1516 fn drop(&mut self) {
1517 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
1518 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1522 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
1524 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
1526 /// Used only if an object of this type is returned as a trait impl by a method
1527 pub(crate) extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
1528 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoutingFees) };
1532 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1533 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1535 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
1536 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1538 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1539 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
1540 assert!(self.is_owned);
1541 let ret = ObjOps::untweak_ptr(self.inner);
1542 self.inner = core::ptr::null_mut();
1546 /// Flat routing fee in millisatoshis.
1548 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1549 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1552 /// Flat routing fee in millisatoshis.
1554 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1555 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1557 /// Liquidity-based routing fee in millionths of a routed amount.
1558 /// In other words, 10000 is 1%.
1560 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1561 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1564 /// Liquidity-based routing fee in millionths of a routed amount.
1565 /// In other words, 10000 is 1%.
1567 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1568 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1570 /// Constructs a new RoutingFees given each field
1573 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1574 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1575 base_msat: base_msat_arg,
1576 proportional_millionths: proportional_millionths_arg,
1577 }), is_owned: true }
1579 /// Checks if two RoutingFeess contain equal inner contents.
1580 /// This ignores pointers and is_owned flags and looks at the values in fields.
1581 /// Two objects with NULL inner values will be considered "equal" here.
1583 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1584 if a.inner == b.inner { return true; }
1585 if a.inner.is_null() || b.inner.is_null() { return false; }
1586 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1588 impl Clone for RoutingFees {
1589 fn clone(&self) -> Self {
1591 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1592 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1598 /// Used only if an object of this type is returned as a trait impl by a method
1599 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1600 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRoutingFees)).clone() })) as *mut c_void
1603 /// Creates a copy of the RoutingFees
1604 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1607 /// Get a string which allows debug introspection of a RoutingFees object
1608 pub extern "C" fn RoutingFees_debug_str_void(o: *const c_void) -> Str {
1609 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::RoutingFees }).into()}
1610 /// Generates a non-cryptographic 64-bit hash of the RoutingFees.
1612 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1613 if o.inner.is_null() { return 0; }
1614 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1615 #[allow(deprecated)]
1616 let mut hasher = core::hash::SipHasher::new();
1617 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1618 core::hash::Hasher::finish(&hasher)
1621 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1622 pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::gossip::RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1623 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1626 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1627 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1630 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1631 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1632 let res: Result<lightning::routing::gossip::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1633 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() };
1637 use lightning::routing::gossip::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1638 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1640 /// Information received in the latest node_announcement from this node.
1643 pub struct NodeAnnouncementInfo {
1644 /// A pointer to the opaque Rust object.
1646 /// Nearly everywhere, inner must be non-null, however in places where
1647 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1648 pub inner: *mut nativeNodeAnnouncementInfo,
1649 /// Indicates that this is the only struct which contains the same pointer.
1651 /// Rust functions which take ownership of an object provided via an argument require
1652 /// this to be true and invalidate the object pointed to by inner.
1656 impl Drop for NodeAnnouncementInfo {
1657 fn drop(&mut self) {
1658 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1659 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1663 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1665 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1667 /// Used only if an object of this type is returned as a trait impl by a method
1668 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1669 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo) };
1672 impl NodeAnnouncementInfo {
1673 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1674 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1676 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1677 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1679 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1680 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1681 assert!(self.is_owned);
1682 let ret = ObjOps::untweak_ptr(self.inner);
1683 self.inner = core::ptr::null_mut();
1687 /// Protocol features the node announced support for
1689 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1690 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1691 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 }
1693 /// Protocol features the node announced support for
1695 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1696 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1698 /// When the last known update to the node state was issued.
1699 /// Value is opaque, as set in the announcement.
1701 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1702 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1705 /// When the last known update to the node state was issued.
1706 /// Value is opaque, as set in the announcement.
1708 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1709 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1711 /// Color assigned to the node
1713 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1714 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1717 /// Color assigned to the node
1719 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1720 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1722 /// Moniker assigned to the node.
1723 /// May be invalid or malicious (eg control chars),
1724 /// should not be exposed to the user.
1726 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::routing::gossip::NodeAlias {
1727 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1728 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 }
1730 /// Moniker assigned to the node.
1731 /// May be invalid or malicious (eg control chars),
1732 /// should not be exposed to the user.
1734 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::routing::gossip::NodeAlias) {
1735 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = *unsafe { Box::from_raw(val.take_inner()) };
1737 /// An initial announcement of the node
1738 /// Mostly redundant with the data we store in fields explicitly.
1739 /// Everything else is useful only for sending out for initial routing sync.
1740 /// Not stored if contains excess data to prevent DoS.
1742 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1744 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1745 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1746 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 };
1749 /// An initial announcement of the node
1750 /// Mostly redundant with the data we store in fields explicitly.
1751 /// Everything else is useful only for sending out for initial routing sync.
1752 /// Not stored if contains excess data to prevent DoS.
1754 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1756 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1757 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1758 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1760 /// Constructs a new NodeAnnouncementInfo given each field
1762 /// Note that announcement_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
1765 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 {
1766 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()) } }) };
1767 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1768 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1769 last_update: last_update_arg,
1771 alias: *unsafe { Box::from_raw(alias_arg.take_inner()) },
1772 announcement_message: local_announcement_message_arg,
1773 }), is_owned: true }
1775 impl Clone for NodeAnnouncementInfo {
1776 fn clone(&self) -> Self {
1778 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1779 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1785 /// Used only if an object of this type is returned as a trait impl by a method
1786 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1787 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1790 /// Creates a copy of the NodeAnnouncementInfo
1791 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1794 /// Get a string which allows debug introspection of a NodeAnnouncementInfo object
1795 pub extern "C" fn NodeAnnouncementInfo_debug_str_void(o: *const c_void) -> Str {
1796 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeAnnouncementInfo }).into()}
1797 /// Checks if two NodeAnnouncementInfos contain equal inner contents.
1798 /// This ignores pointers and is_owned flags and looks at the values in fields.
1799 /// Two objects with NULL inner values will be considered "equal" here.
1801 pub extern "C" fn NodeAnnouncementInfo_eq(a: &NodeAnnouncementInfo, b: &NodeAnnouncementInfo) -> bool {
1802 if a.inner == b.inner { return true; }
1803 if a.inner.is_null() || b.inner.is_null() { return false; }
1804 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1806 /// Internet-level addresses via which one can connect to the node
1809 pub extern "C" fn NodeAnnouncementInfo_addresses(this_arg: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_SocketAddressZ {
1810 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.addresses();
1811 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::SocketAddress::native_into(item) }); };
1816 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1817 pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1818 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1821 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1822 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1825 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1826 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1827 let res: Result<lightning::routing::gossip::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1828 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() };
1832 use lightning::routing::gossip::NodeAlias as nativeNodeAliasImport;
1833 pub(crate) type nativeNodeAlias = nativeNodeAliasImport;
1835 /// A user-defined name for a node, which may be used when displaying the node in a graph.
1837 /// Since node aliases are provided by third parties, they are a potential avenue for injection
1838 /// attacks. Care must be taken when processing.
1841 pub struct NodeAlias {
1842 /// A pointer to the opaque Rust object.
1844 /// Nearly everywhere, inner must be non-null, however in places where
1845 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1846 pub inner: *mut nativeNodeAlias,
1847 /// Indicates that this is the only struct which contains the same pointer.
1849 /// Rust functions which take ownership of an object provided via an argument require
1850 /// this to be true and invalidate the object pointed to by inner.
1854 impl Drop for NodeAlias {
1855 fn drop(&mut self) {
1856 if self.is_owned && !<*mut nativeNodeAlias>::is_null(self.inner) {
1857 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1861 /// Frees any resources used by the NodeAlias, if is_owned is set and inner is non-NULL.
1863 pub extern "C" fn NodeAlias_free(this_obj: NodeAlias) { }
1865 /// Used only if an object of this type is returned as a trait impl by a method
1866 pub(crate) extern "C" fn NodeAlias_free_void(this_ptr: *mut c_void) {
1867 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAlias) };
1871 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAlias {
1872 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1874 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAlias {
1875 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1877 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1878 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAlias {
1879 assert!(self.is_owned);
1880 let ret = ObjOps::untweak_ptr(self.inner);
1881 self.inner = core::ptr::null_mut();
1886 pub extern "C" fn NodeAlias_get_a(this_ptr: &NodeAlias) -> *const [u8; 32] {
1887 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1891 pub extern "C" fn NodeAlias_set_a(this_ptr: &mut NodeAlias, mut val: crate::c_types::ThirtyTwoBytes) {
1892 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.data;
1894 /// Constructs a new NodeAlias given each field
1897 pub extern "C" fn NodeAlias_new(mut a_arg: crate::c_types::ThirtyTwoBytes) -> NodeAlias {
1898 NodeAlias { inner: ObjOps::heap_alloc(lightning::routing::gossip::NodeAlias (
1900 )), is_owned: true }
1902 impl Clone for NodeAlias {
1903 fn clone(&self) -> Self {
1905 inner: if <*mut nativeNodeAlias>::is_null(self.inner) { core::ptr::null_mut() } else {
1906 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1912 /// Used only if an object of this type is returned as a trait impl by a method
1913 pub(crate) extern "C" fn NodeAlias_clone_void(this_ptr: *const c_void) -> *mut c_void {
1914 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAlias)).clone() })) as *mut c_void
1917 /// Creates a copy of the NodeAlias
1918 pub extern "C" fn NodeAlias_clone(orig: &NodeAlias) -> NodeAlias {
1921 /// Get a string which allows debug introspection of a NodeAlias object
1922 pub extern "C" fn NodeAlias_debug_str_void(o: *const c_void) -> Str {
1923 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeAlias }).into()}
1924 /// Generates a non-cryptographic 64-bit hash of the NodeAlias.
1926 pub extern "C" fn NodeAlias_hash(o: &NodeAlias) -> u64 {
1927 if o.inner.is_null() { return 0; }
1928 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1929 #[allow(deprecated)]
1930 let mut hasher = core::hash::SipHasher::new();
1931 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1932 core::hash::Hasher::finish(&hasher)
1934 /// Checks if two NodeAliass contain equal inner contents.
1935 /// This ignores pointers and is_owned flags and looks at the values in fields.
1936 /// Two objects with NULL inner values will be considered "equal" here.
1938 pub extern "C" fn NodeAlias_eq(a: &NodeAlias, b: &NodeAlias) -> bool {
1939 if a.inner == b.inner { return true; }
1940 if a.inner.is_null() || b.inner.is_null() { return false; }
1941 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1944 /// Serialize the NodeAlias object into a byte array which can be read by NodeAlias_read
1945 pub extern "C" fn NodeAlias_write(obj: &crate::lightning::routing::gossip::NodeAlias) -> crate::c_types::derived::CVec_u8Z {
1946 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1949 pub(crate) extern "C" fn NodeAlias_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1950 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAlias) })
1953 /// Read a NodeAlias from a byte array, created by NodeAlias_write
1954 pub extern "C" fn NodeAlias_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAliasDecodeErrorZ {
1955 let res: Result<lightning::routing::gossip::NodeAlias, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1956 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() };
1960 use lightning::routing::gossip::NodeInfo as nativeNodeInfoImport;
1961 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1963 /// Details about a node in the network, known from the network announcement.
1966 pub struct NodeInfo {
1967 /// A pointer to the opaque Rust object.
1969 /// Nearly everywhere, inner must be non-null, however in places where
1970 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1971 pub inner: *mut nativeNodeInfo,
1972 /// Indicates that this is the only struct which contains the same pointer.
1974 /// Rust functions which take ownership of an object provided via an argument require
1975 /// this to be true and invalidate the object pointed to by inner.
1979 impl Drop for NodeInfo {
1980 fn drop(&mut self) {
1981 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1982 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1986 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1988 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1990 /// Used only if an object of this type is returned as a trait impl by a method
1991 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1992 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeInfo) };
1996 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1997 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1999 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
2000 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2002 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2003 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
2004 assert!(self.is_owned);
2005 let ret = ObjOps::untweak_ptr(self.inner);
2006 self.inner = core::ptr::null_mut();
2010 /// All valid channels a node has announced
2012 /// Returns a copy of the field.
2014 pub extern "C" fn NodeInfo_get_channels(this_ptr: &NodeInfo) -> crate::c_types::derived::CVec_u64Z {
2015 let mut inner_val = this_ptr.get_native_mut_ref().channels.clone();
2016 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
2017 local_inner_val.into()
2019 /// All valid channels a node has announced
2021 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
2022 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
2023 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
2025 /// More information about a node from node_announcement.
2026 /// Optional because we store a Node entry after learning about it from
2027 /// a channel announcement, but before receiving a node announcement.
2029 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2031 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::NodeAnnouncementInfo {
2032 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
2033 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 };
2036 /// More information about a node from node_announcement.
2037 /// Optional because we store a Node entry after learning about it from
2038 /// a channel announcement, but before receiving a node announcement.
2040 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
2042 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::NodeAnnouncementInfo) {
2043 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
2044 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
2046 /// Constructs a new NodeInfo given each field
2048 /// Note that announcement_info_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
2051 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 {
2052 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
2053 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()) } }) };
2054 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
2055 channels: local_channels_arg,
2056 announcement_info: local_announcement_info_arg,
2057 }), is_owned: true }
2059 impl Clone for NodeInfo {
2060 fn clone(&self) -> Self {
2062 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
2063 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2069 /// Used only if an object of this type is returned as a trait impl by a method
2070 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
2071 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeInfo)).clone() })) as *mut c_void
2074 /// Creates a copy of the NodeInfo
2075 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
2078 /// Get a string which allows debug introspection of a NodeInfo object
2079 pub extern "C" fn NodeInfo_debug_str_void(o: *const c_void) -> Str {
2080 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeInfo }).into()}
2081 /// Checks if two NodeInfos contain equal inner contents.
2082 /// This ignores pointers and is_owned flags and looks at the values in fields.
2083 /// Two objects with NULL inner values will be considered "equal" here.
2085 pub extern "C" fn NodeInfo_eq(a: &NodeInfo, b: &NodeInfo) -> bool {
2086 if a.inner == b.inner { return true; }
2087 if a.inner.is_null() || b.inner.is_null() { return false; }
2088 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2090 /// Returns whether the node has only announced Tor addresses.
2093 pub extern "C" fn NodeInfo_is_tor_only(this_arg: &crate::lightning::routing::gossip::NodeInfo) -> bool {
2094 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_tor_only();
2099 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
2100 pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::gossip::NodeInfo) -> crate::c_types::derived::CVec_u8Z {
2101 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2104 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2105 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
2108 /// Read a NodeInfo from a byte array, created by NodeInfo_write
2109 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
2110 let res: Result<lightning::routing::gossip::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2111 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() };
2115 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
2116 pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
2117 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2120 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2121 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
2124 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
2125 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
2127 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);
2128 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() };
2131 /// Creates a new, empty, network graph.
2134 pub extern "C" fn NetworkGraph_new(mut network: crate::bitcoin::network::Network, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph {
2135 let mut ret = lightning::routing::gossip::NetworkGraph::new(network.into_bitcoin(), logger);
2136 crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
2139 /// Returns a read-only view of the network graph.
2142 pub extern "C" fn NetworkGraph_read_only(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::lightning::routing::gossip::ReadOnlyNetworkGraph {
2143 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
2144 crate::lightning::routing::gossip::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
2147 /// The unix timestamp provided by the most recent rapid gossip sync.
2148 /// It will be set by the rapid sync process after every sync completion.
2151 pub extern "C" fn NetworkGraph_get_last_rapid_gossip_sync_timestamp(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::COption_u32Z {
2152 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_last_rapid_gossip_sync_timestamp();
2153 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() }) };
2157 /// Update the unix timestamp provided by the most recent rapid gossip sync.
2158 /// This should be done automatically by the rapid sync process after every sync completion.
2160 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) {
2161 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.set_last_rapid_gossip_sync_timestamp(last_rapid_gossip_sync_timestamp)
2164 /// For an already known node (from channel announcements), update its stored properties from a
2165 /// given node announcement.
2167 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
2168 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
2169 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2172 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 {
2173 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref());
2174 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() };
2178 /// For an already known node (from channel announcements), update its stored properties from a
2179 /// given node announcement without verifying the associated signatures. Because we aren't
2180 /// given the associated signatures here we cannot relay the node announcement to any of our
2184 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 {
2185 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
2186 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() };
2190 /// Store or update channel info from a channel announcement.
2192 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2193 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2194 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2196 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2197 /// the corresponding UTXO exists on chain and is correctly-formatted.
2200 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 {
2201 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() } }})} };
2202 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_utxo_lookup);
2203 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() };
2207 /// Store or update channel info from a channel announcement.
2209 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2210 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2211 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2213 /// This will skip verification of if the channel is actually on-chain.
2216 pub extern "C" fn NetworkGraph_update_channel_from_announcement_no_lookup(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2217 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement_no_lookup(msg.get_native_ref());
2218 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() };
2222 /// Store or update channel info from a channel announcement without verifying the associated
2223 /// signatures. Because we aren't given the associated signatures here we cannot relay the
2224 /// channel announcement to any of our peers.
2226 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2227 /// the corresponding UTXO exists on chain and is correctly-formatted.
2230 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 {
2231 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() } }})} };
2232 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_utxo_lookup);
2233 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() };
2237 /// Update channel from partial announcement data received via rapid gossip sync
2239 /// `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
2240 /// rapid gossip sync server)
2242 /// All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
2245 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 {
2246 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());
2247 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() };
2251 /// Marks a channel in the graph as failed permanently.
2253 /// The channel and any node for which this was their last channel are removed from the graph.
2255 pub extern "C" fn NetworkGraph_channel_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64) {
2256 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed_permanent(short_channel_id)
2259 /// Marks a node in the graph as permanently failed, effectively removing it and its channels
2260 /// from local storage.
2262 pub extern "C" fn NetworkGraph_node_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut node_id: crate::c_types::PublicKey) {
2263 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node_failed_permanent(&node_id.into_rust())
2266 /// Removes information about channels that we haven't heard any updates about in some time.
2267 /// This can be used regularly to prune the network graph of channels that likely no longer
2270 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2271 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2272 /// pruning occur for updates which are at least two weeks old, which we implement here.
2274 /// Note that for users of the `lightning-background-processor` crate this method may be
2275 /// automatically called regularly for you.
2277 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2278 /// in the map for a while so that these can be resynced from gossip in the future.
2280 /// This method is only available with the `std` feature. See
2281 /// [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for `no-std` use.
2283 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking(this_arg: &crate::lightning::routing::gossip::NetworkGraph) {
2284 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking()
2287 /// Removes information about channels that we haven't heard any updates about in some time.
2288 /// This can be used regularly to prune the network graph of channels that likely no longer
2291 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2292 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2293 /// pruning occur for updates which are at least two weeks old, which we implement here.
2295 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2296 /// in the map for a while so that these can be resynced from gossip in the future.
2298 /// This function takes the current unix time as an argument. For users with the `std` feature
2299 /// enabled, [`NetworkGraph::remove_stale_channels_and_tracking`] may be preferable.
2301 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking_with_time(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut current_time_unix: u64) {
2302 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking_with_time(current_time_unix)
2305 /// For an already known (from announcement) channel, update info about one of the directions
2308 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2309 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2310 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2312 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2313 /// materially in the future will be rejected.
2316 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 {
2317 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref());
2318 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() };
2322 /// For an already known (from announcement) channel, update info about one of the directions
2323 /// of the channel without verifying the associated signatures. Because we aren't given the
2324 /// associated signatures here we cannot relay the channel update to any of our peers.
2326 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2327 /// materially in the future will be rejected.
2330 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 {
2331 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
2332 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() };
2336 /// For an already known (from announcement) channel, verify the given [`ChannelUpdate`].
2338 /// This checks whether the update currently is applicable by [`Self::update_channel`].
2340 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2341 /// materially in the future will be rejected.
2344 pub extern "C" fn NetworkGraph_verify_channel_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2345 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify_channel_update(msg.get_native_ref());
2346 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() };
2350 /// Returns information on a channel with the given id.
2352 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2355 pub extern "C" fn ReadOnlyNetworkGraph_channel(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut short_channel_id: u64) -> crate::lightning::routing::gossip::ChannelInfo {
2356 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel(short_channel_id);
2357 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 };
2361 /// Returns the list of channels in the graph
2364 pub extern "C" fn ReadOnlyNetworkGraph_list_channels(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_u64Z {
2365 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
2366 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { item }); };
2370 /// Returns information on a node with the given id.
2372 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2375 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 {
2376 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node(node_id.get_native_ref());
2377 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 };
2381 /// Returns the list of nodes in the graph
2384 pub extern "C" fn ReadOnlyNetworkGraph_list_nodes(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_NodeIdZ {
2385 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_nodes();
2386 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 } }); };
2390 /// Get network addresses by node id.
2391 /// Returns None if the requested node is completely unknown,
2392 /// or if node announcement for the node was never received.
2395 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_SocketAddressZZ {
2396 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust());
2397 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_SocketAddressZZ::None } else { crate::c_types::derived::COption_CVec_SocketAddressZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; local_ret_0.into() }) };