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 top-level network map tracking logic lives here.
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
20 use lightning::routing::gossip::NodeId as nativeNodeIdImport;
21 pub(crate) type nativeNodeId = nativeNodeIdImport;
23 /// Represents the compressed public key of a node
27 /// A pointer to the opaque Rust object.
29 /// Nearly everywhere, inner must be non-null, however in places where
30 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
31 pub inner: *mut nativeNodeId,
32 /// Indicates that this is the only struct which contains the same pointer.
34 /// Rust functions which take ownership of an object provided via an argument require
35 /// this to be true and invalidate the object pointed to by inner.
39 impl Drop for NodeId {
41 if self.is_owned && !<*mut nativeNodeId>::is_null(self.inner) {
42 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
46 /// Frees any resources used by the NodeId, if is_owned is set and inner is non-NULL.
48 pub extern "C" fn NodeId_free(this_obj: NodeId) { }
50 /// Used only if an object of this type is returned as a trait impl by a method
51 pub(crate) extern "C" fn NodeId_free_void(this_ptr: *mut c_void) {
52 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeId); }
56 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeId {
57 unsafe { &*ObjOps::untweak_ptr(self.inner) }
59 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeId {
60 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
62 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
63 pub(crate) fn take_inner(mut self) -> *mut nativeNodeId {
64 assert!(self.is_owned);
65 let ret = ObjOps::untweak_ptr(self.inner);
66 self.inner = core::ptr::null_mut();
70 impl Clone for NodeId {
71 fn clone(&self) -> Self {
73 inner: if <*mut nativeNodeId>::is_null(self.inner) { core::ptr::null_mut() } else {
74 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
80 /// Used only if an object of this type is returned as a trait impl by a method
81 pub(crate) extern "C" fn NodeId_clone_void(this_ptr: *const c_void) -> *mut c_void {
82 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeId)).clone() })) as *mut c_void
85 /// Creates a copy of the NodeId
86 pub extern "C" fn NodeId_clone(orig: &NodeId) -> NodeId {
89 /// Create a new NodeId from a public key
92 pub extern "C" fn NodeId_from_pubkey(mut pubkey: crate::c_types::PublicKey) -> crate::lightning::routing::gossip::NodeId {
93 let mut ret = lightning::routing::gossip::NodeId::from_pubkey(&pubkey.into_rust());
94 crate::lightning::routing::gossip::NodeId { inner: ObjOps::heap_alloc(ret), is_owned: true }
97 /// Get the public key slice from this NodeId
100 pub extern "C" fn NodeId_as_slice(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::u8slice {
101 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_slice();
102 let mut local_ret = crate::c_types::u8slice::from_slice(ret);
106 /// Checks if two NodeIds contain equal inner contents.
108 pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 {
109 if o.inner.is_null() { return 0; }
110 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
112 let mut hasher = core::hash::SipHasher::new();
113 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
114 core::hash::Hasher::finish(&hasher)
117 /// Serialize the NodeId object into a byte array which can be read by NodeId_read
118 pub extern "C" fn NodeId_write(obj: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CVec_u8Z {
119 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
122 pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
123 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) })
126 /// Read a NodeId from a byte array, created by NodeId_write
127 pub extern "C" fn NodeId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ {
128 let res: Result<lightning::routing::gossip::NodeId, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
129 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
133 use lightning::routing::gossip::NetworkGraph as nativeNetworkGraphImport;
134 pub(crate) type nativeNetworkGraph = nativeNetworkGraphImport<crate::lightning::util::logger::Logger>;
136 /// Represents the network as nodes and channels between them
139 pub struct NetworkGraph {
140 /// A pointer to the opaque Rust object.
142 /// Nearly everywhere, inner must be non-null, however in places where
143 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
144 pub inner: *mut nativeNetworkGraph,
145 /// Indicates that this is the only struct which contains the same pointer.
147 /// Rust functions which take ownership of an object provided via an argument require
148 /// this to be true and invalidate the object pointed to by inner.
152 impl Drop for NetworkGraph {
154 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
155 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
159 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
161 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
163 /// Used only if an object of this type is returned as a trait impl by a method
164 pub(crate) extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
165 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
169 pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
170 unsafe { &*ObjOps::untweak_ptr(self.inner) }
172 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
173 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
175 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
176 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
177 assert!(self.is_owned);
178 let ret = ObjOps::untweak_ptr(self.inner);
179 self.inner = core::ptr::null_mut();
184 use lightning::routing::gossip::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
185 pub(crate) type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
187 /// A read-only view of [`NetworkGraph`].
190 pub struct ReadOnlyNetworkGraph {
191 /// A pointer to the opaque Rust object.
193 /// Nearly everywhere, inner must be non-null, however in places where
194 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
195 pub inner: *mut nativeReadOnlyNetworkGraph,
196 /// Indicates that this is the only struct which contains the same pointer.
198 /// Rust functions which take ownership of an object provided via an argument require
199 /// this to be true and invalidate the object pointed to by inner.
203 impl Drop for ReadOnlyNetworkGraph {
205 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
206 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
210 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
212 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
214 /// Used only if an object of this type is returned as a trait impl by a method
215 pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
216 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph); }
219 impl ReadOnlyNetworkGraph {
220 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
221 unsafe { &*ObjOps::untweak_ptr(self.inner) }
223 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
224 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
226 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
227 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
228 assert!(self.is_owned);
229 let ret = ObjOps::untweak_ptr(self.inner);
230 self.inner = core::ptr::null_mut();
234 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
235 /// return packet by a node along the route. See [BOLT #4] for details.
237 /// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
241 pub enum NetworkUpdate {
242 /// An error indicating a `channel_update` messages should be applied via
243 /// [`NetworkGraph::update_channel`].
244 ChannelUpdateMessage {
245 /// The update to apply via [`NetworkGraph::update_channel`].
246 msg: crate::lightning::ln::msgs::ChannelUpdate,
248 /// An error indicating that a channel failed to route a payment, which should be applied via
249 /// [`NetworkGraph::channel_failed`].
251 /// The short channel id of the closed channel.
252 short_channel_id: u64,
253 /// Whether the channel should be permanently removed or temporarily disabled until a new
254 /// `channel_update` message is received.
257 /// An error indicating that a node failed to route a payment, which should be applied via
258 /// [`NetworkGraph::node_failed`].
260 /// The node id of the failed node.
261 node_id: crate::c_types::PublicKey,
262 /// Whether the node should be permanently removed from consideration or can be restored
263 /// when a new `channel_update` message is received.
267 use lightning::routing::gossip::NetworkUpdate as NetworkUpdateImport;
268 pub(crate) type nativeNetworkUpdate = NetworkUpdateImport;
272 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
274 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
275 let mut msg_nonref = (*msg).clone();
276 nativeNetworkUpdate::ChannelUpdateMessage {
277 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
280 NetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
281 let mut short_channel_id_nonref = (*short_channel_id).clone();
282 let mut is_permanent_nonref = (*is_permanent).clone();
283 nativeNetworkUpdate::ChannelFailure {
284 short_channel_id: short_channel_id_nonref,
285 is_permanent: is_permanent_nonref,
288 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
289 let mut node_id_nonref = (*node_id).clone();
290 let mut is_permanent_nonref = (*is_permanent).clone();
291 nativeNetworkUpdate::NodeFailure {
292 node_id: node_id_nonref.into_rust(),
293 is_permanent: is_permanent_nonref,
299 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
301 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
302 nativeNetworkUpdate::ChannelUpdateMessage {
303 msg: *unsafe { Box::from_raw(msg.take_inner()) },
306 NetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
307 nativeNetworkUpdate::ChannelFailure {
308 short_channel_id: short_channel_id,
309 is_permanent: is_permanent,
312 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
313 nativeNetworkUpdate::NodeFailure {
314 node_id: node_id.into_rust(),
315 is_permanent: is_permanent,
321 pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
323 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
324 let mut msg_nonref = (*msg).clone();
325 NetworkUpdate::ChannelUpdateMessage {
326 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
329 nativeNetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
330 let mut short_channel_id_nonref = (*short_channel_id).clone();
331 let mut is_permanent_nonref = (*is_permanent).clone();
332 NetworkUpdate::ChannelFailure {
333 short_channel_id: short_channel_id_nonref,
334 is_permanent: is_permanent_nonref,
337 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
338 let mut node_id_nonref = (*node_id).clone();
339 let mut is_permanent_nonref = (*is_permanent).clone();
340 NetworkUpdate::NodeFailure {
341 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
342 is_permanent: is_permanent_nonref,
348 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
350 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
351 NetworkUpdate::ChannelUpdateMessage {
352 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
355 nativeNetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
356 NetworkUpdate::ChannelFailure {
357 short_channel_id: short_channel_id,
358 is_permanent: is_permanent,
361 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
362 NetworkUpdate::NodeFailure {
363 node_id: crate::c_types::PublicKey::from_rust(&node_id),
364 is_permanent: is_permanent,
370 /// Frees any resources used by the NetworkUpdate
372 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
373 /// Creates a copy of the NetworkUpdate
375 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
379 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
380 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
381 NetworkUpdate::ChannelUpdateMessage {
386 /// Utility method to constructs a new ChannelFailure-variant NetworkUpdate
387 pub extern "C" fn NetworkUpdate_channel_failure(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
388 NetworkUpdate::ChannelFailure {
394 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
395 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
396 NetworkUpdate::NodeFailure {
402 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
403 pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::gossip::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
404 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
407 /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
408 pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ {
409 let res: Result<Option<lightning::routing::gossip::NetworkUpdate>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
410 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::gossip::NetworkUpdate::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
414 use lightning::routing::gossip::P2PGossipSync as nativeP2PGossipSyncImport;
415 pub(crate) type nativeP2PGossipSync = nativeP2PGossipSyncImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::chain::Access, crate::lightning::util::logger::Logger>;
417 /// Receives and validates network updates from peers,
418 /// stores authentic and relevant data as a network graph.
419 /// This network graph is then used for routing payments.
420 /// Provides interface to help with initial routing sync by
421 /// serving historical announcements.
423 /// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
424 /// [`NetworkGraph`].
427 pub struct P2PGossipSync {
428 /// A pointer to the opaque Rust object.
430 /// Nearly everywhere, inner must be non-null, however in places where
431 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
432 pub inner: *mut nativeP2PGossipSync,
433 /// Indicates that this is the only struct which contains the same pointer.
435 /// Rust functions which take ownership of an object provided via an argument require
436 /// this to be true and invalidate the object pointed to by inner.
440 impl Drop for P2PGossipSync {
442 if self.is_owned && !<*mut nativeP2PGossipSync>::is_null(self.inner) {
443 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
447 /// Frees any resources used by the P2PGossipSync, if is_owned is set and inner is non-NULL.
449 pub extern "C" fn P2PGossipSync_free(this_obj: P2PGossipSync) { }
451 /// Used only if an object of this type is returned as a trait impl by a method
452 pub(crate) extern "C" fn P2PGossipSync_free_void(this_ptr: *mut c_void) {
453 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeP2PGossipSync); }
457 pub(crate) fn get_native_ref(&self) -> &'static nativeP2PGossipSync {
458 unsafe { &*ObjOps::untweak_ptr(self.inner) }
460 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeP2PGossipSync {
461 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
463 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
464 pub(crate) fn take_inner(mut self) -> *mut nativeP2PGossipSync {
465 assert!(self.is_owned);
466 let ret = ObjOps::untweak_ptr(self.inner);
467 self.inner = core::ptr::null_mut();
471 /// Creates a new tracker of the actual state of the network of channels and nodes,
472 /// assuming an existing Network Graph.
473 /// Chain monitor is used to make sure announced channels exist on-chain,
474 /// channel data is correct, and that the announcement is signed with
475 /// channel owners' keys.
478 pub extern "C" fn P2PGossipSync_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut chain_access: crate::c_types::derived::COption_AccessZ, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::P2PGossipSync {
479 let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
480 let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_chain_access, logger);
481 crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(ret), is_owned: true }
484 /// Adds a provider used to check new announcements. Does not affect
485 /// existing announcements unless they are updated.
486 /// Add, update or remove the provider would replace the current one.
488 pub extern "C" fn P2PGossipSync_add_chain_access(this_arg: &mut crate::lightning::routing::gossip::P2PGossipSync, mut chain_access: crate::c_types::derived::COption_AccessZ) {
489 let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
490 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::gossip::nativeP2PGossipSync)) }.add_chain_access(local_chain_access)
493 impl From<nativeNetworkGraph> for crate::lightning::util::events::EventHandler {
494 fn from(obj: nativeNetworkGraph) -> Self {
495 let mut rust_obj = NetworkGraph { inner: ObjOps::heap_alloc(obj), is_owned: true };
496 let mut ret = NetworkGraph_as_EventHandler(&rust_obj);
497 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
498 rust_obj.inner = core::ptr::null_mut();
499 ret.free = Some(NetworkGraph_free_void);
503 /// Constructs a new EventHandler which calls the relevant methods on this_arg.
504 /// This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
506 pub extern "C" fn NetworkGraph_as_EventHandler(this_arg: &NetworkGraph) -> crate::lightning::util::events::EventHandler {
507 crate::lightning::util::events::EventHandler {
508 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
510 handle_event: NetworkGraph_EventHandler_handle_event,
514 extern "C" fn NetworkGraph_EventHandler_handle_event(this_arg: *const c_void, event: &crate::lightning::util::events::Event) {
515 <nativeNetworkGraph as lightning::util::events::EventHandler<>>::handle_event(unsafe { &mut *(this_arg as *mut nativeNetworkGraph) }, &event.to_native())
518 impl From<nativeP2PGossipSync> for crate::lightning::ln::msgs::RoutingMessageHandler {
519 fn from(obj: nativeP2PGossipSync) -> Self {
520 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
521 let mut ret = P2PGossipSync_as_RoutingMessageHandler(&rust_obj);
522 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
523 rust_obj.inner = core::ptr::null_mut();
524 ret.free = Some(P2PGossipSync_free_void);
528 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
529 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
531 pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSync) -> crate::lightning::ln::msgs::RoutingMessageHandler {
532 crate::lightning::ln::msgs::RoutingMessageHandler {
533 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
535 handle_node_announcement: P2PGossipSync_RoutingMessageHandler_handle_node_announcement,
536 handle_channel_announcement: P2PGossipSync_RoutingMessageHandler_handle_channel_announcement,
537 handle_channel_update: P2PGossipSync_RoutingMessageHandler_handle_channel_update,
538 get_next_channel_announcements: P2PGossipSync_RoutingMessageHandler_get_next_channel_announcements,
539 get_next_node_announcements: P2PGossipSync_RoutingMessageHandler_get_next_node_announcements,
540 peer_connected: P2PGossipSync_RoutingMessageHandler_peer_connected,
541 handle_reply_channel_range: P2PGossipSync_RoutingMessageHandler_handle_reply_channel_range,
542 handle_reply_short_channel_ids_end: P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end,
543 handle_query_channel_range: P2PGossipSync_RoutingMessageHandler_handle_query_channel_range,
544 handle_query_short_channel_ids: P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids,
545 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
546 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
548 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
554 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 {
555 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
556 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
560 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 {
561 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
562 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
566 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 {
567 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
568 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
572 extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_channel_announcements(this_arg: *const c_void, mut starting_point: u64, mut batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
573 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, starting_point, batch_amount);
574 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; 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 }); };
578 extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_node_announcements(this_arg: *const c_void, mut starting_point: crate::c_types::PublicKey, mut batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ {
579 let mut local_starting_point_base = if starting_point.is_null() { None } else { Some( { starting_point.into_rust() }) }; let mut local_starting_point = local_starting_point_base.as_ref();
580 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcements(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, local_starting_point, batch_amount);
581 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
584 extern "C" fn P2PGossipSync_RoutingMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init_msg: &crate::lightning::ln::msgs::Init) {
585 <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), init_msg.get_native_ref())
588 extern "C" fn P2PGossipSync_RoutingMessageHandler_handle_reply_channel_range(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::lightning::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
589 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_channel_range(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
590 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
594 extern "C" fn P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::lightning::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
595 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_short_channel_ids_end(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
596 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
600 extern "C" fn P2PGossipSync_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
601 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
602 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
606 extern "C" fn P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
607 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_short_channel_ids(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
608 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
612 impl From<nativeP2PGossipSync> for crate::lightning::util::events::MessageSendEventsProvider {
613 fn from(obj: nativeP2PGossipSync) -> Self {
614 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
615 let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj);
616 // 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
617 rust_obj.inner = core::ptr::null_mut();
618 ret.free = Some(P2PGossipSync_free_void);
622 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
623 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
625 pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::util::events::MessageSendEventsProvider {
626 crate::lightning::util::events::MessageSendEventsProvider {
627 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
629 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
634 extern "C" fn P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
635 let mut ret = <nativeP2PGossipSync as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
636 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
641 use lightning::routing::gossip::ChannelUpdateInfo as nativeChannelUpdateInfoImport;
642 pub(crate) type nativeChannelUpdateInfo = nativeChannelUpdateInfoImport;
644 /// Details about one direction of a channel as received within a [`ChannelUpdate`].
647 pub struct ChannelUpdateInfo {
648 /// A pointer to the opaque Rust object.
650 /// Nearly everywhere, inner must be non-null, however in places where
651 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
652 pub inner: *mut nativeChannelUpdateInfo,
653 /// Indicates that this is the only struct which contains the same pointer.
655 /// Rust functions which take ownership of an object provided via an argument require
656 /// this to be true and invalidate the object pointed to by inner.
660 impl Drop for ChannelUpdateInfo {
662 if self.is_owned && !<*mut nativeChannelUpdateInfo>::is_null(self.inner) {
663 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
667 /// Frees any resources used by the ChannelUpdateInfo, if is_owned is set and inner is non-NULL.
669 pub extern "C" fn ChannelUpdateInfo_free(this_obj: ChannelUpdateInfo) { }
671 /// Used only if an object of this type is returned as a trait impl by a method
672 pub(crate) extern "C" fn ChannelUpdateInfo_free_void(this_ptr: *mut c_void) {
673 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo); }
676 impl ChannelUpdateInfo {
677 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUpdateInfo {
678 unsafe { &*ObjOps::untweak_ptr(self.inner) }
680 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUpdateInfo {
681 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
683 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
684 pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdateInfo {
685 assert!(self.is_owned);
686 let ret = ObjOps::untweak_ptr(self.inner);
687 self.inner = core::ptr::null_mut();
691 /// When the last update to the channel direction was issued.
692 /// Value is opaque, as set in the announcement.
694 pub extern "C" fn ChannelUpdateInfo_get_last_update(this_ptr: &ChannelUpdateInfo) -> u32 {
695 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
698 /// When the last update to the channel direction was issued.
699 /// Value is opaque, as set in the announcement.
701 pub extern "C" fn ChannelUpdateInfo_set_last_update(this_ptr: &mut ChannelUpdateInfo, mut val: u32) {
702 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
704 /// Whether the channel can be currently used for payments (in this one direction).
706 pub extern "C" fn ChannelUpdateInfo_get_enabled(this_ptr: &ChannelUpdateInfo) -> bool {
707 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
710 /// Whether the channel can be currently used for payments (in this one direction).
712 pub extern "C" fn ChannelUpdateInfo_set_enabled(this_ptr: &mut ChannelUpdateInfo, mut val: bool) {
713 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
715 /// The difference in CLTV values that you must have when routing through this channel.
717 pub extern "C" fn ChannelUpdateInfo_get_cltv_expiry_delta(this_ptr: &ChannelUpdateInfo) -> u16 {
718 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
721 /// The difference in CLTV values that you must have when routing through this channel.
723 pub extern "C" fn ChannelUpdateInfo_set_cltv_expiry_delta(this_ptr: &mut ChannelUpdateInfo, mut val: u16) {
724 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
726 /// The minimum value, which must be relayed to the next hop via the channel
728 pub extern "C" fn ChannelUpdateInfo_get_htlc_minimum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
729 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
732 /// The minimum value, which must be relayed to the next hop via the channel
734 pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
735 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
737 /// The maximum value which may be relayed to the next hop via the channel.
739 pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> crate::c_types::derived::COption_u64Z {
740 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
741 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() }) };
744 /// The maximum value which may be relayed to the next hop via the channel.
746 pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: crate::c_types::derived::COption_u64Z) {
747 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
748 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
750 /// Fees charged when the channel is used for routing
752 pub extern "C" fn ChannelUpdateInfo_get_fees(this_ptr: &ChannelUpdateInfo) -> crate::lightning::routing::gossip::RoutingFees {
753 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
754 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 }
756 /// Fees charged when the channel is used for routing
758 pub extern "C" fn ChannelUpdateInfo_set_fees(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::routing::gossip::RoutingFees) {
759 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
761 /// Most recent update for the channel received from the network
762 /// Mostly redundant with the data we store in fields explicitly.
763 /// Everything else is useful only for sending out for initial routing sync.
764 /// Not stored if contains excess data to prevent DoS.
766 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
768 pub extern "C" fn ChannelUpdateInfo_get_last_update_message(this_ptr: &ChannelUpdateInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
769 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
770 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 };
773 /// Most recent update for the channel received from the network
774 /// Mostly redundant with the data we store in fields explicitly.
775 /// Everything else is useful only for sending out for initial routing sync.
776 /// Not stored if contains excess data to prevent DoS.
778 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
780 pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
781 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
782 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
784 /// Constructs a new ChannelUpdateInfo given each field
787 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: crate::c_types::derived::COption_u64Z, mut fees_arg: crate::lightning::routing::gossip::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> ChannelUpdateInfo {
788 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
789 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()) } }) };
790 ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo {
791 last_update: last_update_arg,
792 enabled: enabled_arg,
793 cltv_expiry_delta: cltv_expiry_delta_arg,
794 htlc_minimum_msat: htlc_minimum_msat_arg,
795 htlc_maximum_msat: local_htlc_maximum_msat_arg,
796 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
797 last_update_message: local_last_update_message_arg,
800 impl Clone for ChannelUpdateInfo {
801 fn clone(&self) -> Self {
803 inner: if <*mut nativeChannelUpdateInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
804 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
810 /// Used only if an object of this type is returned as a trait impl by a method
811 pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
812 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdateInfo)).clone() })) as *mut c_void
815 /// Creates a copy of the ChannelUpdateInfo
816 pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo {
820 /// Serialize the ChannelUpdateInfo object into a byte array which can be read by ChannelUpdateInfo_read
821 pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::gossip::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z {
822 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
825 pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
826 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) })
829 /// Read a ChannelUpdateInfo from a byte array, created by ChannelUpdateInfo_write
830 pub extern "C" fn ChannelUpdateInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateInfoDecodeErrorZ {
831 let res: Result<lightning::routing::gossip::ChannelUpdateInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
832 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::ChannelUpdateInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
836 use lightning::routing::gossip::ChannelInfo as nativeChannelInfoImport;
837 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
839 /// Details about a channel (both directions).
840 /// Received within a channel announcement.
843 pub struct ChannelInfo {
844 /// A pointer to the opaque Rust object.
846 /// Nearly everywhere, inner must be non-null, however in places where
847 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
848 pub inner: *mut nativeChannelInfo,
849 /// Indicates that this is the only struct which contains the same pointer.
851 /// Rust functions which take ownership of an object provided via an argument require
852 /// this to be true and invalidate the object pointed to by inner.
856 impl Drop for ChannelInfo {
858 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
859 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
863 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
865 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
867 /// Used only if an object of this type is returned as a trait impl by a method
868 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
869 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
873 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
874 unsafe { &*ObjOps::untweak_ptr(self.inner) }
876 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
877 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
879 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
880 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
881 assert!(self.is_owned);
882 let ret = ObjOps::untweak_ptr(self.inner);
883 self.inner = core::ptr::null_mut();
887 /// Protocol features of a channel communicated during its announcement
889 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
890 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
891 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 }
893 /// Protocol features of a channel communicated during its announcement
895 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
896 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
898 /// Source node of the first direction of a channel
900 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
901 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
902 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 }
904 /// Source node of the first direction of a channel
906 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
907 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
909 /// Details about the first direction of a channel
911 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
913 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
914 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
915 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 };
918 /// Details about the first direction of a channel
920 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
922 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
923 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
924 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
926 /// Source node of the second direction of a channel
928 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
929 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
930 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 }
932 /// Source node of the second direction of a channel
934 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
935 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
937 /// Details about the second direction of a channel
939 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
941 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
942 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
943 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 };
946 /// Details about the second direction of a channel
948 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
950 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
951 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
952 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
954 /// The channel capacity as seen on-chain, if chain lookup is available.
956 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
957 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
958 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() }) };
961 /// The channel capacity as seen on-chain, if chain lookup is available.
963 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
964 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
965 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
967 /// An initial announcement of the channel
968 /// Mostly redundant with the data we store in fields explicitly.
969 /// Everything else is useful only for sending out for initial routing sync.
970 /// Not stored if contains excess data to prevent DoS.
972 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
974 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
975 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
976 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 };
979 /// An initial announcement of the channel
980 /// Mostly redundant with the data we store in fields explicitly.
981 /// Everything else is useful only for sending out for initial routing sync.
982 /// Not stored if contains excess data to prevent DoS.
984 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
986 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
987 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
988 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
990 impl Clone for ChannelInfo {
991 fn clone(&self) -> Self {
993 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
994 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1000 /// Used only if an object of this type is returned as a trait impl by a method
1001 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1002 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
1005 /// Creates a copy of the ChannelInfo
1006 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1009 /// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
1011 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1014 pub extern "C" fn ChannelInfo_get_directional_info(this_arg: &crate::lightning::routing::gossip::ChannelInfo, mut channel_flags: u8) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1015 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_directional_info(channel_flags);
1016 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 };
1021 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1022 pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::gossip::ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1023 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1026 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1027 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1030 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1031 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1032 let res: Result<lightning::routing::gossip::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1033 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::ChannelInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1037 use lightning::routing::gossip::DirectedChannelInfo as nativeDirectedChannelInfoImport;
1038 pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static>;
1040 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
1041 /// source node to a target node.
1044 pub struct DirectedChannelInfo {
1045 /// A pointer to the opaque Rust object.
1047 /// Nearly everywhere, inner must be non-null, however in places where
1048 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1049 pub inner: *mut nativeDirectedChannelInfo,
1050 /// Indicates that this is the only struct which contains the same pointer.
1052 /// Rust functions which take ownership of an object provided via an argument require
1053 /// this to be true and invalidate the object pointed to by inner.
1057 impl Drop for DirectedChannelInfo {
1058 fn drop(&mut self) {
1059 if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
1060 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1064 /// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
1066 pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
1068 /// Used only if an object of this type is returned as a trait impl by a method
1069 pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
1070 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo); }
1073 impl DirectedChannelInfo {
1074 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
1075 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1077 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
1078 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1080 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1081 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelInfo {
1082 assert!(self.is_owned);
1083 let ret = ObjOps::untweak_ptr(self.inner);
1084 self.inner = core::ptr::null_mut();
1088 impl Clone for DirectedChannelInfo {
1089 fn clone(&self) -> Self {
1091 inner: if <*mut nativeDirectedChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1092 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1098 /// Used only if an object of this type is returned as a trait impl by a method
1099 pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1100 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void
1103 /// Creates a copy of the DirectedChannelInfo
1104 pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
1107 /// Returns information for the channel.
1110 pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::ChannelInfo {
1111 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
1112 crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::ChannelInfo<>) as *mut _) }, is_owned: false }
1115 /// Returns information for the direction.
1117 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1120 pub extern "C" fn DirectedChannelInfo_direction(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1121 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.direction();
1122 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 };
1126 /// Returns the maximum HTLC amount allowed over the channel in the direction.
1129 pub extern "C" fn DirectedChannelInfo_htlc_maximum_msat(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> u64 {
1130 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.htlc_maximum_msat();
1134 /// Returns the [`EffectiveCapacity`] of the channel in the direction.
1136 /// This is either the total capacity from the funding transaction, if known, or the
1137 /// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
1141 pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::EffectiveCapacity {
1142 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
1143 crate::lightning::routing::gossip::EffectiveCapacity::native_into(ret)
1146 /// The effective capacity of a channel for routing purposes.
1148 /// While this may be smaller than the actual channel capacity, amounts greater than
1149 /// [`Self::as_msat`] should not be routed through the channel.
1153 pub enum EffectiveCapacity {
1154 /// The available liquidity in the channel known from being a channel counterparty, and thus a
1157 /// Either the inbound or outbound liquidity depending on the direction, denominated in
1159 liquidity_msat: u64,
1161 /// The maximum HTLC amount in one direction as advertised on the gossip network.
1163 /// The maximum HTLC amount denominated in millisatoshi.
1166 /// The total capacity of the channel as determined by the funding transaction.
1168 /// The funding amount denominated in millisatoshi.
1171 /// A capacity sufficient to route any payment, typically used for private channels provided by
1174 /// A capacity that is unknown possibly because either the chain state is unavailable to know
1175 /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
1178 use lightning::routing::gossip::EffectiveCapacity as EffectiveCapacityImport;
1179 pub(crate) type nativeEffectiveCapacity = EffectiveCapacityImport;
1181 impl EffectiveCapacity {
1183 pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
1185 EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1186 let mut liquidity_msat_nonref = (*liquidity_msat).clone();
1187 nativeEffectiveCapacity::ExactLiquidity {
1188 liquidity_msat: liquidity_msat_nonref,
1191 EffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1192 let mut amount_msat_nonref = (*amount_msat).clone();
1193 nativeEffectiveCapacity::MaximumHTLC {
1194 amount_msat: amount_msat_nonref,
1197 EffectiveCapacity::Total {ref capacity_msat, } => {
1198 let mut capacity_msat_nonref = (*capacity_msat).clone();
1199 nativeEffectiveCapacity::Total {
1200 capacity_msat: capacity_msat_nonref,
1203 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1204 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1208 pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
1210 EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1211 nativeEffectiveCapacity::ExactLiquidity {
1212 liquidity_msat: liquidity_msat,
1215 EffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1216 nativeEffectiveCapacity::MaximumHTLC {
1217 amount_msat: amount_msat,
1220 EffectiveCapacity::Total {mut capacity_msat, } => {
1221 nativeEffectiveCapacity::Total {
1222 capacity_msat: capacity_msat,
1225 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1226 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1230 pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self {
1232 nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1233 let mut liquidity_msat_nonref = (*liquidity_msat).clone();
1234 EffectiveCapacity::ExactLiquidity {
1235 liquidity_msat: liquidity_msat_nonref,
1238 nativeEffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1239 let mut amount_msat_nonref = (*amount_msat).clone();
1240 EffectiveCapacity::MaximumHTLC {
1241 amount_msat: amount_msat_nonref,
1244 nativeEffectiveCapacity::Total {ref capacity_msat, } => {
1245 let mut capacity_msat_nonref = (*capacity_msat).clone();
1246 EffectiveCapacity::Total {
1247 capacity_msat: capacity_msat_nonref,
1250 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1251 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1255 pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
1257 nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1258 EffectiveCapacity::ExactLiquidity {
1259 liquidity_msat: liquidity_msat,
1262 nativeEffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1263 EffectiveCapacity::MaximumHTLC {
1264 amount_msat: amount_msat,
1267 nativeEffectiveCapacity::Total {mut capacity_msat, } => {
1268 EffectiveCapacity::Total {
1269 capacity_msat: capacity_msat,
1272 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1273 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1277 /// Frees any resources used by the EffectiveCapacity
1279 pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
1280 /// Creates a copy of the EffectiveCapacity
1282 pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
1286 /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
1287 pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
1288 EffectiveCapacity::ExactLiquidity {
1293 /// Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity
1294 pub extern "C" fn EffectiveCapacity_maximum_htlc(amount_msat: u64) -> EffectiveCapacity {
1295 EffectiveCapacity::MaximumHTLC {
1300 /// Utility method to constructs a new Total-variant EffectiveCapacity
1301 pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64) -> EffectiveCapacity {
1302 EffectiveCapacity::Total {
1307 /// Utility method to constructs a new Infinite-variant EffectiveCapacity
1308 pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
1309 EffectiveCapacity::Infinite}
1311 /// Utility method to constructs a new Unknown-variant EffectiveCapacity
1312 pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
1313 EffectiveCapacity::Unknown}
1314 /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
1315 /// use when making routing decisions.
1318 pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::gossip::UNKNOWN_CHANNEL_CAPACITY_MSAT;
1319 /// Returns the effective capacity denominated in millisatoshi.
1322 pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &crate::lightning::routing::gossip::EffectiveCapacity) -> u64 {
1323 let mut ret = this_arg.to_native().as_msat();
1328 use lightning::routing::gossip::RoutingFees as nativeRoutingFeesImport;
1329 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1331 /// Fees for routing via a given channel or a node
1334 pub struct RoutingFees {
1335 /// A pointer to the opaque Rust object.
1337 /// Nearly everywhere, inner must be non-null, however in places where
1338 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1339 pub inner: *mut nativeRoutingFees,
1340 /// Indicates that this is the only struct which contains the same pointer.
1342 /// Rust functions which take ownership of an object provided via an argument require
1343 /// this to be true and invalidate the object pointed to by inner.
1347 impl Drop for RoutingFees {
1348 fn drop(&mut self) {
1349 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
1350 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1354 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
1356 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
1358 /// Used only if an object of this type is returned as a trait impl by a method
1359 pub(crate) extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
1360 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
1364 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1365 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1367 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
1368 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1370 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1371 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
1372 assert!(self.is_owned);
1373 let ret = ObjOps::untweak_ptr(self.inner);
1374 self.inner = core::ptr::null_mut();
1378 /// Flat routing fee in satoshis
1380 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1381 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1384 /// Flat routing fee in satoshis
1386 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1387 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1389 /// Liquidity-based routing fee in millionths of a routed amount.
1390 /// In other words, 10000 is 1%.
1392 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1393 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1396 /// Liquidity-based routing fee in millionths of a routed amount.
1397 /// In other words, 10000 is 1%.
1399 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1400 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1402 /// Constructs a new RoutingFees given each field
1405 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1406 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1407 base_msat: base_msat_arg,
1408 proportional_millionths: proportional_millionths_arg,
1409 }), is_owned: true }
1411 /// Checks if two RoutingFeess contain equal inner contents.
1412 /// This ignores pointers and is_owned flags and looks at the values in fields.
1413 /// Two objects with NULL inner values will be considered "equal" here.
1415 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1416 if a.inner == b.inner { return true; }
1417 if a.inner.is_null() || b.inner.is_null() { return false; }
1418 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1420 impl Clone for RoutingFees {
1421 fn clone(&self) -> Self {
1423 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1424 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1430 /// Used only if an object of this type is returned as a trait impl by a method
1431 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1432 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1435 /// Creates a copy of the RoutingFees
1436 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1439 /// Checks if two RoutingFeess contain equal inner contents.
1441 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1442 if o.inner.is_null() { return 0; }
1443 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1444 #[allow(deprecated)]
1445 let mut hasher = core::hash::SipHasher::new();
1446 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1447 core::hash::Hasher::finish(&hasher)
1450 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1451 pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::gossip::RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1452 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1455 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1456 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1459 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1460 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1461 let res: Result<lightning::routing::gossip::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1462 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::RoutingFees { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1466 use lightning::routing::gossip::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1467 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1469 /// Information received in the latest node_announcement from this node.
1472 pub struct NodeAnnouncementInfo {
1473 /// A pointer to the opaque Rust object.
1475 /// Nearly everywhere, inner must be non-null, however in places where
1476 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1477 pub inner: *mut nativeNodeAnnouncementInfo,
1478 /// Indicates that this is the only struct which contains the same pointer.
1480 /// Rust functions which take ownership of an object provided via an argument require
1481 /// this to be true and invalidate the object pointed to by inner.
1485 impl Drop for NodeAnnouncementInfo {
1486 fn drop(&mut self) {
1487 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1488 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1492 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1494 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1496 /// Used only if an object of this type is returned as a trait impl by a method
1497 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1498 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
1501 impl NodeAnnouncementInfo {
1502 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1503 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1505 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1506 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1508 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1509 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1510 assert!(self.is_owned);
1511 let ret = ObjOps::untweak_ptr(self.inner);
1512 self.inner = core::ptr::null_mut();
1516 /// Protocol features the node announced support for
1518 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1519 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1520 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 }
1522 /// Protocol features the node announced support for
1524 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1525 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1527 /// When the last known update to the node state was issued.
1528 /// Value is opaque, as set in the announcement.
1530 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1531 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1534 /// When the last known update to the node state was issued.
1535 /// Value is opaque, as set in the announcement.
1537 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1538 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1540 /// Color assigned to the node
1542 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1543 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1546 /// Color assigned to the node
1548 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1549 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1551 /// Moniker assigned to the node.
1552 /// May be invalid or malicious (eg control chars),
1553 /// should not be exposed to the user.
1555 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
1556 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1559 /// Moniker assigned to the node.
1560 /// May be invalid or malicious (eg control chars),
1561 /// should not be exposed to the user.
1563 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
1564 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = val.data;
1566 /// Internet-level addresses via which one can connect to the node
1568 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
1569 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
1570 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val;
1572 /// An initial announcement of the node
1573 /// Mostly redundant with the data we store in fields explicitly.
1574 /// Everything else is useful only for sending out for initial routing sync.
1575 /// Not stored if contains excess data to prevent DoS.
1577 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1579 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1580 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1581 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 };
1584 /// An initial announcement of the node
1585 /// Mostly redundant with the data we store in fields explicitly.
1586 /// Everything else is useful only for sending out for initial routing sync.
1587 /// Not stored if contains excess data to prevent DoS.
1589 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1591 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1592 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1593 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1595 /// Constructs a new NodeAnnouncementInfo given each field
1598 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::c_types::ThirtyTwoBytes, mut addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo {
1599 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
1600 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()) } }) };
1601 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1602 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1603 last_update: last_update_arg,
1605 alias: alias_arg.data,
1606 addresses: local_addresses_arg,
1607 announcement_message: local_announcement_message_arg,
1608 }), is_owned: true }
1610 impl Clone for NodeAnnouncementInfo {
1611 fn clone(&self) -> Self {
1613 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1614 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1620 /// Used only if an object of this type is returned as a trait impl by a method
1621 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1622 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1625 /// Creates a copy of the NodeAnnouncementInfo
1626 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1630 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1631 pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1632 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1635 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1636 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1639 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1640 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1641 let res: Result<lightning::routing::gossip::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1642 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeAnnouncementInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1646 use lightning::routing::gossip::NodeInfo as nativeNodeInfoImport;
1647 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1649 /// Details about a node in the network, known from the network announcement.
1652 pub struct NodeInfo {
1653 /// A pointer to the opaque Rust object.
1655 /// Nearly everywhere, inner must be non-null, however in places where
1656 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1657 pub inner: *mut nativeNodeInfo,
1658 /// Indicates that this is the only struct which contains the same pointer.
1660 /// Rust functions which take ownership of an object provided via an argument require
1661 /// this to be true and invalidate the object pointed to by inner.
1665 impl Drop for NodeInfo {
1666 fn drop(&mut self) {
1667 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1668 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1672 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1674 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1676 /// Used only if an object of this type is returned as a trait impl by a method
1677 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1678 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1682 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1683 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1685 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1686 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1688 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1689 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1690 assert!(self.is_owned);
1691 let ret = ObjOps::untweak_ptr(self.inner);
1692 self.inner = core::ptr::null_mut();
1696 /// All valid channels a node has announced
1698 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1699 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1700 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1702 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1703 /// The two fields (flat and proportional fee) are independent,
1704 /// meaning they don't have to refer to the same channel.
1706 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1708 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::RoutingFees {
1709 let mut inner_val = &mut this_ptr.get_native_mut_ref().lowest_inbound_channel_fees;
1710 let mut local_inner_val = crate::lightning::routing::gossip::RoutingFees { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::gossip::RoutingFees<>) as *mut _ }, is_owned: false };
1713 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1714 /// The two fields (flat and proportional fee) are independent,
1715 /// meaning they don't have to refer to the same channel.
1717 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1719 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::RoutingFees) {
1720 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1721 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.lowest_inbound_channel_fees = local_val;
1723 /// More information about a node from node_announcement.
1724 /// Optional because we store a Node entry after learning about it from
1725 /// a channel announcement, but before receiving a node announcement.
1727 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1729 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::NodeAnnouncementInfo {
1730 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1731 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 };
1734 /// More information about a node from node_announcement.
1735 /// Optional because we store a Node entry after learning about it from
1736 /// a channel announcement, but before receiving a node announcement.
1738 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1740 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::NodeAnnouncementInfo) {
1741 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1742 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1744 /// Constructs a new NodeInfo given each field
1747 pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::lightning::routing::gossip::RoutingFees, mut announcement_info_arg: crate::lightning::routing::gossip::NodeAnnouncementInfo) -> NodeInfo {
1748 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1749 let mut local_lowest_inbound_channel_fees_arg = if lowest_inbound_channel_fees_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(lowest_inbound_channel_fees_arg.take_inner()) } }) };
1750 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()) } }) };
1751 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1752 channels: local_channels_arg,
1753 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1754 announcement_info: local_announcement_info_arg,
1755 }), is_owned: true }
1757 impl Clone for NodeInfo {
1758 fn clone(&self) -> Self {
1760 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1761 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1767 /// Used only if an object of this type is returned as a trait impl by a method
1768 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1769 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1772 /// Creates a copy of the NodeInfo
1773 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1777 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1778 pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::gossip::NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1779 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1782 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1783 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1786 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1787 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1788 let res: Result<lightning::routing::gossip::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1789 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1793 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1794 pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1795 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1798 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1799 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1802 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1803 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1805 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);
1806 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1809 /// Creates a new, empty, network graph.
1812 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph {
1813 let mut ret = lightning::routing::gossip::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), logger);
1814 crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1817 /// Returns a read-only view of the network graph.
1820 pub extern "C" fn NetworkGraph_read_only(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::lightning::routing::gossip::ReadOnlyNetworkGraph {
1821 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
1822 crate::lightning::routing::gossip::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1825 /// The unix timestamp provided by the most recent rapid gossip sync.
1826 /// It will be set by the rapid sync process after every sync completion.
1829 pub extern "C" fn NetworkGraph_get_last_rapid_gossip_sync_timestamp(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::COption_u32Z {
1830 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_last_rapid_gossip_sync_timestamp();
1831 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() }) };
1835 /// Update the unix timestamp provided by the most recent rapid gossip sync.
1836 /// This should be done automatically by the rapid sync process after every sync completion.
1838 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) {
1839 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.set_last_rapid_gossip_sync_timestamp(last_rapid_gossip_sync_timestamp)
1842 /// For an already known node (from channel announcements), update its stored properties from a
1843 /// given node announcement.
1845 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
1846 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1847 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1850 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 {
1851 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref());
1852 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() };
1856 /// For an already known node (from channel announcements), update its stored properties from a
1857 /// given node announcement without verifying the associated signatures. Because we aren't
1858 /// given the associated signatures here we cannot relay the node announcement to any of our
1862 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 {
1863 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
1864 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() };
1868 /// Store or update channel info from a channel announcement.
1870 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
1871 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1872 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1874 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1875 /// the corresponding UTXO exists on chain and is correctly-formatted.
1878 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1879 let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
1880 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_chain_access);
1881 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() };
1885 /// Store or update channel info from a channel announcement without verifying the associated
1886 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1887 /// channel announcement to any of our peers.
1889 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1890 /// the corresponding UTXO exists on chain and is correctly-formatted.
1893 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1894 let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
1895 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_chain_access);
1896 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() };
1900 /// Update channel from partial announcement data received via rapid gossip sync
1902 /// `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
1903 /// rapid gossip sync server)
1905 /// All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
1908 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 {
1909 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());
1910 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() };
1914 /// Marks a channel in the graph as failed if a corresponding HTLC fail was sent.
1915 /// If permanent, removes a channel from the local storage.
1916 /// May cause the removal of nodes too, if this was their last channel.
1917 /// If not permanent, makes channels unavailable for routing.
1919 pub extern "C" fn NetworkGraph_channel_failed(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1920 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed(short_channel_id, is_permanent)
1923 /// Marks a node in the graph as failed.
1925 pub extern "C" fn NetworkGraph_node_failed(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut _node_id: crate::c_types::PublicKey, mut is_permanent: bool) {
1926 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node_failed(&_node_id.into_rust(), is_permanent)
1929 /// Removes information about channels that we haven't heard any updates about in some time.
1930 /// This can be used regularly to prune the network graph of channels that likely no longer
1933 /// While there is no formal requirement that nodes regularly re-broadcast their channel
1934 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
1935 /// pruning occur for updates which are at least two weeks old, which we implement here.
1937 /// Note that for users of the `lightning-background-processor` crate this method may be
1938 /// automatically called regularly for you.
1940 /// This method is only available with the `std` feature. See
1941 /// [`NetworkGraph::remove_stale_channels_with_time`] for `no-std` use.
1943 pub extern "C" fn NetworkGraph_remove_stale_channels(this_arg: &crate::lightning::routing::gossip::NetworkGraph) {
1944 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels()
1947 /// Removes information about channels that we haven't heard any updates about in some time.
1948 /// This can be used regularly to prune the network graph of channels that likely no longer
1951 /// While there is no formal requirement that nodes regularly re-broadcast their channel
1952 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
1953 /// pruning occur for updates which are at least two weeks old, which we implement here.
1955 /// This function takes the current unix time as an argument. For users with the `std` feature
1956 /// enabled, [`NetworkGraph::remove_stale_channels`] may be preferable.
1958 pub extern "C" fn NetworkGraph_remove_stale_channels_with_time(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut current_time_unix: u64) {
1959 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_with_time(current_time_unix)
1962 /// For an already known (from announcement) channel, update info about one of the directions
1965 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
1966 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1967 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1969 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1970 /// materially in the future will be rejected.
1973 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 {
1974 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref());
1975 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() };
1979 /// For an already known (from announcement) channel, update info about one of the directions
1980 /// of the channel without verifying the associated signatures. Because we aren't given the
1981 /// associated signatures here we cannot relay the channel update to any of our peers.
1983 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1984 /// materially in the future will be rejected.
1987 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 {
1988 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
1989 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() };
1993 /// Get network addresses by node id.
1994 /// Returns None if the requested node is completely unknown,
1995 /// or if node announcement for the node was never received.
1998 pub extern "C" fn ReadOnlyNetworkGraph_get_addresses(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::COption_CVec_NetAddressZZ {
1999 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust());
2000 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_NetAddressZZ::None } else { crate::c_types::derived::COption_CVec_NetAddressZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); }; local_ret_0.into() }) };