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 *mut 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 from this NodeId
110 pub extern "C" fn NodeId_as_pubkey(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CResult_PublicKeySecp256k1ErrorZ {
111 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_pubkey();
112 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() };
116 /// Generates a non-cryptographic 64-bit hash of the NodeId.
118 pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 {
119 if o.inner.is_null() { return 0; }
120 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
122 let mut hasher = core::hash::SipHasher::new();
123 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
124 core::hash::Hasher::finish(&hasher)
127 /// Serialize the NodeId object into a byte array which can be read by NodeId_read
128 pub extern "C" fn NodeId_write(obj: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CVec_u8Z {
129 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
132 pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
133 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) })
136 /// Read a NodeId from a byte array, created by NodeId_write
137 pub extern "C" fn NodeId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ {
138 let res: Result<lightning::routing::gossip::NodeId, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
139 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() };
143 use lightning::routing::gossip::NetworkGraph as nativeNetworkGraphImport;
144 pub(crate) type nativeNetworkGraph = nativeNetworkGraphImport<crate::lightning::util::logger::Logger>;
146 /// Represents the network as nodes and channels between them
149 pub struct NetworkGraph {
150 /// A pointer to the opaque Rust object.
152 /// Nearly everywhere, inner must be non-null, however in places where
153 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
154 pub inner: *mut nativeNetworkGraph,
155 /// Indicates that this is the only struct which contains the same pointer.
157 /// Rust functions which take ownership of an object provided via an argument require
158 /// this to be true and invalidate the object pointed to by inner.
162 impl Drop for NetworkGraph {
164 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
165 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
169 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
171 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
173 /// Used only if an object of this type is returned as a trait impl by a method
174 pub(crate) extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
175 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNetworkGraph) };
179 pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
180 unsafe { &*ObjOps::untweak_ptr(self.inner) }
182 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
183 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
185 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
186 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
187 assert!(self.is_owned);
188 let ret = ObjOps::untweak_ptr(self.inner);
189 self.inner = core::ptr::null_mut();
194 use lightning::routing::gossip::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
195 pub(crate) type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
197 /// A read-only view of [`NetworkGraph`].
200 pub struct ReadOnlyNetworkGraph {
201 /// A pointer to the opaque Rust object.
203 /// Nearly everywhere, inner must be non-null, however in places where
204 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
205 pub inner: *mut nativeReadOnlyNetworkGraph,
206 /// Indicates that this is the only struct which contains the same pointer.
208 /// Rust functions which take ownership of an object provided via an argument require
209 /// this to be true and invalidate the object pointed to by inner.
213 impl Drop for ReadOnlyNetworkGraph {
215 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
216 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
220 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
222 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
224 /// Used only if an object of this type is returned as a trait impl by a method
225 pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
226 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph) };
229 impl ReadOnlyNetworkGraph {
230 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
231 unsafe { &*ObjOps::untweak_ptr(self.inner) }
233 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
234 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
236 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
237 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
238 assert!(self.is_owned);
239 let ret = ObjOps::untweak_ptr(self.inner);
240 self.inner = core::ptr::null_mut();
244 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
245 /// return packet by a node along the route. See [BOLT #4] for details.
247 /// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
251 pub enum NetworkUpdate {
252 /// An error indicating a `channel_update` messages should be applied via
253 /// [`NetworkGraph::update_channel`].
254 ChannelUpdateMessage {
255 /// The update to apply via [`NetworkGraph::update_channel`].
256 msg: crate::lightning::ln::msgs::ChannelUpdate,
258 /// An error indicating that a channel failed to route a payment, which should be applied via
259 /// [`NetworkGraph::channel_failed_permanent`] if permanent.
261 /// The short channel id of the closed channel.
262 short_channel_id: u64,
263 /// Whether the channel should be permanently removed or temporarily disabled until a new
264 /// `channel_update` message is received.
267 /// An error indicating that a node failed to route a payment, which should be applied via
268 /// [`NetworkGraph::node_failed_permanent`] if permanent.
270 /// The node id of the failed node.
271 node_id: crate::c_types::PublicKey,
272 /// Whether the node should be permanently removed from consideration or can be restored
273 /// when a new `channel_update` message is received.
277 use lightning::routing::gossip::NetworkUpdate as NetworkUpdateImport;
278 pub(crate) type nativeNetworkUpdate = NetworkUpdateImport;
282 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
284 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
285 let mut msg_nonref = Clone::clone(msg);
286 nativeNetworkUpdate::ChannelUpdateMessage {
287 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
290 NetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
291 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
292 let mut is_permanent_nonref = Clone::clone(is_permanent);
293 nativeNetworkUpdate::ChannelFailure {
294 short_channel_id: short_channel_id_nonref,
295 is_permanent: is_permanent_nonref,
298 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
299 let mut node_id_nonref = Clone::clone(node_id);
300 let mut is_permanent_nonref = Clone::clone(is_permanent);
301 nativeNetworkUpdate::NodeFailure {
302 node_id: node_id_nonref.into_rust(),
303 is_permanent: is_permanent_nonref,
309 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
311 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
312 nativeNetworkUpdate::ChannelUpdateMessage {
313 msg: *unsafe { Box::from_raw(msg.take_inner()) },
316 NetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
317 nativeNetworkUpdate::ChannelFailure {
318 short_channel_id: short_channel_id,
319 is_permanent: is_permanent,
322 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
323 nativeNetworkUpdate::NodeFailure {
324 node_id: node_id.into_rust(),
325 is_permanent: is_permanent,
331 pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
333 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
334 let mut msg_nonref = Clone::clone(msg);
335 NetworkUpdate::ChannelUpdateMessage {
336 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
339 nativeNetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
340 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
341 let mut is_permanent_nonref = Clone::clone(is_permanent);
342 NetworkUpdate::ChannelFailure {
343 short_channel_id: short_channel_id_nonref,
344 is_permanent: is_permanent_nonref,
347 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
348 let mut node_id_nonref = Clone::clone(node_id);
349 let mut is_permanent_nonref = Clone::clone(is_permanent);
350 NetworkUpdate::NodeFailure {
351 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
352 is_permanent: is_permanent_nonref,
358 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
360 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
361 NetworkUpdate::ChannelUpdateMessage {
362 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
365 nativeNetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
366 NetworkUpdate::ChannelFailure {
367 short_channel_id: short_channel_id,
368 is_permanent: is_permanent,
371 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
372 NetworkUpdate::NodeFailure {
373 node_id: crate::c_types::PublicKey::from_rust(&node_id),
374 is_permanent: is_permanent,
380 /// Frees any resources used by the NetworkUpdate
382 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
383 /// Creates a copy of the NetworkUpdate
385 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
389 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
390 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
391 NetworkUpdate::ChannelUpdateMessage {
396 /// Utility method to constructs a new ChannelFailure-variant NetworkUpdate
397 pub extern "C" fn NetworkUpdate_channel_failure(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
398 NetworkUpdate::ChannelFailure {
404 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
405 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
406 NetworkUpdate::NodeFailure {
411 /// Checks if two NetworkUpdates contain equal inner contents.
412 /// This ignores pointers and is_owned flags and looks at the values in fields.
414 pub extern "C" fn NetworkUpdate_eq(a: &NetworkUpdate, b: &NetworkUpdate) -> bool {
415 if &a.to_native() == &b.to_native() { true } else { false }
418 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
419 pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::gossip::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
420 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
423 /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
424 pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ {
425 let res: Result<Option<lightning::routing::gossip::NetworkUpdate>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
426 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() };
430 use lightning::routing::gossip::P2PGossipSync as nativeP2PGossipSyncImport;
431 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>;
433 /// Receives and validates network updates from peers,
434 /// stores authentic and relevant data as a network graph.
435 /// This network graph is then used for routing payments.
436 /// Provides interface to help with initial routing sync by
437 /// serving historical announcements.
440 pub struct P2PGossipSync {
441 /// A pointer to the opaque Rust object.
443 /// Nearly everywhere, inner must be non-null, however in places where
444 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
445 pub inner: *mut nativeP2PGossipSync,
446 /// Indicates that this is the only struct which contains the same pointer.
448 /// Rust functions which take ownership of an object provided via an argument require
449 /// this to be true and invalidate the object pointed to by inner.
453 impl Drop for P2PGossipSync {
455 if self.is_owned && !<*mut nativeP2PGossipSync>::is_null(self.inner) {
456 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
460 /// Frees any resources used by the P2PGossipSync, if is_owned is set and inner is non-NULL.
462 pub extern "C" fn P2PGossipSync_free(this_obj: P2PGossipSync) { }
464 /// Used only if an object of this type is returned as a trait impl by a method
465 pub(crate) extern "C" fn P2PGossipSync_free_void(this_ptr: *mut c_void) {
466 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeP2PGossipSync) };
470 pub(crate) fn get_native_ref(&self) -> &'static nativeP2PGossipSync {
471 unsafe { &*ObjOps::untweak_ptr(self.inner) }
473 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeP2PGossipSync {
474 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
476 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
477 pub(crate) fn take_inner(mut self) -> *mut nativeP2PGossipSync {
478 assert!(self.is_owned);
479 let ret = ObjOps::untweak_ptr(self.inner);
480 self.inner = core::ptr::null_mut();
484 /// Creates a new tracker of the actual state of the network of channels and nodes,
485 /// assuming an existing [`NetworkGraph`].
486 /// UTXO lookup is used to make sure announced channels exist on-chain, channel data is
487 /// correct, and the announcement is signed with channel owners' keys.
490 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 {
491 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() } }})} };
492 let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_utxo_lookup, logger);
493 crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(ret), is_owned: true }
496 /// Adds a provider used to check new announcements. Does not affect
497 /// existing announcements unless they are updated.
498 /// Add, update or remove the provider would replace the current one.
500 pub extern "C" fn P2PGossipSync_add_utxo_lookup(this_arg: &crate::lightning::routing::gossip::P2PGossipSync, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) {
501 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() } }})} };
502 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.add_utxo_lookup(local_utxo_lookup)
505 /// Handles any network updates originating from [`Event`]s.
507 /// [`Event`]: crate::events::Event
509 pub extern "C" fn NetworkGraph_handle_network_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, network_update: &crate::lightning::routing::gossip::NetworkUpdate) {
510 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_network_update(&network_update.to_native())
513 /// Gets the genesis hash for this network graph.
516 pub extern "C" fn NetworkGraph_get_genesis_hash(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::ThirtyTwoBytes {
517 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_genesis_hash();
518 crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
521 /// Verifies the signature of a [`NodeAnnouncement`].
523 /// Returns an error if it is invalid.
525 pub extern "C" fn verify_node_announcement(msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
526 let mut ret = lightning::routing::gossip::verify_node_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1);
527 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() };
531 /// Verifies all signatures included in a [`ChannelAnnouncement`].
533 /// Returns an error if one of the signatures is invalid.
535 pub extern "C" fn verify_channel_announcement(msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
536 let mut ret = lightning::routing::gossip::verify_channel_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1);
537 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() };
541 impl From<nativeP2PGossipSync> for crate::lightning::ln::msgs::RoutingMessageHandler {
542 fn from(obj: nativeP2PGossipSync) -> Self {
543 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
544 let mut ret = P2PGossipSync_as_RoutingMessageHandler(&rust_obj);
545 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
546 rust_obj.inner = core::ptr::null_mut();
547 ret.free = Some(P2PGossipSync_free_void);
551 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
552 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
554 pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSync) -> crate::lightning::ln::msgs::RoutingMessageHandler {
555 crate::lightning::ln::msgs::RoutingMessageHandler {
556 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
558 handle_node_announcement: P2PGossipSync_RoutingMessageHandler_handle_node_announcement,
559 handle_channel_announcement: P2PGossipSync_RoutingMessageHandler_handle_channel_announcement,
560 handle_channel_update: P2PGossipSync_RoutingMessageHandler_handle_channel_update,
561 get_next_channel_announcement: P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement,
562 get_next_node_announcement: P2PGossipSync_RoutingMessageHandler_get_next_node_announcement,
563 peer_connected: P2PGossipSync_RoutingMessageHandler_peer_connected,
564 handle_reply_channel_range: P2PGossipSync_RoutingMessageHandler_handle_reply_channel_range,
565 handle_reply_short_channel_ids_end: P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end,
566 handle_query_channel_range: P2PGossipSync_RoutingMessageHandler_handle_query_channel_range,
567 handle_query_short_channel_ids: P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids,
568 processing_queue_high: P2PGossipSync_RoutingMessageHandler_processing_queue_high,
569 provided_node_features: P2PGossipSync_RoutingMessageHandler_provided_node_features,
570 provided_init_features: P2PGossipSync_RoutingMessageHandler_provided_init_features,
571 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
572 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
574 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
580 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 {
581 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
582 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() };
586 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 {
587 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
588 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() };
592 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 {
593 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
594 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() };
598 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 {
599 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, starting_point);
600 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 }) };
604 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 {
605 let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
606 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, local_starting_point);
607 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 };
611 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 {
612 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);
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( { () /*e*/ }).into() };
617 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 {
618 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()) });
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_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 {
624 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()) });
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_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 {
630 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()) });
631 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() };
635 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 {
636 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()) });
637 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() };
641 extern "C" fn P2PGossipSync_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
642 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
646 extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
647 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
648 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
651 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 {
652 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust());
653 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
656 impl From<nativeP2PGossipSync> for crate::lightning::events::MessageSendEventsProvider {
657 fn from(obj: nativeP2PGossipSync) -> Self {
658 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
659 let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj);
660 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
661 rust_obj.inner = core::ptr::null_mut();
662 ret.free = Some(P2PGossipSync_free_void);
666 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
667 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
669 pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::events::MessageSendEventsProvider {
670 crate::lightning::events::MessageSendEventsProvider {
671 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
673 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
678 extern "C" fn P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
679 let mut ret = <nativeP2PGossipSync as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
680 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
685 use lightning::routing::gossip::ChannelUpdateInfo as nativeChannelUpdateInfoImport;
686 pub(crate) type nativeChannelUpdateInfo = nativeChannelUpdateInfoImport;
688 /// Details about one direction of a channel as received within a [`ChannelUpdate`].
691 pub struct ChannelUpdateInfo {
692 /// A pointer to the opaque Rust object.
694 /// Nearly everywhere, inner must be non-null, however in places where
695 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
696 pub inner: *mut nativeChannelUpdateInfo,
697 /// Indicates that this is the only struct which contains the same pointer.
699 /// Rust functions which take ownership of an object provided via an argument require
700 /// this to be true and invalidate the object pointed to by inner.
704 impl Drop for ChannelUpdateInfo {
706 if self.is_owned && !<*mut nativeChannelUpdateInfo>::is_null(self.inner) {
707 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
711 /// Frees any resources used by the ChannelUpdateInfo, if is_owned is set and inner is non-NULL.
713 pub extern "C" fn ChannelUpdateInfo_free(this_obj: ChannelUpdateInfo) { }
715 /// Used only if an object of this type is returned as a trait impl by a method
716 pub(crate) extern "C" fn ChannelUpdateInfo_free_void(this_ptr: *mut c_void) {
717 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo) };
720 impl ChannelUpdateInfo {
721 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUpdateInfo {
722 unsafe { &*ObjOps::untweak_ptr(self.inner) }
724 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUpdateInfo {
725 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
727 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
728 pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdateInfo {
729 assert!(self.is_owned);
730 let ret = ObjOps::untweak_ptr(self.inner);
731 self.inner = core::ptr::null_mut();
735 /// When the last update to the channel direction was issued.
736 /// Value is opaque, as set in the announcement.
738 pub extern "C" fn ChannelUpdateInfo_get_last_update(this_ptr: &ChannelUpdateInfo) -> u32 {
739 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
742 /// When the last update to the channel direction was issued.
743 /// Value is opaque, as set in the announcement.
745 pub extern "C" fn ChannelUpdateInfo_set_last_update(this_ptr: &mut ChannelUpdateInfo, mut val: u32) {
746 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
748 /// Whether the channel can be currently used for payments (in this one direction).
750 pub extern "C" fn ChannelUpdateInfo_get_enabled(this_ptr: &ChannelUpdateInfo) -> bool {
751 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
754 /// Whether the channel can be currently used for payments (in this one direction).
756 pub extern "C" fn ChannelUpdateInfo_set_enabled(this_ptr: &mut ChannelUpdateInfo, mut val: bool) {
757 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
759 /// The difference in CLTV values that you must have when routing through this channel.
761 pub extern "C" fn ChannelUpdateInfo_get_cltv_expiry_delta(this_ptr: &ChannelUpdateInfo) -> u16 {
762 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
765 /// The difference in CLTV values that you must have when routing through this channel.
767 pub extern "C" fn ChannelUpdateInfo_set_cltv_expiry_delta(this_ptr: &mut ChannelUpdateInfo, mut val: u16) {
768 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
770 /// The minimum value, which must be relayed to the next hop via the channel
772 pub extern "C" fn ChannelUpdateInfo_get_htlc_minimum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
773 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
776 /// The minimum value, which must be relayed to the next hop via the channel
778 pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
779 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
781 /// The maximum value which may be relayed to the next hop via the channel.
783 pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
784 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
787 /// The maximum value which may be relayed to the next hop via the channel.
789 pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
790 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
792 /// Fees charged when the channel is used for routing
794 pub extern "C" fn ChannelUpdateInfo_get_fees(this_ptr: &ChannelUpdateInfo) -> crate::lightning::routing::gossip::RoutingFees {
795 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
796 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 }
798 /// Fees charged when the channel is used for routing
800 pub extern "C" fn ChannelUpdateInfo_set_fees(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::routing::gossip::RoutingFees) {
801 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
803 /// Most recent update for the channel received from the network
804 /// Mostly redundant with the data we store in fields explicitly.
805 /// Everything else is useful only for sending out for initial routing sync.
806 /// Not stored if contains excess data to prevent DoS.
808 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
810 pub extern "C" fn ChannelUpdateInfo_get_last_update_message(this_ptr: &ChannelUpdateInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
811 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
812 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 };
815 /// Most recent update for the channel received from the network
816 /// Mostly redundant with the data we store in fields explicitly.
817 /// Everything else is useful only for sending out for initial routing sync.
818 /// Not stored if contains excess data to prevent DoS.
820 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
822 pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
823 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
824 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
826 /// Constructs a new ChannelUpdateInfo given each field
828 /// Note that last_update_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
831 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 {
832 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()) } }) };
833 ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo {
834 last_update: last_update_arg,
835 enabled: enabled_arg,
836 cltv_expiry_delta: cltv_expiry_delta_arg,
837 htlc_minimum_msat: htlc_minimum_msat_arg,
838 htlc_maximum_msat: htlc_maximum_msat_arg,
839 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
840 last_update_message: local_last_update_message_arg,
843 impl Clone for ChannelUpdateInfo {
844 fn clone(&self) -> Self {
846 inner: if <*mut nativeChannelUpdateInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
847 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
853 /// Used only if an object of this type is returned as a trait impl by a method
854 pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
855 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdateInfo)).clone() })) as *mut c_void
858 /// Creates a copy of the ChannelUpdateInfo
859 pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo {
862 /// Checks if two ChannelUpdateInfos contain equal inner contents.
863 /// This ignores pointers and is_owned flags and looks at the values in fields.
864 /// Two objects with NULL inner values will be considered "equal" here.
866 pub extern "C" fn ChannelUpdateInfo_eq(a: &ChannelUpdateInfo, b: &ChannelUpdateInfo) -> bool {
867 if a.inner == b.inner { return true; }
868 if a.inner.is_null() || b.inner.is_null() { return false; }
869 if a.get_native_ref() == b.get_native_ref() { true } else { false }
872 /// Serialize the ChannelUpdateInfo object into a byte array which can be read by ChannelUpdateInfo_read
873 pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::gossip::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z {
874 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
877 pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
878 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) })
881 /// Read a ChannelUpdateInfo from a byte array, created by ChannelUpdateInfo_write
882 pub extern "C" fn ChannelUpdateInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateInfoDecodeErrorZ {
883 let res: Result<lightning::routing::gossip::ChannelUpdateInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
884 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() };
888 use lightning::routing::gossip::ChannelInfo as nativeChannelInfoImport;
889 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
891 /// Details about a channel (both directions).
892 /// Received within a channel announcement.
895 pub struct ChannelInfo {
896 /// A pointer to the opaque Rust object.
898 /// Nearly everywhere, inner must be non-null, however in places where
899 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
900 pub inner: *mut nativeChannelInfo,
901 /// Indicates that this is the only struct which contains the same pointer.
903 /// Rust functions which take ownership of an object provided via an argument require
904 /// this to be true and invalidate the object pointed to by inner.
908 impl Drop for ChannelInfo {
910 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
911 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
915 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
917 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
919 /// Used only if an object of this type is returned as a trait impl by a method
920 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
921 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelInfo) };
925 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
926 unsafe { &*ObjOps::untweak_ptr(self.inner) }
928 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
929 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
931 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
932 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
933 assert!(self.is_owned);
934 let ret = ObjOps::untweak_ptr(self.inner);
935 self.inner = core::ptr::null_mut();
939 /// Protocol features of a channel communicated during its announcement
941 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
942 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
943 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 }
945 /// Protocol features of a channel communicated during its announcement
947 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
948 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
950 /// Source node of the first direction of a channel
952 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
953 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
954 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 }
956 /// Source node of the first direction of a channel
958 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
959 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
961 /// Details about the first direction of a channel
963 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
965 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
966 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
967 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 };
970 /// Details about the first direction of a channel
972 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
974 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
975 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
976 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
978 /// Source node of the second direction of a channel
980 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
981 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
982 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 }
984 /// Source node of the second direction of a channel
986 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
987 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
989 /// Details about the second direction of a channel
991 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
993 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
994 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
995 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 };
998 /// Details about the second direction of a channel
1000 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1002 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
1003 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1004 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
1006 /// The channel capacity as seen on-chain, if chain lookup is available.
1008 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
1009 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
1010 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() }) };
1013 /// The channel capacity as seen on-chain, if chain lookup is available.
1015 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
1016 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1017 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
1019 /// An initial announcement of the channel
1020 /// Mostly redundant with the data we store in fields explicitly.
1021 /// Everything else is useful only for sending out for initial routing sync.
1022 /// Not stored if contains excess data to prevent DoS.
1024 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1026 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
1027 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1028 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 };
1031 /// An initial announcement of the channel
1032 /// Mostly redundant with the data we store in fields explicitly.
1033 /// Everything else is useful only for sending out for initial routing sync.
1034 /// Not stored if contains excess data to prevent DoS.
1036 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1038 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
1039 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1040 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1042 impl Clone for ChannelInfo {
1043 fn clone(&self) -> Self {
1045 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1046 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1052 /// Used only if an object of this type is returned as a trait impl by a method
1053 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1054 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
1057 /// Creates a copy of the ChannelInfo
1058 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1061 /// Checks if two ChannelInfos contain equal inner contents.
1062 /// This ignores pointers and is_owned flags and looks at the values in fields.
1063 /// Two objects with NULL inner values will be considered "equal" here.
1065 pub extern "C" fn ChannelInfo_eq(a: &ChannelInfo, b: &ChannelInfo) -> bool {
1066 if a.inner == b.inner { return true; }
1067 if a.inner.is_null() || b.inner.is_null() { return false; }
1068 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1070 /// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
1072 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1075 pub extern "C" fn ChannelInfo_get_directional_info(this_arg: &crate::lightning::routing::gossip::ChannelInfo, mut channel_flags: u8) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1076 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_directional_info(channel_flags);
1077 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 };
1082 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1083 pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::gossip::ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1084 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1087 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1088 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1091 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1092 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1093 let res: Result<lightning::routing::gossip::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1094 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() };
1098 use lightning::routing::gossip::DirectedChannelInfo as nativeDirectedChannelInfoImport;
1099 pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static>;
1101 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
1102 /// source node to a target node.
1105 pub struct DirectedChannelInfo {
1106 /// A pointer to the opaque Rust object.
1108 /// Nearly everywhere, inner must be non-null, however in places where
1109 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1110 pub inner: *mut nativeDirectedChannelInfo,
1111 /// Indicates that this is the only struct which contains the same pointer.
1113 /// Rust functions which take ownership of an object provided via an argument require
1114 /// this to be true and invalidate the object pointed to by inner.
1118 impl Drop for DirectedChannelInfo {
1119 fn drop(&mut self) {
1120 if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
1121 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1125 /// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
1127 pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
1129 /// Used only if an object of this type is returned as a trait impl by a method
1130 pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
1131 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo) };
1134 impl DirectedChannelInfo {
1135 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
1136 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1138 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
1139 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1141 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1142 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelInfo {
1143 assert!(self.is_owned);
1144 let ret = ObjOps::untweak_ptr(self.inner);
1145 self.inner = core::ptr::null_mut();
1149 impl Clone for DirectedChannelInfo {
1150 fn clone(&self) -> Self {
1152 inner: if <*mut nativeDirectedChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1153 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1159 /// Used only if an object of this type is returned as a trait impl by a method
1160 pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1161 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void
1164 /// Creates a copy of the DirectedChannelInfo
1165 pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
1168 /// Returns information for the channel.
1171 pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::ChannelInfo {
1172 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
1173 crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::ChannelInfo<>) as *mut _) }, is_owned: false }
1176 /// Returns the maximum HTLC amount allowed over the channel in the direction.
1179 pub extern "C" fn DirectedChannelInfo_htlc_maximum_msat(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> u64 {
1180 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.htlc_maximum_msat();
1184 /// Returns the [`EffectiveCapacity`] of the channel in the direction.
1186 /// This is either the total capacity from the funding transaction, if known, or the
1187 /// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
1191 pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::EffectiveCapacity {
1192 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
1193 crate::lightning::routing::gossip::EffectiveCapacity::native_into(ret)
1196 /// The effective capacity of a channel for routing purposes.
1198 /// While this may be smaller than the actual channel capacity, amounts greater than
1199 /// [`Self::as_msat`] should not be routed through the channel.
1203 pub enum EffectiveCapacity {
1204 /// The available liquidity in the channel known from being a channel counterparty, and thus a
1207 /// Either the inbound or outbound liquidity depending on the direction, denominated in
1209 liquidity_msat: u64,
1211 /// The maximum HTLC amount in one direction as advertised on the gossip network.
1213 /// The maximum HTLC amount denominated in millisatoshi.
1216 /// The total capacity of the channel as determined by the funding transaction.
1218 /// The funding amount denominated in millisatoshi.
1220 /// The maximum HTLC amount denominated in millisatoshi.
1221 htlc_maximum_msat: u64,
1223 /// A capacity sufficient to route any payment, typically used for private channels provided by
1226 /// The maximum HTLC amount as provided by an invoice route hint.
1228 /// The maximum HTLC amount denominated in millisatoshi.
1231 /// A capacity that is unknown possibly because either the chain state is unavailable to know
1232 /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
1235 use lightning::routing::gossip::EffectiveCapacity as EffectiveCapacityImport;
1236 pub(crate) type nativeEffectiveCapacity = EffectiveCapacityImport;
1238 impl EffectiveCapacity {
1240 pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
1242 EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1243 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1244 nativeEffectiveCapacity::ExactLiquidity {
1245 liquidity_msat: liquidity_msat_nonref,
1248 EffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => {
1249 let mut amount_msat_nonref = Clone::clone(amount_msat);
1250 nativeEffectiveCapacity::AdvertisedMaxHTLC {
1251 amount_msat: amount_msat_nonref,
1254 EffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1255 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1256 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1257 nativeEffectiveCapacity::Total {
1258 capacity_msat: capacity_msat_nonref,
1259 htlc_maximum_msat: htlc_maximum_msat_nonref,
1262 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1263 EffectiveCapacity::HintMaxHTLC {ref amount_msat, } => {
1264 let mut amount_msat_nonref = Clone::clone(amount_msat);
1265 nativeEffectiveCapacity::HintMaxHTLC {
1266 amount_msat: amount_msat_nonref,
1269 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1273 pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
1275 EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1276 nativeEffectiveCapacity::ExactLiquidity {
1277 liquidity_msat: liquidity_msat,
1280 EffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => {
1281 nativeEffectiveCapacity::AdvertisedMaxHTLC {
1282 amount_msat: amount_msat,
1285 EffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1286 nativeEffectiveCapacity::Total {
1287 capacity_msat: capacity_msat,
1288 htlc_maximum_msat: htlc_maximum_msat,
1291 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1292 EffectiveCapacity::HintMaxHTLC {mut amount_msat, } => {
1293 nativeEffectiveCapacity::HintMaxHTLC {
1294 amount_msat: amount_msat,
1297 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1301 pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self {
1303 nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1304 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1305 EffectiveCapacity::ExactLiquidity {
1306 liquidity_msat: liquidity_msat_nonref,
1309 nativeEffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => {
1310 let mut amount_msat_nonref = Clone::clone(amount_msat);
1311 EffectiveCapacity::AdvertisedMaxHTLC {
1312 amount_msat: amount_msat_nonref,
1315 nativeEffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1316 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1317 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1318 EffectiveCapacity::Total {
1319 capacity_msat: capacity_msat_nonref,
1320 htlc_maximum_msat: htlc_maximum_msat_nonref,
1323 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1324 nativeEffectiveCapacity::HintMaxHTLC {ref amount_msat, } => {
1325 let mut amount_msat_nonref = Clone::clone(amount_msat);
1326 EffectiveCapacity::HintMaxHTLC {
1327 amount_msat: amount_msat_nonref,
1330 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1334 pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
1336 nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1337 EffectiveCapacity::ExactLiquidity {
1338 liquidity_msat: liquidity_msat,
1341 nativeEffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => {
1342 EffectiveCapacity::AdvertisedMaxHTLC {
1343 amount_msat: amount_msat,
1346 nativeEffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1347 EffectiveCapacity::Total {
1348 capacity_msat: capacity_msat,
1349 htlc_maximum_msat: htlc_maximum_msat,
1352 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1353 nativeEffectiveCapacity::HintMaxHTLC {mut amount_msat, } => {
1354 EffectiveCapacity::HintMaxHTLC {
1355 amount_msat: amount_msat,
1358 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1362 /// Frees any resources used by the EffectiveCapacity
1364 pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
1365 /// Creates a copy of the EffectiveCapacity
1367 pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
1371 /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
1372 pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
1373 EffectiveCapacity::ExactLiquidity {
1378 /// Utility method to constructs a new AdvertisedMaxHTLC-variant EffectiveCapacity
1379 pub extern "C" fn EffectiveCapacity_advertised_max_htlc(amount_msat: u64) -> EffectiveCapacity {
1380 EffectiveCapacity::AdvertisedMaxHTLC {
1385 /// Utility method to constructs a new Total-variant EffectiveCapacity
1386 pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: u64) -> EffectiveCapacity {
1387 EffectiveCapacity::Total {
1393 /// Utility method to constructs a new Infinite-variant EffectiveCapacity
1394 pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
1395 EffectiveCapacity::Infinite}
1397 /// Utility method to constructs a new HintMaxHTLC-variant EffectiveCapacity
1398 pub extern "C" fn EffectiveCapacity_hint_max_htlc(amount_msat: u64) -> EffectiveCapacity {
1399 EffectiveCapacity::HintMaxHTLC {
1404 /// Utility method to constructs a new Unknown-variant EffectiveCapacity
1405 pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
1406 EffectiveCapacity::Unknown}
1407 /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
1408 /// use when making routing decisions.
1411 pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::gossip::UNKNOWN_CHANNEL_CAPACITY_MSAT;
1412 /// Returns the effective capacity denominated in millisatoshi.
1415 pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &crate::lightning::routing::gossip::EffectiveCapacity) -> u64 {
1416 let mut ret = this_arg.to_native().as_msat();
1421 use lightning::routing::gossip::RoutingFees as nativeRoutingFeesImport;
1422 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1424 /// Fees for routing via a given channel or a node
1427 pub struct RoutingFees {
1428 /// A pointer to the opaque Rust object.
1430 /// Nearly everywhere, inner must be non-null, however in places where
1431 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1432 pub inner: *mut nativeRoutingFees,
1433 /// Indicates that this is the only struct which contains the same pointer.
1435 /// Rust functions which take ownership of an object provided via an argument require
1436 /// this to be true and invalidate the object pointed to by inner.
1440 impl Drop for RoutingFees {
1441 fn drop(&mut self) {
1442 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
1443 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1447 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
1449 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
1451 /// Used only if an object of this type is returned as a trait impl by a method
1452 pub(crate) extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
1453 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoutingFees) };
1457 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1458 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1460 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
1461 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1463 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1464 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
1465 assert!(self.is_owned);
1466 let ret = ObjOps::untweak_ptr(self.inner);
1467 self.inner = core::ptr::null_mut();
1471 /// Flat routing fee in millisatoshis.
1473 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1474 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1477 /// Flat routing fee in millisatoshis.
1479 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1480 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1482 /// Liquidity-based routing fee in millionths of a routed amount.
1483 /// In other words, 10000 is 1%.
1485 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1486 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1489 /// Liquidity-based routing fee in millionths of a routed amount.
1490 /// In other words, 10000 is 1%.
1492 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1493 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1495 /// Constructs a new RoutingFees given each field
1498 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1499 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1500 base_msat: base_msat_arg,
1501 proportional_millionths: proportional_millionths_arg,
1502 }), is_owned: true }
1504 /// Checks if two RoutingFeess contain equal inner contents.
1505 /// This ignores pointers and is_owned flags and looks at the values in fields.
1506 /// Two objects with NULL inner values will be considered "equal" here.
1508 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1509 if a.inner == b.inner { return true; }
1510 if a.inner.is_null() || b.inner.is_null() { return false; }
1511 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1513 impl Clone for RoutingFees {
1514 fn clone(&self) -> Self {
1516 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1517 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1523 /// Used only if an object of this type is returned as a trait impl by a method
1524 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1525 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1528 /// Creates a copy of the RoutingFees
1529 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1532 /// Generates a non-cryptographic 64-bit hash of the RoutingFees.
1534 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1535 if o.inner.is_null() { return 0; }
1536 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1537 #[allow(deprecated)]
1538 let mut hasher = core::hash::SipHasher::new();
1539 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1540 core::hash::Hasher::finish(&hasher)
1543 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1544 pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::gossip::RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1545 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1548 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1549 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1552 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1553 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1554 let res: Result<lightning::routing::gossip::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1555 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() };
1559 use lightning::routing::gossip::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1560 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1562 /// Information received in the latest node_announcement from this node.
1565 pub struct NodeAnnouncementInfo {
1566 /// A pointer to the opaque Rust object.
1568 /// Nearly everywhere, inner must be non-null, however in places where
1569 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1570 pub inner: *mut nativeNodeAnnouncementInfo,
1571 /// Indicates that this is the only struct which contains the same pointer.
1573 /// Rust functions which take ownership of an object provided via an argument require
1574 /// this to be true and invalidate the object pointed to by inner.
1578 impl Drop for NodeAnnouncementInfo {
1579 fn drop(&mut self) {
1580 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1581 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1585 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1587 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1589 /// Used only if an object of this type is returned as a trait impl by a method
1590 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1591 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo) };
1594 impl NodeAnnouncementInfo {
1595 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1596 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1598 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1599 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1601 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1602 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1603 assert!(self.is_owned);
1604 let ret = ObjOps::untweak_ptr(self.inner);
1605 self.inner = core::ptr::null_mut();
1609 /// Protocol features the node announced support for
1611 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1612 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1613 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 }
1615 /// Protocol features the node announced support for
1617 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1618 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1620 /// When the last known update to the node state was issued.
1621 /// Value is opaque, as set in the announcement.
1623 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1624 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1627 /// When the last known update to the node state was issued.
1628 /// Value is opaque, as set in the announcement.
1630 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1631 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1633 /// Color assigned to the node
1635 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1636 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1639 /// Color assigned to the node
1641 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1642 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1644 /// Moniker assigned to the node.
1645 /// May be invalid or malicious (eg control chars),
1646 /// should not be exposed to the user.
1648 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::routing::gossip::NodeAlias {
1649 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1650 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 }
1652 /// Moniker assigned to the node.
1653 /// May be invalid or malicious (eg control chars),
1654 /// should not be exposed to the user.
1656 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::routing::gossip::NodeAlias) {
1657 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = *unsafe { Box::from_raw(val.take_inner()) };
1659 /// An initial announcement of the node
1660 /// Mostly redundant with the data we store in fields explicitly.
1661 /// Everything else is useful only for sending out for initial routing sync.
1662 /// Not stored if contains excess data to prevent DoS.
1664 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1666 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1667 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1668 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 };
1671 /// An initial announcement of the node
1672 /// Mostly redundant with the data we store in fields explicitly.
1673 /// Everything else is useful only for sending out for initial routing sync.
1674 /// Not stored if contains excess data to prevent DoS.
1676 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1678 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1679 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1680 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1682 /// Constructs a new NodeAnnouncementInfo given each field
1684 /// Note that announcement_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
1687 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 {
1688 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()) } }) };
1689 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1690 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1691 last_update: last_update_arg,
1693 alias: *unsafe { Box::from_raw(alias_arg.take_inner()) },
1694 announcement_message: local_announcement_message_arg,
1695 }), is_owned: true }
1697 impl Clone for NodeAnnouncementInfo {
1698 fn clone(&self) -> Self {
1700 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1701 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1707 /// Used only if an object of this type is returned as a trait impl by a method
1708 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1709 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1712 /// Creates a copy of the NodeAnnouncementInfo
1713 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1716 /// Checks if two NodeAnnouncementInfos contain equal inner contents.
1717 /// This ignores pointers and is_owned flags and looks at the values in fields.
1718 /// Two objects with NULL inner values will be considered "equal" here.
1720 pub extern "C" fn NodeAnnouncementInfo_eq(a: &NodeAnnouncementInfo, b: &NodeAnnouncementInfo) -> bool {
1721 if a.inner == b.inner { return true; }
1722 if a.inner.is_null() || b.inner.is_null() { return false; }
1723 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1725 /// Internet-level addresses via which one can connect to the node
1728 pub extern "C" fn NodeAnnouncementInfo_addresses(this_arg: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_SocketAddressZ {
1729 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.addresses();
1730 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) }); };
1735 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1736 pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1737 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1740 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1741 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1744 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1745 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1746 let res: Result<lightning::routing::gossip::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1747 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() };
1751 use lightning::routing::gossip::NodeAlias as nativeNodeAliasImport;
1752 pub(crate) type nativeNodeAlias = nativeNodeAliasImport;
1754 /// A user-defined name for a node, which may be used when displaying the node in a graph.
1756 /// Since node aliases are provided by third parties, they are a potential avenue for injection
1757 /// attacks. Care must be taken when processing.
1760 pub struct NodeAlias {
1761 /// A pointer to the opaque Rust object.
1763 /// Nearly everywhere, inner must be non-null, however in places where
1764 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1765 pub inner: *mut nativeNodeAlias,
1766 /// Indicates that this is the only struct which contains the same pointer.
1768 /// Rust functions which take ownership of an object provided via an argument require
1769 /// this to be true and invalidate the object pointed to by inner.
1773 impl Drop for NodeAlias {
1774 fn drop(&mut self) {
1775 if self.is_owned && !<*mut nativeNodeAlias>::is_null(self.inner) {
1776 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1780 /// Frees any resources used by the NodeAlias, if is_owned is set and inner is non-NULL.
1782 pub extern "C" fn NodeAlias_free(this_obj: NodeAlias) { }
1784 /// Used only if an object of this type is returned as a trait impl by a method
1785 pub(crate) extern "C" fn NodeAlias_free_void(this_ptr: *mut c_void) {
1786 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAlias) };
1790 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAlias {
1791 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1793 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAlias {
1794 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1796 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1797 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAlias {
1798 assert!(self.is_owned);
1799 let ret = ObjOps::untweak_ptr(self.inner);
1800 self.inner = core::ptr::null_mut();
1805 pub extern "C" fn NodeAlias_get_a(this_ptr: &NodeAlias) -> *const [u8; 32] {
1806 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1810 pub extern "C" fn NodeAlias_set_a(this_ptr: &mut NodeAlias, mut val: crate::c_types::ThirtyTwoBytes) {
1811 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.data;
1813 /// Constructs a new NodeAlias given each field
1816 pub extern "C" fn NodeAlias_new(mut a_arg: crate::c_types::ThirtyTwoBytes) -> NodeAlias {
1817 NodeAlias { inner: ObjOps::heap_alloc(lightning::routing::gossip::NodeAlias (
1819 )), is_owned: true }
1821 impl Clone for NodeAlias {
1822 fn clone(&self) -> Self {
1824 inner: if <*mut nativeNodeAlias>::is_null(self.inner) { core::ptr::null_mut() } else {
1825 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1831 /// Used only if an object of this type is returned as a trait impl by a method
1832 pub(crate) extern "C" fn NodeAlias_clone_void(this_ptr: *const c_void) -> *mut c_void {
1833 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAlias)).clone() })) as *mut c_void
1836 /// Creates a copy of the NodeAlias
1837 pub extern "C" fn NodeAlias_clone(orig: &NodeAlias) -> NodeAlias {
1840 /// Checks if two NodeAliass contain equal inner contents.
1841 /// This ignores pointers and is_owned flags and looks at the values in fields.
1842 /// Two objects with NULL inner values will be considered "equal" here.
1844 pub extern "C" fn NodeAlias_eq(a: &NodeAlias, b: &NodeAlias) -> bool {
1845 if a.inner == b.inner { return true; }
1846 if a.inner.is_null() || b.inner.is_null() { return false; }
1847 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1850 /// Serialize the NodeAlias object into a byte array which can be read by NodeAlias_read
1851 pub extern "C" fn NodeAlias_write(obj: &crate::lightning::routing::gossip::NodeAlias) -> crate::c_types::derived::CVec_u8Z {
1852 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1855 pub(crate) extern "C" fn NodeAlias_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1856 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAlias) })
1859 /// Read a NodeAlias from a byte array, created by NodeAlias_write
1860 pub extern "C" fn NodeAlias_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAliasDecodeErrorZ {
1861 let res: Result<lightning::routing::gossip::NodeAlias, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1862 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() };
1866 use lightning::routing::gossip::NodeInfo as nativeNodeInfoImport;
1867 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1869 /// Details about a node in the network, known from the network announcement.
1872 pub struct NodeInfo {
1873 /// A pointer to the opaque Rust object.
1875 /// Nearly everywhere, inner must be non-null, however in places where
1876 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1877 pub inner: *mut nativeNodeInfo,
1878 /// Indicates that this is the only struct which contains the same pointer.
1880 /// Rust functions which take ownership of an object provided via an argument require
1881 /// this to be true and invalidate the object pointed to by inner.
1885 impl Drop for NodeInfo {
1886 fn drop(&mut self) {
1887 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1888 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1892 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1894 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1896 /// Used only if an object of this type is returned as a trait impl by a method
1897 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1898 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeInfo) };
1902 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1903 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1905 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1906 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1908 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1909 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1910 assert!(self.is_owned);
1911 let ret = ObjOps::untweak_ptr(self.inner);
1912 self.inner = core::ptr::null_mut();
1916 /// All valid channels a node has announced
1918 /// Returns a copy of the field.
1920 pub extern "C" fn NodeInfo_get_channels(this_ptr: &NodeInfo) -> crate::c_types::derived::CVec_u64Z {
1921 let mut inner_val = this_ptr.get_native_mut_ref().channels.clone();
1922 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1923 local_inner_val.into()
1925 /// All valid channels a node has announced
1927 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1928 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1929 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1931 /// More information about a node from node_announcement.
1932 /// Optional because we store a Node entry after learning about it from
1933 /// a channel announcement, but before receiving a node announcement.
1935 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1937 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::NodeAnnouncementInfo {
1938 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1939 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 };
1942 /// More information about a node from node_announcement.
1943 /// Optional because we store a Node entry after learning about it from
1944 /// a channel announcement, but before receiving a node announcement.
1946 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1948 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::NodeAnnouncementInfo) {
1949 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1950 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1952 /// Constructs a new NodeInfo given each field
1954 /// Note that announcement_info_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
1957 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 {
1958 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1959 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()) } }) };
1960 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1961 channels: local_channels_arg,
1962 announcement_info: local_announcement_info_arg,
1963 }), is_owned: true }
1965 impl Clone for NodeInfo {
1966 fn clone(&self) -> Self {
1968 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1969 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1975 /// Used only if an object of this type is returned as a trait impl by a method
1976 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1977 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1980 /// Creates a copy of the NodeInfo
1981 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1984 /// Checks if two NodeInfos contain equal inner contents.
1985 /// This ignores pointers and is_owned flags and looks at the values in fields.
1986 /// Two objects with NULL inner values will be considered "equal" here.
1988 pub extern "C" fn NodeInfo_eq(a: &NodeInfo, b: &NodeInfo) -> bool {
1989 if a.inner == b.inner { return true; }
1990 if a.inner.is_null() || b.inner.is_null() { return false; }
1991 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1994 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1995 pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::gossip::NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1996 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1999 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2000 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
2003 /// Read a NodeInfo from a byte array, created by NodeInfo_write
2004 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
2005 let res: Result<lightning::routing::gossip::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2006 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() };
2010 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
2011 pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
2012 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2015 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2016 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
2019 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
2020 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
2022 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);
2023 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() };
2026 /// Creates a new, empty, network graph.
2029 pub extern "C" fn NetworkGraph_new(mut network: crate::bitcoin::network::Network, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph {
2030 let mut ret = lightning::routing::gossip::NetworkGraph::new(network.into_bitcoin(), logger);
2031 crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
2034 /// Returns a read-only view of the network graph.
2037 pub extern "C" fn NetworkGraph_read_only(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::lightning::routing::gossip::ReadOnlyNetworkGraph {
2038 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
2039 crate::lightning::routing::gossip::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
2042 /// The unix timestamp provided by the most recent rapid gossip sync.
2043 /// It will be set by the rapid sync process after every sync completion.
2046 pub extern "C" fn NetworkGraph_get_last_rapid_gossip_sync_timestamp(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::COption_u32Z {
2047 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_last_rapid_gossip_sync_timestamp();
2048 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() }) };
2052 /// Update the unix timestamp provided by the most recent rapid gossip sync.
2053 /// This should be done automatically by the rapid sync process after every sync completion.
2055 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) {
2056 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.set_last_rapid_gossip_sync_timestamp(last_rapid_gossip_sync_timestamp)
2059 /// For an already known node (from channel announcements), update its stored properties from a
2060 /// given node announcement.
2062 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
2063 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
2064 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2067 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 {
2068 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref());
2069 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() };
2073 /// For an already known node (from channel announcements), update its stored properties from a
2074 /// given node announcement without verifying the associated signatures. Because we aren't
2075 /// given the associated signatures here we cannot relay the node announcement to any of our
2079 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 {
2080 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
2081 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() };
2085 /// Store or update channel info from a channel announcement.
2087 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2088 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2089 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2091 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2092 /// the corresponding UTXO exists on chain and is correctly-formatted.
2095 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 {
2096 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() } }})} };
2097 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_utxo_lookup);
2098 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() };
2102 /// Store or update channel info from a channel announcement.
2104 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2105 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2106 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2108 /// This will skip verification of if the channel is actually on-chain.
2111 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 {
2112 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement_no_lookup(msg.get_native_ref());
2113 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() };
2117 /// Store or update channel info from a channel announcement without verifying the associated
2118 /// signatures. Because we aren't given the associated signatures here we cannot relay the
2119 /// channel announcement to any of our peers.
2121 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2122 /// the corresponding UTXO exists on chain and is correctly-formatted.
2125 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 {
2126 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() } }})} };
2127 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_utxo_lookup);
2128 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() };
2132 /// Update channel from partial announcement data received via rapid gossip sync
2134 /// `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
2135 /// rapid gossip sync server)
2137 /// All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
2140 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 {
2141 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());
2142 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() };
2146 /// Marks a channel in the graph as failed permanently.
2148 /// The channel and any node for which this was their last channel are removed from the graph.
2150 pub extern "C" fn NetworkGraph_channel_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64) {
2151 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed_permanent(short_channel_id)
2154 /// Marks a node in the graph as permanently failed, effectively removing it and its channels
2155 /// from local storage.
2157 pub extern "C" fn NetworkGraph_node_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut node_id: crate::c_types::PublicKey) {
2158 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node_failed_permanent(&node_id.into_rust())
2161 /// Removes information about channels that we haven't heard any updates about in some time.
2162 /// This can be used regularly to prune the network graph of channels that likely no longer
2165 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2166 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2167 /// pruning occur for updates which are at least two weeks old, which we implement here.
2169 /// Note that for users of the `lightning-background-processor` crate this method may be
2170 /// automatically called regularly for you.
2172 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2173 /// in the map for a while so that these can be resynced from gossip in the future.
2175 /// This method is only available with the `std` feature. See
2176 /// [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for `no-std` use.
2178 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking(this_arg: &crate::lightning::routing::gossip::NetworkGraph) {
2179 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking()
2182 /// Removes information about channels that we haven't heard any updates about in some time.
2183 /// This can be used regularly to prune the network graph of channels that likely no longer
2186 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2187 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2188 /// pruning occur for updates which are at least two weeks old, which we implement here.
2190 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2191 /// in the map for a while so that these can be resynced from gossip in the future.
2193 /// This function takes the current unix time as an argument. For users with the `std` feature
2194 /// enabled, [`NetworkGraph::remove_stale_channels_and_tracking`] may be preferable.
2196 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking_with_time(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut current_time_unix: u64) {
2197 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking_with_time(current_time_unix)
2200 /// For an already known (from announcement) channel, update info about one of the directions
2203 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
2204 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
2205 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2207 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2208 /// materially in the future will be rejected.
2211 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 {
2212 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref());
2213 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() };
2217 /// For an already known (from announcement) channel, update info about one of the directions
2218 /// of the channel without verifying the associated signatures. Because we aren't given the
2219 /// associated signatures here we cannot relay the channel update to any of our peers.
2221 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2222 /// materially in the future will be rejected.
2225 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 {
2226 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
2227 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() };
2231 /// Returns information on a channel with the given id.
2233 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2236 pub extern "C" fn ReadOnlyNetworkGraph_channel(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut short_channel_id: u64) -> crate::lightning::routing::gossip::ChannelInfo {
2237 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel(short_channel_id);
2238 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 };
2242 /// Returns the list of channels in the graph
2245 pub extern "C" fn ReadOnlyNetworkGraph_list_channels(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_u64Z {
2246 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
2247 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { item }); };
2251 /// Returns information on a node with the given id.
2253 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2256 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 {
2257 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node(node_id.get_native_ref());
2258 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 };
2262 /// Returns the list of nodes in the graph
2265 pub extern "C" fn ReadOnlyNetworkGraph_list_nodes(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_NodeIdZ {
2266 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_nodes();
2267 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 } }); };
2271 /// Get network addresses by node id.
2272 /// Returns None if the requested node is completely unknown,
2273 /// or if node announcement for the node was never received.
2276 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 {
2277 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust());
2278 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() }) };