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 /// Get the public key slice from this NodeId
101 pub extern "C" fn NodeId_as_slice(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::u8slice {
102 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_slice();
103 let mut local_ret = crate::c_types::u8slice::from_slice(ret);
107 /// Get the public key as an array from this NodeId
110 pub extern "C" fn NodeId_as_array(this_arg: &crate::lightning::routing::gossip::NodeId) -> *const [u8; 33] {
111 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_array();
115 /// Get the public key from this NodeId
118 pub extern "C" fn NodeId_as_pubkey(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CResult_PublicKeySecp256k1ErrorZ {
119 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_pubkey();
120 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() };
124 /// Get a string which allows debug introspection of a NodeId object
125 pub extern "C" fn NodeId_debug_str_void(o: *const c_void) -> Str {
126 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeId }).into()}
127 /// Generates a non-cryptographic 64-bit hash of the NodeId.
129 pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 {
130 if o.inner.is_null() { return 0; }
131 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
133 let mut hasher = core::hash::SipHasher::new();
134 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
135 core::hash::Hasher::finish(&hasher)
138 /// Serialize the NodeId object into a byte array which can be read by NodeId_read
139 pub extern "C" fn NodeId_write(obj: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CVec_u8Z {
140 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
143 pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
144 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) })
147 /// Read a NodeId from a byte array, created by NodeId_write
148 pub extern "C" fn NodeId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ {
149 let res: Result<lightning::routing::gossip::NodeId, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
150 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() };
154 use lightning::routing::gossip::NetworkGraph as nativeNetworkGraphImport;
155 pub(crate) type nativeNetworkGraph = nativeNetworkGraphImport<crate::lightning::util::logger::Logger>;
157 /// Represents the network as nodes and channels between them
160 pub struct NetworkGraph {
161 /// A pointer to the opaque Rust object.
163 /// Nearly everywhere, inner must be non-null, however in places where
164 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
165 pub inner: *mut nativeNetworkGraph,
166 /// Indicates that this is the only struct which contains the same pointer.
168 /// Rust functions which take ownership of an object provided via an argument require
169 /// this to be true and invalidate the object pointed to by inner.
173 impl Drop for NetworkGraph {
175 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
176 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
180 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
182 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
184 /// Used only if an object of this type is returned as a trait impl by a method
185 pub(crate) extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
186 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNetworkGraph) };
190 pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
191 unsafe { &*ObjOps::untweak_ptr(self.inner) }
193 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
194 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
196 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
197 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
198 assert!(self.is_owned);
199 let ret = ObjOps::untweak_ptr(self.inner);
200 self.inner = core::ptr::null_mut();
205 use lightning::routing::gossip::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
206 pub(crate) type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
208 /// A read-only view of [`NetworkGraph`].
211 pub struct ReadOnlyNetworkGraph {
212 /// A pointer to the opaque Rust object.
214 /// Nearly everywhere, inner must be non-null, however in places where
215 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
216 pub inner: *mut nativeReadOnlyNetworkGraph,
217 /// Indicates that this is the only struct which contains the same pointer.
219 /// Rust functions which take ownership of an object provided via an argument require
220 /// this to be true and invalidate the object pointed to by inner.
224 impl Drop for ReadOnlyNetworkGraph {
226 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
227 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
231 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
233 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
235 /// Used only if an object of this type is returned as a trait impl by a method
236 pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
237 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph) };
240 impl ReadOnlyNetworkGraph {
241 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
242 unsafe { &*ObjOps::untweak_ptr(self.inner) }
244 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
245 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
247 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
248 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
249 assert!(self.is_owned);
250 let ret = ObjOps::untweak_ptr(self.inner);
251 self.inner = core::ptr::null_mut();
255 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
256 /// return packet by a node along the route. See [BOLT #4] for details.
258 /// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
262 pub enum NetworkUpdate {
263 /// An error indicating a `channel_update` messages should be applied via
264 /// [`NetworkGraph::update_channel`].
265 ChannelUpdateMessage {
266 /// The update to apply via [`NetworkGraph::update_channel`].
267 msg: crate::lightning::ln::msgs::ChannelUpdate,
269 /// An error indicating that a channel failed to route a payment, which should be applied via
270 /// [`NetworkGraph::channel_failed_permanent`] if permanent.
272 /// The short channel id of the closed channel.
273 short_channel_id: u64,
274 /// Whether the channel should be permanently removed or temporarily disabled until a new
275 /// `channel_update` message is received.
278 /// An error indicating that a node failed to route a payment, which should be applied via
279 /// [`NetworkGraph::node_failed_permanent`] if permanent.
281 /// The node id of the failed node.
282 node_id: crate::c_types::PublicKey,
283 /// Whether the node should be permanently removed from consideration or can be restored
284 /// when a new `channel_update` message is received.
288 use lightning::routing::gossip::NetworkUpdate as NetworkUpdateImport;
289 pub(crate) type nativeNetworkUpdate = NetworkUpdateImport;
293 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
295 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
296 let mut msg_nonref = Clone::clone(msg);
297 nativeNetworkUpdate::ChannelUpdateMessage {
298 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
301 NetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
302 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
303 let mut is_permanent_nonref = Clone::clone(is_permanent);
304 nativeNetworkUpdate::ChannelFailure {
305 short_channel_id: short_channel_id_nonref,
306 is_permanent: is_permanent_nonref,
309 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
310 let mut node_id_nonref = Clone::clone(node_id);
311 let mut is_permanent_nonref = Clone::clone(is_permanent);
312 nativeNetworkUpdate::NodeFailure {
313 node_id: node_id_nonref.into_rust(),
314 is_permanent: is_permanent_nonref,
320 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
322 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
323 nativeNetworkUpdate::ChannelUpdateMessage {
324 msg: *unsafe { Box::from_raw(msg.take_inner()) },
327 NetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
328 nativeNetworkUpdate::ChannelFailure {
329 short_channel_id: short_channel_id,
330 is_permanent: is_permanent,
333 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
334 nativeNetworkUpdate::NodeFailure {
335 node_id: node_id.into_rust(),
336 is_permanent: is_permanent,
342 pub(crate) fn from_native(native: &NetworkUpdateImport) -> Self {
343 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeNetworkUpdate) };
345 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
346 let mut msg_nonref = Clone::clone(msg);
347 NetworkUpdate::ChannelUpdateMessage {
348 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
351 nativeNetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
352 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
353 let mut is_permanent_nonref = Clone::clone(is_permanent);
354 NetworkUpdate::ChannelFailure {
355 short_channel_id: short_channel_id_nonref,
356 is_permanent: is_permanent_nonref,
359 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
360 let mut node_id_nonref = Clone::clone(node_id);
361 let mut is_permanent_nonref = Clone::clone(is_permanent);
362 NetworkUpdate::NodeFailure {
363 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
364 is_permanent: is_permanent_nonref,
370 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
372 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
373 NetworkUpdate::ChannelUpdateMessage {
374 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
377 nativeNetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
378 NetworkUpdate::ChannelFailure {
379 short_channel_id: short_channel_id,
380 is_permanent: is_permanent,
383 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
384 NetworkUpdate::NodeFailure {
385 node_id: crate::c_types::PublicKey::from_rust(&node_id),
386 is_permanent: is_permanent,
392 /// Frees any resources used by the NetworkUpdate
394 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
395 /// Creates a copy of the NetworkUpdate
397 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
401 /// Used only if an object of this type is returned as a trait impl by a method
402 pub(crate) extern "C" fn NetworkUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
403 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const NetworkUpdate)).clone() })) as *mut c_void
406 /// Used only if an object of this type is returned as a trait impl by a method
407 pub(crate) extern "C" fn NetworkUpdate_free_void(this_ptr: *mut c_void) {
408 let _ = unsafe { Box::from_raw(this_ptr as *mut NetworkUpdate) };
411 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
412 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
413 NetworkUpdate::ChannelUpdateMessage {
418 /// Utility method to constructs a new ChannelFailure-variant NetworkUpdate
419 pub extern "C" fn NetworkUpdate_channel_failure(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
420 NetworkUpdate::ChannelFailure {
426 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
427 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
428 NetworkUpdate::NodeFailure {
433 /// Get a string which allows debug introspection of a NetworkUpdate object
434 pub extern "C" fn NetworkUpdate_debug_str_void(o: *const c_void) -> Str {
435 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NetworkUpdate }).into()}
436 /// Checks if two NetworkUpdates contain equal inner contents.
437 /// This ignores pointers and is_owned flags and looks at the values in fields.
439 pub extern "C" fn NetworkUpdate_eq(a: &NetworkUpdate, b: &NetworkUpdate) -> bool {
440 if &a.to_native() == &b.to_native() { true } else { false }
443 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
444 pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::gossip::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
445 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
448 pub(crate) extern "C" fn NetworkUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
449 NetworkUpdate_write(unsafe { &*(obj as *const NetworkUpdate) })
452 /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
453 pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ {
454 let res: Result<Option<lightning::routing::gossip::NetworkUpdate>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
455 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() };
459 use lightning::routing::gossip::P2PGossipSync as nativeP2PGossipSyncImport;
460 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>;
462 /// Receives and validates network updates from peers,
463 /// stores authentic and relevant data as a network graph.
464 /// This network graph is then used for routing payments.
465 /// Provides interface to help with initial routing sync by
466 /// serving historical announcements.
469 pub struct P2PGossipSync {
470 /// A pointer to the opaque Rust object.
472 /// Nearly everywhere, inner must be non-null, however in places where
473 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
474 pub inner: *mut nativeP2PGossipSync,
475 /// Indicates that this is the only struct which contains the same pointer.
477 /// Rust functions which take ownership of an object provided via an argument require
478 /// this to be true and invalidate the object pointed to by inner.
482 impl Drop for P2PGossipSync {
484 if self.is_owned && !<*mut nativeP2PGossipSync>::is_null(self.inner) {
485 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
489 /// Frees any resources used by the P2PGossipSync, if is_owned is set and inner is non-NULL.
491 pub extern "C" fn P2PGossipSync_free(this_obj: P2PGossipSync) { }
493 /// Used only if an object of this type is returned as a trait impl by a method
494 pub(crate) extern "C" fn P2PGossipSync_free_void(this_ptr: *mut c_void) {
495 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeP2PGossipSync) };
499 pub(crate) fn get_native_ref(&self) -> &'static nativeP2PGossipSync {
500 unsafe { &*ObjOps::untweak_ptr(self.inner) }
502 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeP2PGossipSync {
503 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
505 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
506 pub(crate) fn take_inner(mut self) -> *mut nativeP2PGossipSync {
507 assert!(self.is_owned);
508 let ret = ObjOps::untweak_ptr(self.inner);
509 self.inner = core::ptr::null_mut();
513 /// Creates a new tracker of the actual state of the network of channels and nodes,
514 /// assuming an existing [`NetworkGraph`].
515 /// UTXO lookup is used to make sure announced channels exist on-chain, channel data is
516 /// correct, and the announcement is signed with channel owners' keys.
519 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 {
520 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() } }})} };
521 let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_utxo_lookup, logger);
522 crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(ret), is_owned: true }
525 /// Adds a provider used to check new announcements. Does not affect
526 /// existing announcements unless they are updated.
527 /// Add, update or remove the provider would replace the current one.
529 pub extern "C" fn P2PGossipSync_add_utxo_lookup(this_arg: &crate::lightning::routing::gossip::P2PGossipSync, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) {
530 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() } }})} };
531 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.add_utxo_lookup(local_utxo_lookup)
534 /// Handles any network updates originating from [`Event`]s.
535 /// Note that this will skip applying any [`NetworkUpdate::ChannelUpdateMessage`] to avoid
536 /// leaking possibly identifying information of the sender to the public network.
538 /// [`Event`]: crate::events::Event
540 pub extern "C" fn NetworkGraph_handle_network_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, network_update: &crate::lightning::routing::gossip::NetworkUpdate) {
541 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_network_update(&network_update.to_native())
544 /// Gets the chain hash for this network graph.
547 pub extern "C" fn NetworkGraph_get_chain_hash(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::ThirtyTwoBytes {
548 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_chain_hash();
549 crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
552 /// Verifies the signature of a [`NodeAnnouncement`].
554 /// Returns an error if it is invalid.
556 pub extern "C" fn verify_node_announcement(msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
557 let mut ret = lightning::routing::gossip::verify_node_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1);
558 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
562 /// Verifies all signatures included in a [`ChannelAnnouncement`].
564 /// Returns an error if one of the signatures is invalid.
566 pub extern "C" fn verify_channel_announcement(msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
567 let mut ret = lightning::routing::gossip::verify_channel_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1);
568 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
572 impl From<nativeP2PGossipSync> for crate::lightning::ln::msgs::RoutingMessageHandler {
573 fn from(obj: nativeP2PGossipSync) -> Self {
574 let rust_obj = crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
575 let mut ret = P2PGossipSync_as_RoutingMessageHandler(&rust_obj);
576 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
577 core::mem::forget(rust_obj);
578 ret.free = Some(P2PGossipSync_free_void);
582 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
583 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
585 pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSync) -> crate::lightning::ln::msgs::RoutingMessageHandler {
586 crate::lightning::ln::msgs::RoutingMessageHandler {
587 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
589 handle_node_announcement: P2PGossipSync_RoutingMessageHandler_handle_node_announcement,
590 handle_channel_announcement: P2PGossipSync_RoutingMessageHandler_handle_channel_announcement,
591 handle_channel_update: P2PGossipSync_RoutingMessageHandler_handle_channel_update,
592 get_next_channel_announcement: P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement,
593 get_next_node_announcement: P2PGossipSync_RoutingMessageHandler_get_next_node_announcement,
594 peer_connected: P2PGossipSync_RoutingMessageHandler_peer_connected,
595 handle_reply_channel_range: P2PGossipSync_RoutingMessageHandler_handle_reply_channel_range,
596 handle_reply_short_channel_ids_end: P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end,
597 handle_query_channel_range: P2PGossipSync_RoutingMessageHandler_handle_query_channel_range,
598 handle_query_short_channel_ids: P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids,
599 processing_queue_high: P2PGossipSync_RoutingMessageHandler_processing_queue_high,
600 provided_node_features: P2PGossipSync_RoutingMessageHandler_provided_node_features,
601 provided_init_features: P2PGossipSync_RoutingMessageHandler_provided_init_features,
602 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
603 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
605 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
611 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 {
612 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
613 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() };
617 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 {
618 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
619 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() };
623 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 {
624 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
625 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() };
629 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 {
630 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, starting_point);
631 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 }) };
635 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 {
636 let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
637 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, local_starting_point);
638 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 };
642 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 {
643 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);
644 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() };
648 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 {
649 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()) });
650 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() };
654 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 {
655 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()) });
656 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() };
660 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 {
661 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()) });
662 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() };
666 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 {
667 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()) });
668 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() };
672 extern "C" fn P2PGossipSync_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
673 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
677 extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
678 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
679 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
682 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 {
683 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust());
684 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
687 impl From<nativeP2PGossipSync> for crate::lightning::events::MessageSendEventsProvider {
688 fn from(obj: nativeP2PGossipSync) -> Self {
689 let rust_obj = crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
690 let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj);
691 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
692 core::mem::forget(rust_obj);
693 ret.free = Some(P2PGossipSync_free_void);
697 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
698 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
700 pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::events::MessageSendEventsProvider {
701 crate::lightning::events::MessageSendEventsProvider {
702 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
704 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
709 extern "C" fn P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
710 let mut ret = <nativeP2PGossipSync as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
711 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
716 use lightning::routing::gossip::ChannelUpdateInfo as nativeChannelUpdateInfoImport;
717 pub(crate) type nativeChannelUpdateInfo = nativeChannelUpdateInfoImport;
719 /// Details about one direction of a channel as received within a [`ChannelUpdate`].
722 pub struct ChannelUpdateInfo {
723 /// A pointer to the opaque Rust object.
725 /// Nearly everywhere, inner must be non-null, however in places where
726 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
727 pub inner: *mut nativeChannelUpdateInfo,
728 /// Indicates that this is the only struct which contains the same pointer.
730 /// Rust functions which take ownership of an object provided via an argument require
731 /// this to be true and invalidate the object pointed to by inner.
735 impl Drop for ChannelUpdateInfo {
737 if self.is_owned && !<*mut nativeChannelUpdateInfo>::is_null(self.inner) {
738 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
742 /// Frees any resources used by the ChannelUpdateInfo, if is_owned is set and inner is non-NULL.
744 pub extern "C" fn ChannelUpdateInfo_free(this_obj: ChannelUpdateInfo) { }
746 /// Used only if an object of this type is returned as a trait impl by a method
747 pub(crate) extern "C" fn ChannelUpdateInfo_free_void(this_ptr: *mut c_void) {
748 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo) };
751 impl ChannelUpdateInfo {
752 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUpdateInfo {
753 unsafe { &*ObjOps::untweak_ptr(self.inner) }
755 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUpdateInfo {
756 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
758 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
759 pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdateInfo {
760 assert!(self.is_owned);
761 let ret = ObjOps::untweak_ptr(self.inner);
762 self.inner = core::ptr::null_mut();
766 /// When the last update to the channel direction was issued.
767 /// Value is opaque, as set in the announcement.
769 pub extern "C" fn ChannelUpdateInfo_get_last_update(this_ptr: &ChannelUpdateInfo) -> u32 {
770 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
773 /// When the last update to the channel direction was issued.
774 /// Value is opaque, as set in the announcement.
776 pub extern "C" fn ChannelUpdateInfo_set_last_update(this_ptr: &mut ChannelUpdateInfo, mut val: u32) {
777 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
779 /// Whether the channel can be currently used for payments (in this one direction).
781 pub extern "C" fn ChannelUpdateInfo_get_enabled(this_ptr: &ChannelUpdateInfo) -> bool {
782 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
785 /// Whether the channel can be currently used for payments (in this one direction).
787 pub extern "C" fn ChannelUpdateInfo_set_enabled(this_ptr: &mut ChannelUpdateInfo, mut val: bool) {
788 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
790 /// The difference in CLTV values that you must have when routing through this channel.
792 pub extern "C" fn ChannelUpdateInfo_get_cltv_expiry_delta(this_ptr: &ChannelUpdateInfo) -> u16 {
793 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
796 /// The difference in CLTV values that you must have when routing through this channel.
798 pub extern "C" fn ChannelUpdateInfo_set_cltv_expiry_delta(this_ptr: &mut ChannelUpdateInfo, mut val: u16) {
799 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
801 /// The minimum value, which must be relayed to the next hop via the channel
803 pub extern "C" fn ChannelUpdateInfo_get_htlc_minimum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
804 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
807 /// The minimum value, which must be relayed to the next hop via the channel
809 pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
810 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
812 /// The maximum value which may be relayed to the next hop via the channel.
814 pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
815 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
818 /// The maximum value which may be relayed to the next hop via the channel.
820 pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
821 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
823 /// Fees charged when the channel is used for routing
825 pub extern "C" fn ChannelUpdateInfo_get_fees(this_ptr: &ChannelUpdateInfo) -> crate::lightning::routing::gossip::RoutingFees {
826 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
827 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 }
829 /// Fees charged when the channel is used for routing
831 pub extern "C" fn ChannelUpdateInfo_set_fees(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::routing::gossip::RoutingFees) {
832 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
834 /// Most recent update for the channel received from the network
835 /// Mostly redundant with the data we store in fields explicitly.
836 /// Everything else is useful only for sending out for initial routing sync.
837 /// Not stored if contains excess data to prevent DoS.
839 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
841 pub extern "C" fn ChannelUpdateInfo_get_last_update_message(this_ptr: &ChannelUpdateInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
842 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
843 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 };
846 /// Most recent update for the channel received from the network
847 /// Mostly redundant with the data we store in fields explicitly.
848 /// Everything else is useful only for sending out for initial routing sync.
849 /// Not stored if contains excess data to prevent DoS.
851 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
853 pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
854 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
855 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
857 /// Constructs a new ChannelUpdateInfo given each field
859 /// Note that last_update_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
862 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 {
863 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()) } }) };
864 ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo {
865 last_update: last_update_arg,
866 enabled: enabled_arg,
867 cltv_expiry_delta: cltv_expiry_delta_arg,
868 htlc_minimum_msat: htlc_minimum_msat_arg,
869 htlc_maximum_msat: htlc_maximum_msat_arg,
870 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
871 last_update_message: local_last_update_message_arg,
874 impl Clone for ChannelUpdateInfo {
875 fn clone(&self) -> Self {
877 inner: if <*mut nativeChannelUpdateInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
878 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
884 /// Used only if an object of this type is returned as a trait impl by a method
885 pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
886 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelUpdateInfo)).clone() })) as *mut c_void
889 /// Creates a copy of the ChannelUpdateInfo
890 pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo {
893 /// Get a string which allows debug introspection of a ChannelUpdateInfo object
894 pub extern "C" fn ChannelUpdateInfo_debug_str_void(o: *const c_void) -> Str {
895 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::ChannelUpdateInfo }).into()}
896 /// Checks if two ChannelUpdateInfos contain equal inner contents.
897 /// This ignores pointers and is_owned flags and looks at the values in fields.
898 /// Two objects with NULL inner values will be considered "equal" here.
900 pub extern "C" fn ChannelUpdateInfo_eq(a: &ChannelUpdateInfo, b: &ChannelUpdateInfo) -> bool {
901 if a.inner == b.inner { return true; }
902 if a.inner.is_null() || b.inner.is_null() { return false; }
903 if a.get_native_ref() == b.get_native_ref() { true } else { false }
906 /// Serialize the ChannelUpdateInfo object into a byte array which can be read by ChannelUpdateInfo_read
907 pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::gossip::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z {
908 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
911 pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
912 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) })
915 /// Read a ChannelUpdateInfo from a byte array, created by ChannelUpdateInfo_write
916 pub extern "C" fn ChannelUpdateInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateInfoDecodeErrorZ {
917 let res: Result<lightning::routing::gossip::ChannelUpdateInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
918 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() };
922 use lightning::routing::gossip::ChannelInfo as nativeChannelInfoImport;
923 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
925 /// Details about a channel (both directions).
926 /// Received within a channel announcement.
929 pub struct ChannelInfo {
930 /// A pointer to the opaque Rust object.
932 /// Nearly everywhere, inner must be non-null, however in places where
933 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
934 pub inner: *mut nativeChannelInfo,
935 /// Indicates that this is the only struct which contains the same pointer.
937 /// Rust functions which take ownership of an object provided via an argument require
938 /// this to be true and invalidate the object pointed to by inner.
942 impl Drop for ChannelInfo {
944 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
945 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
949 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
951 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
953 /// Used only if an object of this type is returned as a trait impl by a method
954 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
955 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelInfo) };
959 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
960 unsafe { &*ObjOps::untweak_ptr(self.inner) }
962 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
963 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
965 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
966 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
967 assert!(self.is_owned);
968 let ret = ObjOps::untweak_ptr(self.inner);
969 self.inner = core::ptr::null_mut();
973 /// Protocol features of a channel communicated during its announcement
975 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
976 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
977 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 }
979 /// Protocol features of a channel communicated during its announcement
981 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
982 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
984 /// Source node of the first direction of a channel
986 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
987 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
988 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 }
990 /// Source node of the first direction of a channel
992 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
993 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
995 /// Details about the first direction of a channel
997 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
999 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1000 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
1001 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 };
1004 /// Details about the first direction of a channel
1006 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1008 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
1009 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1010 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
1012 /// Source node of the second direction of a channel
1014 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
1015 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
1016 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 }
1018 /// Source node of the second direction of a channel
1020 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
1021 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
1023 /// Details about the second direction of a channel
1025 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1027 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1028 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
1029 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 };
1032 /// Details about the second direction of a channel
1034 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1036 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
1037 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1038 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
1040 /// The channel capacity as seen on-chain, if chain lookup is available.
1042 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
1043 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
1044 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() }) };
1047 /// The channel capacity as seen on-chain, if chain lookup is available.
1049 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
1050 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1051 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
1053 /// An initial announcement of the channel
1054 /// Mostly redundant with the data we store in fields explicitly.
1055 /// Everything else is useful only for sending out for initial routing sync.
1056 /// Not stored if contains excess data to prevent DoS.
1058 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1060 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
1061 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1062 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 };
1065 /// An initial announcement of the channel
1066 /// Mostly redundant with the data we store in fields explicitly.
1067 /// Everything else is useful only for sending out for initial routing sync.
1068 /// Not stored if contains excess data to prevent DoS.
1070 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1072 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
1073 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1074 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1076 impl Clone for ChannelInfo {
1077 fn clone(&self) -> Self {
1079 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1080 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1086 /// Used only if an object of this type is returned as a trait impl by a method
1087 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1088 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelInfo)).clone() })) as *mut c_void
1091 /// Creates a copy of the ChannelInfo
1092 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1095 /// Get a string which allows debug introspection of a ChannelInfo object
1096 pub extern "C" fn ChannelInfo_debug_str_void(o: *const c_void) -> Str {
1097 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::ChannelInfo }).into()}
1098 /// Checks if two ChannelInfos contain equal inner contents.
1099 /// This ignores pointers and is_owned flags and looks at the values in fields.
1100 /// Two objects with NULL inner values will be considered "equal" here.
1102 pub extern "C" fn ChannelInfo_eq(a: &ChannelInfo, b: &ChannelInfo) -> bool {
1103 if a.inner == b.inner { return true; }
1104 if a.inner.is_null() || b.inner.is_null() { return false; }
1105 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1107 /// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
1109 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1112 pub extern "C" fn ChannelInfo_get_directional_info(this_arg: &crate::lightning::routing::gossip::ChannelInfo, mut channel_flags: u8) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1113 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_directional_info(channel_flags);
1114 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 };
1119 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1120 pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::gossip::ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1121 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1124 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1125 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1128 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1129 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1130 let res: Result<lightning::routing::gossip::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1131 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() };
1135 use lightning::routing::gossip::DirectedChannelInfo as nativeDirectedChannelInfoImport;
1136 pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static>;
1138 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
1139 /// source node to a target node.
1142 pub struct DirectedChannelInfo {
1143 /// A pointer to the opaque Rust object.
1145 /// Nearly everywhere, inner must be non-null, however in places where
1146 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1147 pub inner: *mut nativeDirectedChannelInfo,
1148 /// Indicates that this is the only struct which contains the same pointer.
1150 /// Rust functions which take ownership of an object provided via an argument require
1151 /// this to be true and invalidate the object pointed to by inner.
1155 impl Drop for DirectedChannelInfo {
1156 fn drop(&mut self) {
1157 if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
1158 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1162 /// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
1164 pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
1166 /// Used only if an object of this type is returned as a trait impl by a method
1167 pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
1168 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo) };
1171 impl DirectedChannelInfo {
1172 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
1173 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1175 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
1176 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1178 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1179 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelInfo {
1180 assert!(self.is_owned);
1181 let ret = ObjOps::untweak_ptr(self.inner);
1182 self.inner = core::ptr::null_mut();
1186 impl Clone for DirectedChannelInfo {
1187 fn clone(&self) -> Self {
1189 inner: if <*mut nativeDirectedChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1190 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1196 /// Used only if an object of this type is returned as a trait impl by a method
1197 pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1198 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDirectedChannelInfo)).clone() })) as *mut c_void
1201 /// Creates a copy of the DirectedChannelInfo
1202 pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
1205 /// Returns information for the channel.
1208 pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::ChannelInfo {
1209 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
1210 crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::ChannelInfo<>) as *mut _) }, is_owned: false }
1213 /// Returns the [`EffectiveCapacity`] of the channel in the direction.
1215 /// This is either the total capacity from the funding transaction, if known, or the
1216 /// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
1220 pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::EffectiveCapacity {
1221 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
1222 crate::lightning::routing::gossip::EffectiveCapacity::native_into(ret)
1225 /// Get a string which allows debug introspection of a DirectedChannelInfo object
1226 pub extern "C" fn DirectedChannelInfo_debug_str_void(o: *const c_void) -> Str {
1227 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::DirectedChannelInfo }).into()}
1228 /// The effective capacity of a channel for routing purposes.
1230 /// While this may be smaller than the actual channel capacity, amounts greater than
1231 /// [`Self::as_msat`] should not be routed through the channel.
1235 pub enum EffectiveCapacity {
1236 /// The available liquidity in the channel known from being a channel counterparty, and thus a
1239 /// Either the inbound or outbound liquidity depending on the direction, denominated in
1241 liquidity_msat: u64,
1243 /// The maximum HTLC amount in one direction as advertised on the gossip network.
1245 /// The maximum HTLC amount denominated in millisatoshi.
1248 /// The total capacity of the channel as determined by the funding transaction.
1250 /// The funding amount denominated in millisatoshi.
1252 /// The maximum HTLC amount denominated in millisatoshi.
1253 htlc_maximum_msat: u64,
1255 /// A capacity sufficient to route any payment, typically used for private channels provided by
1258 /// The maximum HTLC amount as provided by an invoice route hint.
1260 /// The maximum HTLC amount denominated in millisatoshi.
1263 /// A capacity that is unknown possibly because either the chain state is unavailable to know
1264 /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
1267 use lightning::routing::gossip::EffectiveCapacity as EffectiveCapacityImport;
1268 pub(crate) type nativeEffectiveCapacity = EffectiveCapacityImport;
1270 impl EffectiveCapacity {
1272 pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
1274 EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1275 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1276 nativeEffectiveCapacity::ExactLiquidity {
1277 liquidity_msat: liquidity_msat_nonref,
1280 EffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => {
1281 let mut amount_msat_nonref = Clone::clone(amount_msat);
1282 nativeEffectiveCapacity::AdvertisedMaxHTLC {
1283 amount_msat: amount_msat_nonref,
1286 EffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1287 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1288 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1289 nativeEffectiveCapacity::Total {
1290 capacity_msat: capacity_msat_nonref,
1291 htlc_maximum_msat: htlc_maximum_msat_nonref,
1294 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1295 EffectiveCapacity::HintMaxHTLC {ref amount_msat, } => {
1296 let mut amount_msat_nonref = Clone::clone(amount_msat);
1297 nativeEffectiveCapacity::HintMaxHTLC {
1298 amount_msat: amount_msat_nonref,
1301 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1305 pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
1307 EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1308 nativeEffectiveCapacity::ExactLiquidity {
1309 liquidity_msat: liquidity_msat,
1312 EffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => {
1313 nativeEffectiveCapacity::AdvertisedMaxHTLC {
1314 amount_msat: amount_msat,
1317 EffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1318 nativeEffectiveCapacity::Total {
1319 capacity_msat: capacity_msat,
1320 htlc_maximum_msat: htlc_maximum_msat,
1323 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1324 EffectiveCapacity::HintMaxHTLC {mut amount_msat, } => {
1325 nativeEffectiveCapacity::HintMaxHTLC {
1326 amount_msat: amount_msat,
1329 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1333 pub(crate) fn from_native(native: &EffectiveCapacityImport) -> Self {
1334 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeEffectiveCapacity) };
1336 nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1337 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1338 EffectiveCapacity::ExactLiquidity {
1339 liquidity_msat: liquidity_msat_nonref,
1342 nativeEffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => {
1343 let mut amount_msat_nonref = Clone::clone(amount_msat);
1344 EffectiveCapacity::AdvertisedMaxHTLC {
1345 amount_msat: amount_msat_nonref,
1348 nativeEffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1349 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1350 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1351 EffectiveCapacity::Total {
1352 capacity_msat: capacity_msat_nonref,
1353 htlc_maximum_msat: htlc_maximum_msat_nonref,
1356 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1357 nativeEffectiveCapacity::HintMaxHTLC {ref amount_msat, } => {
1358 let mut amount_msat_nonref = Clone::clone(amount_msat);
1359 EffectiveCapacity::HintMaxHTLC {
1360 amount_msat: amount_msat_nonref,
1363 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1367 pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
1369 nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1370 EffectiveCapacity::ExactLiquidity {
1371 liquidity_msat: liquidity_msat,
1374 nativeEffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => {
1375 EffectiveCapacity::AdvertisedMaxHTLC {
1376 amount_msat: amount_msat,
1379 nativeEffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1380 EffectiveCapacity::Total {
1381 capacity_msat: capacity_msat,
1382 htlc_maximum_msat: htlc_maximum_msat,
1385 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1386 nativeEffectiveCapacity::HintMaxHTLC {mut amount_msat, } => {
1387 EffectiveCapacity::HintMaxHTLC {
1388 amount_msat: amount_msat,
1391 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1395 /// Frees any resources used by the EffectiveCapacity
1397 pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
1398 /// Creates a copy of the EffectiveCapacity
1400 pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
1404 /// Used only if an object of this type is returned as a trait impl by a method
1405 pub(crate) extern "C" fn EffectiveCapacity_clone_void(this_ptr: *const c_void) -> *mut c_void {
1406 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const EffectiveCapacity)).clone() })) as *mut c_void
1409 /// Used only if an object of this type is returned as a trait impl by a method
1410 pub(crate) extern "C" fn EffectiveCapacity_free_void(this_ptr: *mut c_void) {
1411 let _ = unsafe { Box::from_raw(this_ptr as *mut EffectiveCapacity) };
1414 /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
1415 pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
1416 EffectiveCapacity::ExactLiquidity {
1421 /// Utility method to constructs a new AdvertisedMaxHTLC-variant EffectiveCapacity
1422 pub extern "C" fn EffectiveCapacity_advertised_max_htlc(amount_msat: u64) -> EffectiveCapacity {
1423 EffectiveCapacity::AdvertisedMaxHTLC {
1428 /// Utility method to constructs a new Total-variant EffectiveCapacity
1429 pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: u64) -> EffectiveCapacity {
1430 EffectiveCapacity::Total {
1436 /// Utility method to constructs a new Infinite-variant EffectiveCapacity
1437 pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
1438 EffectiveCapacity::Infinite}
1440 /// Utility method to constructs a new HintMaxHTLC-variant EffectiveCapacity
1441 pub extern "C" fn EffectiveCapacity_hint_max_htlc(amount_msat: u64) -> EffectiveCapacity {
1442 EffectiveCapacity::HintMaxHTLC {
1447 /// Utility method to constructs a new Unknown-variant EffectiveCapacity
1448 pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
1449 EffectiveCapacity::Unknown}
1450 /// Get a string which allows debug introspection of a EffectiveCapacity object
1451 pub extern "C" fn EffectiveCapacity_debug_str_void(o: *const c_void) -> Str {
1452 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::EffectiveCapacity }).into()}
1453 /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
1454 /// use when making routing decisions.
1457 pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::gossip::UNKNOWN_CHANNEL_CAPACITY_MSAT;
1458 /// Returns the effective capacity denominated in millisatoshi.
1461 pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &crate::lightning::routing::gossip::EffectiveCapacity) -> u64 {
1462 let mut ret = this_arg.to_native().as_msat();
1467 use lightning::routing::gossip::RoutingFees as nativeRoutingFeesImport;
1468 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1470 /// Fees for routing via a given channel or a node
1473 pub struct RoutingFees {
1474 /// A pointer to the opaque Rust object.
1476 /// Nearly everywhere, inner must be non-null, however in places where
1477 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1478 pub inner: *mut nativeRoutingFees,
1479 /// Indicates that this is the only struct which contains the same pointer.
1481 /// Rust functions which take ownership of an object provided via an argument require
1482 /// this to be true and invalidate the object pointed to by inner.
1486 impl Drop for RoutingFees {
1487 fn drop(&mut self) {
1488 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
1489 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1493 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
1495 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
1497 /// Used only if an object of this type is returned as a trait impl by a method
1498 pub(crate) extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
1499 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoutingFees) };
1503 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1504 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1506 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
1507 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1509 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1510 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
1511 assert!(self.is_owned);
1512 let ret = ObjOps::untweak_ptr(self.inner);
1513 self.inner = core::ptr::null_mut();
1517 /// Flat routing fee in millisatoshis.
1519 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1520 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1523 /// Flat routing fee in millisatoshis.
1525 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1526 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1528 /// Liquidity-based routing fee in millionths of a routed amount.
1529 /// In other words, 10000 is 1%.
1531 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1532 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1535 /// Liquidity-based routing fee in millionths of a routed amount.
1536 /// In other words, 10000 is 1%.
1538 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1539 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1541 /// Constructs a new RoutingFees given each field
1544 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1545 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1546 base_msat: base_msat_arg,
1547 proportional_millionths: proportional_millionths_arg,
1548 }), is_owned: true }
1550 /// Checks if two RoutingFeess contain equal inner contents.
1551 /// This ignores pointers and is_owned flags and looks at the values in fields.
1552 /// Two objects with NULL inner values will be considered "equal" here.
1554 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1555 if a.inner == b.inner { return true; }
1556 if a.inner.is_null() || b.inner.is_null() { return false; }
1557 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1559 impl Clone for RoutingFees {
1560 fn clone(&self) -> Self {
1562 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1563 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1569 /// Used only if an object of this type is returned as a trait impl by a method
1570 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1571 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRoutingFees)).clone() })) as *mut c_void
1574 /// Creates a copy of the RoutingFees
1575 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1578 /// Get a string which allows debug introspection of a RoutingFees object
1579 pub extern "C" fn RoutingFees_debug_str_void(o: *const c_void) -> Str {
1580 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::RoutingFees }).into()}
1581 /// Generates a non-cryptographic 64-bit hash of the RoutingFees.
1583 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1584 if o.inner.is_null() { return 0; }
1585 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1586 #[allow(deprecated)]
1587 let mut hasher = core::hash::SipHasher::new();
1588 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1589 core::hash::Hasher::finish(&hasher)
1592 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1593 pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::gossip::RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1594 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1597 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1598 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1601 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1602 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1603 let res: Result<lightning::routing::gossip::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1604 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() };
1608 use lightning::routing::gossip::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1609 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1611 /// Information received in the latest node_announcement from this node.
1614 pub struct NodeAnnouncementInfo {
1615 /// A pointer to the opaque Rust object.
1617 /// Nearly everywhere, inner must be non-null, however in places where
1618 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1619 pub inner: *mut nativeNodeAnnouncementInfo,
1620 /// Indicates that this is the only struct which contains the same pointer.
1622 /// Rust functions which take ownership of an object provided via an argument require
1623 /// this to be true and invalidate the object pointed to by inner.
1627 impl Drop for NodeAnnouncementInfo {
1628 fn drop(&mut self) {
1629 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1630 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1634 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1636 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1638 /// Used only if an object of this type is returned as a trait impl by a method
1639 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1640 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo) };
1643 impl NodeAnnouncementInfo {
1644 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1645 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1647 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1648 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1650 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1651 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1652 assert!(self.is_owned);
1653 let ret = ObjOps::untweak_ptr(self.inner);
1654 self.inner = core::ptr::null_mut();
1658 /// Protocol features the node announced support for
1660 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1661 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1662 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 }
1664 /// Protocol features the node announced support for
1666 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1667 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1669 /// When the last known update to the node state was issued.
1670 /// Value is opaque, as set in the announcement.
1672 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1673 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1676 /// When the last known update to the node state was issued.
1677 /// Value is opaque, as set in the announcement.
1679 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1680 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1682 /// Color assigned to the node
1684 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1685 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1688 /// Color assigned to the node
1690 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1691 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1693 /// Moniker assigned to the node.
1694 /// May be invalid or malicious (eg control chars),
1695 /// should not be exposed to the user.
1697 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::routing::gossip::NodeAlias {
1698 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1699 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 }
1701 /// Moniker assigned to the node.
1702 /// May be invalid or malicious (eg control chars),
1703 /// should not be exposed to the user.
1705 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::routing::gossip::NodeAlias) {
1706 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = *unsafe { Box::from_raw(val.take_inner()) };
1708 /// An initial announcement of the node
1709 /// Mostly redundant with the data we store in fields explicitly.
1710 /// Everything else is useful only for sending out for initial routing sync.
1711 /// Not stored if contains excess data to prevent DoS.
1713 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1715 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1716 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1717 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 };
1720 /// An initial announcement of the node
1721 /// Mostly redundant with the data we store in fields explicitly.
1722 /// Everything else is useful only for sending out for initial routing sync.
1723 /// Not stored if contains excess data to prevent DoS.
1725 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1727 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1728 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1729 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1731 /// Constructs a new NodeAnnouncementInfo given each field
1733 /// Note that announcement_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
1736 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 {
1737 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()) } }) };
1738 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1739 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1740 last_update: last_update_arg,
1742 alias: *unsafe { Box::from_raw(alias_arg.take_inner()) },
1743 announcement_message: local_announcement_message_arg,
1744 }), is_owned: true }
1746 impl Clone for NodeAnnouncementInfo {
1747 fn clone(&self) -> Self {
1749 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1750 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1756 /// Used only if an object of this type is returned as a trait impl by a method
1757 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1758 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1761 /// Creates a copy of the NodeAnnouncementInfo
1762 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1765 /// Get a string which allows debug introspection of a NodeAnnouncementInfo object
1766 pub extern "C" fn NodeAnnouncementInfo_debug_str_void(o: *const c_void) -> Str {
1767 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeAnnouncementInfo }).into()}
1768 /// Checks if two NodeAnnouncementInfos contain equal inner contents.
1769 /// This ignores pointers and is_owned flags and looks at the values in fields.
1770 /// Two objects with NULL inner values will be considered "equal" here.
1772 pub extern "C" fn NodeAnnouncementInfo_eq(a: &NodeAnnouncementInfo, b: &NodeAnnouncementInfo) -> bool {
1773 if a.inner == b.inner { return true; }
1774 if a.inner.is_null() || b.inner.is_null() { return false; }
1775 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1777 /// Internet-level addresses via which one can connect to the node
1780 pub extern "C" fn NodeAnnouncementInfo_addresses(this_arg: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_SocketAddressZ {
1781 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.addresses();
1782 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) }); };
1787 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1788 pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1789 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1792 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1793 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1796 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1797 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1798 let res: Result<lightning::routing::gossip::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1799 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() };
1803 use lightning::routing::gossip::NodeAlias as nativeNodeAliasImport;
1804 pub(crate) type nativeNodeAlias = nativeNodeAliasImport;
1806 /// A user-defined name for a node, which may be used when displaying the node in a graph.
1808 /// Since node aliases are provided by third parties, they are a potential avenue for injection
1809 /// attacks. Care must be taken when processing.
1812 pub struct NodeAlias {
1813 /// A pointer to the opaque Rust object.
1815 /// Nearly everywhere, inner must be non-null, however in places where
1816 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1817 pub inner: *mut nativeNodeAlias,
1818 /// Indicates that this is the only struct which contains the same pointer.
1820 /// Rust functions which take ownership of an object provided via an argument require
1821 /// this to be true and invalidate the object pointed to by inner.
1825 impl Drop for NodeAlias {
1826 fn drop(&mut self) {
1827 if self.is_owned && !<*mut nativeNodeAlias>::is_null(self.inner) {
1828 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1832 /// Frees any resources used by the NodeAlias, if is_owned is set and inner is non-NULL.
1834 pub extern "C" fn NodeAlias_free(this_obj: NodeAlias) { }
1836 /// Used only if an object of this type is returned as a trait impl by a method
1837 pub(crate) extern "C" fn NodeAlias_free_void(this_ptr: *mut c_void) {
1838 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAlias) };
1842 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAlias {
1843 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1845 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAlias {
1846 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1848 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1849 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAlias {
1850 assert!(self.is_owned);
1851 let ret = ObjOps::untweak_ptr(self.inner);
1852 self.inner = core::ptr::null_mut();
1857 pub extern "C" fn NodeAlias_get_a(this_ptr: &NodeAlias) -> *const [u8; 32] {
1858 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1862 pub extern "C" fn NodeAlias_set_a(this_ptr: &mut NodeAlias, mut val: crate::c_types::ThirtyTwoBytes) {
1863 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.data;
1865 /// Constructs a new NodeAlias given each field
1868 pub extern "C" fn NodeAlias_new(mut a_arg: crate::c_types::ThirtyTwoBytes) -> NodeAlias {
1869 NodeAlias { inner: ObjOps::heap_alloc(lightning::routing::gossip::NodeAlias (
1871 )), is_owned: true }
1873 impl Clone for NodeAlias {
1874 fn clone(&self) -> Self {
1876 inner: if <*mut nativeNodeAlias>::is_null(self.inner) { core::ptr::null_mut() } else {
1877 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1883 /// Used only if an object of this type is returned as a trait impl by a method
1884 pub(crate) extern "C" fn NodeAlias_clone_void(this_ptr: *const c_void) -> *mut c_void {
1885 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAlias)).clone() })) as *mut c_void
1888 /// Creates a copy of the NodeAlias
1889 pub extern "C" fn NodeAlias_clone(orig: &NodeAlias) -> NodeAlias {
1892 /// Get a string which allows debug introspection of a NodeAlias object
1893 pub extern "C" fn NodeAlias_debug_str_void(o: *const c_void) -> Str {
1894 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeAlias }).into()}
1895 /// Generates a non-cryptographic 64-bit hash of the NodeAlias.
1897 pub extern "C" fn NodeAlias_hash(o: &NodeAlias) -> u64 {
1898 if o.inner.is_null() { return 0; }
1899 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1900 #[allow(deprecated)]
1901 let mut hasher = core::hash::SipHasher::new();
1902 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1903 core::hash::Hasher::finish(&hasher)
1905 /// Checks if two NodeAliass contain equal inner contents.
1906 /// This ignores pointers and is_owned flags and looks at the values in fields.
1907 /// Two objects with NULL inner values will be considered "equal" here.
1909 pub extern "C" fn NodeAlias_eq(a: &NodeAlias, b: &NodeAlias) -> bool {
1910 if a.inner == b.inner { return true; }
1911 if a.inner.is_null() || b.inner.is_null() { return false; }
1912 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1915 /// Serialize the NodeAlias object into a byte array which can be read by NodeAlias_read
1916 pub extern "C" fn NodeAlias_write(obj: &crate::lightning::routing::gossip::NodeAlias) -> crate::c_types::derived::CVec_u8Z {
1917 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1920 pub(crate) extern "C" fn NodeAlias_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1921 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAlias) })
1924 /// Read a NodeAlias from a byte array, created by NodeAlias_write
1925 pub extern "C" fn NodeAlias_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAliasDecodeErrorZ {
1926 let res: Result<lightning::routing::gossip::NodeAlias, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1927 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() };
1931 use lightning::routing::gossip::NodeInfo as nativeNodeInfoImport;
1932 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1934 /// Details about a node in the network, known from the network announcement.
1937 pub struct NodeInfo {
1938 /// A pointer to the opaque Rust object.
1940 /// Nearly everywhere, inner must be non-null, however in places where
1941 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1942 pub inner: *mut nativeNodeInfo,
1943 /// Indicates that this is the only struct which contains the same pointer.
1945 /// Rust functions which take ownership of an object provided via an argument require
1946 /// this to be true and invalidate the object pointed to by inner.
1950 impl Drop for NodeInfo {
1951 fn drop(&mut self) {
1952 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1953 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1957 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1959 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1961 /// Used only if an object of this type is returned as a trait impl by a method
1962 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1963 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeInfo) };
1967 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1968 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1970 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1971 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1973 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1974 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1975 assert!(self.is_owned);
1976 let ret = ObjOps::untweak_ptr(self.inner);
1977 self.inner = core::ptr::null_mut();
1981 /// All valid channels a node has announced
1983 /// Returns a copy of the field.
1985 pub extern "C" fn NodeInfo_get_channels(this_ptr: &NodeInfo) -> crate::c_types::derived::CVec_u64Z {
1986 let mut inner_val = this_ptr.get_native_mut_ref().channels.clone();
1987 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1988 local_inner_val.into()
1990 /// All valid channels a node has announced
1992 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1993 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1994 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1996 /// More information about a node from node_announcement.
1997 /// Optional because we store a Node entry after learning about it from
1998 /// a channel announcement, but before receiving a node announcement.
2000 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2002 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::NodeAnnouncementInfo {
2003 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
2004 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 };
2007 /// More information about a node from node_announcement.
2008 /// Optional because we store a Node entry after learning about it from
2009 /// a channel announcement, but before receiving a node announcement.
2011 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
2013 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::NodeAnnouncementInfo) {
2014 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
2015 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
2017 /// Constructs a new NodeInfo given each field
2019 /// Note that announcement_info_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
2022 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 {
2023 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
2024 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()) } }) };
2025 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
2026 channels: local_channels_arg,
2027 announcement_info: local_announcement_info_arg,
2028 }), is_owned: true }
2030 impl Clone for NodeInfo {
2031 fn clone(&self) -> Self {
2033 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
2034 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2040 /// Used only if an object of this type is returned as a trait impl by a method
2041 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
2042 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeInfo)).clone() })) as *mut c_void
2045 /// Creates a copy of the NodeInfo
2046 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
2049 /// Get a string which allows debug introspection of a NodeInfo object
2050 pub extern "C" fn NodeInfo_debug_str_void(o: *const c_void) -> Str {
2051 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeInfo }).into()}
2052 /// Checks if two NodeInfos contain equal inner contents.
2053 /// This ignores pointers and is_owned flags and looks at the values in fields.
2054 /// Two objects with NULL inner values will be considered "equal" here.
2056 pub extern "C" fn NodeInfo_eq(a: &NodeInfo, b: &NodeInfo) -> bool {
2057 if a.inner == b.inner { return true; }
2058 if a.inner.is_null() || b.inner.is_null() { return false; }
2059 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2062 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
2063 pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::gossip::NodeInfo) -> crate::c_types::derived::CVec_u8Z {
2064 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2067 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2068 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
2071 /// Read a NodeInfo from a byte array, created by NodeInfo_write
2072 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
2073 let res: Result<lightning::routing::gossip::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2074 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() };
2078 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
2079 pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
2080 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2083 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2084 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
2087 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
2088 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
2090 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);
2091 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() };
2094 /// Creates a new, empty, network graph.
2097 pub extern "C" fn NetworkGraph_new(mut network: crate::bitcoin::network::Network, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph {
2098 let mut ret = lightning::routing::gossip::NetworkGraph::new(network.into_bitcoin(), logger);
2099 crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
2102 /// Returns a read-only view of the network graph.
2105 pub extern "C" fn NetworkGraph_read_only(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::lightning::routing::gossip::ReadOnlyNetworkGraph {
2106 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
2107 crate::lightning::routing::gossip::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
2110 /// The unix timestamp provided by the most recent rapid gossip sync.
2111 /// It will be set by the rapid sync process after every sync completion.
2114 pub extern "C" fn NetworkGraph_get_last_rapid_gossip_sync_timestamp(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::COption_u32Z {
2115 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_last_rapid_gossip_sync_timestamp();
2116 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() }) };
2120 /// Update the unix timestamp provided by the most recent rapid gossip sync.
2121 /// This should be done automatically by the rapid sync process after every sync completion.
2123 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) {
2124 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.set_last_rapid_gossip_sync_timestamp(last_rapid_gossip_sync_timestamp)
2127 /// For an already known node (from channel announcements), update its stored properties from a
2128 /// given node announcement.
2130 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
2131 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
2132 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2135 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 {
2136 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref());
2137 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() };
2141 /// For an already known node (from channel announcements), update its stored properties from a
2142 /// given node announcement without verifying the associated signatures. Because we aren't
2143 /// given the associated signatures here we cannot relay the node announcement to any of our
2147 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 {
2148 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
2149 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() };
2153 /// Store or update channel info from a channel announcement.
2155 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2156 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2157 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2159 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2160 /// the corresponding UTXO exists on chain and is correctly-formatted.
2163 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 {
2164 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() } }})} };
2165 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_utxo_lookup);
2166 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() };
2170 /// Store or update channel info from a channel announcement.
2172 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2173 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2174 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2176 /// This will skip verification of if the channel is actually on-chain.
2179 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 {
2180 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement_no_lookup(msg.get_native_ref());
2181 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() };
2185 /// Store or update channel info from a channel announcement without verifying the associated
2186 /// signatures. Because we aren't given the associated signatures here we cannot relay the
2187 /// channel announcement to any of our peers.
2189 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2190 /// the corresponding UTXO exists on chain and is correctly-formatted.
2193 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 {
2194 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() } }})} };
2195 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_utxo_lookup);
2196 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() };
2200 /// Update channel from partial announcement data received via rapid gossip sync
2202 /// `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
2203 /// rapid gossip sync server)
2205 /// All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
2208 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 {
2209 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());
2210 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() };
2214 /// Marks a channel in the graph as failed permanently.
2216 /// The channel and any node for which this was their last channel are removed from the graph.
2218 pub extern "C" fn NetworkGraph_channel_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64) {
2219 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed_permanent(short_channel_id)
2222 /// Marks a node in the graph as permanently failed, effectively removing it and its channels
2223 /// from local storage.
2225 pub extern "C" fn NetworkGraph_node_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut node_id: crate::c_types::PublicKey) {
2226 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node_failed_permanent(&node_id.into_rust())
2229 /// Removes information about channels that we haven't heard any updates about in some time.
2230 /// This can be used regularly to prune the network graph of channels that likely no longer
2233 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2234 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2235 /// pruning occur for updates which are at least two weeks old, which we implement here.
2237 /// Note that for users of the `lightning-background-processor` crate this method may be
2238 /// automatically called regularly for you.
2240 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2241 /// in the map for a while so that these can be resynced from gossip in the future.
2243 /// This method is only available with the `std` feature. See
2244 /// [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for `no-std` use.
2246 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking(this_arg: &crate::lightning::routing::gossip::NetworkGraph) {
2247 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking()
2250 /// Removes information about channels that we haven't heard any updates about in some time.
2251 /// This can be used regularly to prune the network graph of channels that likely no longer
2254 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2255 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2256 /// pruning occur for updates which are at least two weeks old, which we implement here.
2258 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2259 /// in the map for a while so that these can be resynced from gossip in the future.
2261 /// This function takes the current unix time as an argument. For users with the `std` feature
2262 /// enabled, [`NetworkGraph::remove_stale_channels_and_tracking`] may be preferable.
2264 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking_with_time(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut current_time_unix: u64) {
2265 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking_with_time(current_time_unix)
2268 /// For an already known (from announcement) channel, update info about one of the directions
2271 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2272 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2273 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2275 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2276 /// materially in the future will be rejected.
2279 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 {
2280 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref());
2281 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() };
2285 /// For an already known (from announcement) channel, update info about one of the directions
2286 /// of the channel without verifying the associated signatures. Because we aren't given the
2287 /// associated signatures here we cannot relay the channel update to any of our peers.
2289 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2290 /// materially in the future will be rejected.
2293 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 {
2294 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
2295 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() };
2299 /// For an already known (from announcement) channel, verify the given [`ChannelUpdate`].
2301 /// This checks whether the update currently is applicable by [`Self::update_channel`].
2303 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2304 /// materially in the future will be rejected.
2307 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 {
2308 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify_channel_update(msg.get_native_ref());
2309 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() };
2313 /// Returns information on a channel with the given id.
2315 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2318 pub extern "C" fn ReadOnlyNetworkGraph_channel(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut short_channel_id: u64) -> crate::lightning::routing::gossip::ChannelInfo {
2319 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel(short_channel_id);
2320 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 };
2324 /// Returns the list of channels in the graph
2327 pub extern "C" fn ReadOnlyNetworkGraph_list_channels(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_u64Z {
2328 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
2329 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { item }); };
2333 /// Returns information on a node with the given id.
2335 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2338 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 {
2339 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node(node_id.get_native_ref());
2340 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 };
2344 /// Returns the list of nodes in the graph
2347 pub extern "C" fn ReadOnlyNetworkGraph_list_nodes(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_NodeIdZ {
2348 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_nodes();
2349 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 } }); };
2353 /// Get network addresses by node id.
2354 /// Returns None if the requested node is completely unknown,
2355 /// or if node announcement for the node was never received.
2358 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 {
2359 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust());
2360 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() }) };