1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The [`NetworkGraph`] stores the network gossip and [`P2PGossipSync`] fetches it from peers
11 use alloc::str::FromStr;
12 use 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 let _ = unsafe { 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 /// Get the public key from this NodeId
109 pub extern "C" fn NodeId_as_pubkey(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CResult_PublicKeyErrorZ {
110 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_pubkey();
111 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
115 /// Generates a non-cryptographic 64-bit hash of the NodeId.
117 pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 {
118 if o.inner.is_null() { return 0; }
119 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
121 let mut hasher = core::hash::SipHasher::new();
122 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
123 core::hash::Hasher::finish(&hasher)
126 /// Serialize the NodeId object into a byte array which can be read by NodeId_read
127 pub extern "C" fn NodeId_write(obj: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CVec_u8Z {
128 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
131 pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
132 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) })
135 /// Read a NodeId from a byte array, created by NodeId_write
136 pub extern "C" fn NodeId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ {
137 let res: Result<lightning::routing::gossip::NodeId, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
138 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
142 use lightning::routing::gossip::NetworkGraph as nativeNetworkGraphImport;
143 pub(crate) type nativeNetworkGraph = nativeNetworkGraphImport<crate::lightning::util::logger::Logger>;
145 /// Represents the network as nodes and channels between them
148 pub struct NetworkGraph {
149 /// A pointer to the opaque Rust object.
151 /// Nearly everywhere, inner must be non-null, however in places where
152 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
153 pub inner: *mut nativeNetworkGraph,
154 /// Indicates that this is the only struct which contains the same pointer.
156 /// Rust functions which take ownership of an object provided via an argument require
157 /// this to be true and invalidate the object pointed to by inner.
161 impl Drop for NetworkGraph {
163 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
164 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
168 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
170 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
172 /// Used only if an object of this type is returned as a trait impl by a method
173 pub(crate) extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
174 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNetworkGraph) };
178 pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
179 unsafe { &*ObjOps::untweak_ptr(self.inner) }
181 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
182 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
184 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
185 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
186 assert!(self.is_owned);
187 let ret = ObjOps::untweak_ptr(self.inner);
188 self.inner = core::ptr::null_mut();
193 use lightning::routing::gossip::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
194 pub(crate) type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
196 /// A read-only view of [`NetworkGraph`].
199 pub struct ReadOnlyNetworkGraph {
200 /// A pointer to the opaque Rust object.
202 /// Nearly everywhere, inner must be non-null, however in places where
203 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
204 pub inner: *mut nativeReadOnlyNetworkGraph,
205 /// Indicates that this is the only struct which contains the same pointer.
207 /// Rust functions which take ownership of an object provided via an argument require
208 /// this to be true and invalidate the object pointed to by inner.
212 impl Drop for ReadOnlyNetworkGraph {
214 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
215 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
219 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
221 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
223 /// Used only if an object of this type is returned as a trait impl by a method
224 pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
225 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph) };
228 impl ReadOnlyNetworkGraph {
229 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
230 unsafe { &*ObjOps::untweak_ptr(self.inner) }
232 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
233 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
235 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
236 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
237 assert!(self.is_owned);
238 let ret = ObjOps::untweak_ptr(self.inner);
239 self.inner = core::ptr::null_mut();
243 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
244 /// return packet by a node along the route. See [BOLT #4] for details.
246 /// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
250 pub enum NetworkUpdate {
251 /// An error indicating a `channel_update` messages should be applied via
252 /// [`NetworkGraph::update_channel`].
253 ChannelUpdateMessage {
254 /// The update to apply via [`NetworkGraph::update_channel`].
255 msg: crate::lightning::ln::msgs::ChannelUpdate,
257 /// An error indicating that a channel failed to route a payment, which should be applied via
258 /// [`NetworkGraph::channel_failed_permanent`] if permanent.
260 /// The short channel id of the closed channel.
261 short_channel_id: u64,
262 /// Whether the channel should be permanently removed or temporarily disabled until a new
263 /// `channel_update` message is received.
266 /// An error indicating that a node failed to route a payment, which should be applied via
267 /// [`NetworkGraph::node_failed_permanent`] if permanent.
269 /// The node id of the failed node.
270 node_id: crate::c_types::PublicKey,
271 /// Whether the node should be permanently removed from consideration or can be restored
272 /// when a new `channel_update` message is received.
276 use lightning::routing::gossip::NetworkUpdate as NetworkUpdateImport;
277 pub(crate) type nativeNetworkUpdate = NetworkUpdateImport;
281 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
283 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
284 let mut msg_nonref = Clone::clone(msg);
285 nativeNetworkUpdate::ChannelUpdateMessage {
286 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
289 NetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
290 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
291 let mut is_permanent_nonref = Clone::clone(is_permanent);
292 nativeNetworkUpdate::ChannelFailure {
293 short_channel_id: short_channel_id_nonref,
294 is_permanent: is_permanent_nonref,
297 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
298 let mut node_id_nonref = Clone::clone(node_id);
299 let mut is_permanent_nonref = Clone::clone(is_permanent);
300 nativeNetworkUpdate::NodeFailure {
301 node_id: node_id_nonref.into_rust(),
302 is_permanent: is_permanent_nonref,
308 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
310 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
311 nativeNetworkUpdate::ChannelUpdateMessage {
312 msg: *unsafe { Box::from_raw(msg.take_inner()) },
315 NetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
316 nativeNetworkUpdate::ChannelFailure {
317 short_channel_id: short_channel_id,
318 is_permanent: is_permanent,
321 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
322 nativeNetworkUpdate::NodeFailure {
323 node_id: node_id.into_rust(),
324 is_permanent: is_permanent,
330 pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
332 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
333 let mut msg_nonref = Clone::clone(msg);
334 NetworkUpdate::ChannelUpdateMessage {
335 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
338 nativeNetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
339 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
340 let mut is_permanent_nonref = Clone::clone(is_permanent);
341 NetworkUpdate::ChannelFailure {
342 short_channel_id: short_channel_id_nonref,
343 is_permanent: is_permanent_nonref,
346 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
347 let mut node_id_nonref = Clone::clone(node_id);
348 let mut is_permanent_nonref = Clone::clone(is_permanent);
349 NetworkUpdate::NodeFailure {
350 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
351 is_permanent: is_permanent_nonref,
357 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
359 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
360 NetworkUpdate::ChannelUpdateMessage {
361 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
364 nativeNetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
365 NetworkUpdate::ChannelFailure {
366 short_channel_id: short_channel_id,
367 is_permanent: is_permanent,
370 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
371 NetworkUpdate::NodeFailure {
372 node_id: crate::c_types::PublicKey::from_rust(&node_id),
373 is_permanent: is_permanent,
379 /// Frees any resources used by the NetworkUpdate
381 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
382 /// Creates a copy of the NetworkUpdate
384 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
388 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
389 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
390 NetworkUpdate::ChannelUpdateMessage {
395 /// Utility method to constructs a new ChannelFailure-variant NetworkUpdate
396 pub extern "C" fn NetworkUpdate_channel_failure(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
397 NetworkUpdate::ChannelFailure {
403 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
404 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
405 NetworkUpdate::NodeFailure {
410 /// Checks if two NetworkUpdates contain equal inner contents.
411 /// This ignores pointers and is_owned flags and looks at the values in fields.
413 pub extern "C" fn NetworkUpdate_eq(a: &NetworkUpdate, b: &NetworkUpdate) -> bool {
414 if &a.to_native() == &b.to_native() { true } else { false }
417 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
418 pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::gossip::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
419 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
422 /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
423 pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ {
424 let res: Result<Option<lightning::routing::gossip::NetworkUpdate>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
425 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::gossip::NetworkUpdate::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
429 use lightning::routing::gossip::P2PGossipSync as nativeP2PGossipSyncImport;
430 pub(crate) type nativeP2PGossipSync = nativeP2PGossipSyncImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::routing::utxo::UtxoLookup, crate::lightning::util::logger::Logger>;
432 /// Receives and validates network updates from peers,
433 /// stores authentic and relevant data as a network graph.
434 /// This network graph is then used for routing payments.
435 /// Provides interface to help with initial routing sync by
436 /// serving historical announcements.
439 pub struct P2PGossipSync {
440 /// A pointer to the opaque Rust object.
442 /// Nearly everywhere, inner must be non-null, however in places where
443 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
444 pub inner: *mut nativeP2PGossipSync,
445 /// Indicates that this is the only struct which contains the same pointer.
447 /// Rust functions which take ownership of an object provided via an argument require
448 /// this to be true and invalidate the object pointed to by inner.
452 impl Drop for P2PGossipSync {
454 if self.is_owned && !<*mut nativeP2PGossipSync>::is_null(self.inner) {
455 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
459 /// Frees any resources used by the P2PGossipSync, if is_owned is set and inner is non-NULL.
461 pub extern "C" fn P2PGossipSync_free(this_obj: P2PGossipSync) { }
463 /// Used only if an object of this type is returned as a trait impl by a method
464 pub(crate) extern "C" fn P2PGossipSync_free_void(this_ptr: *mut c_void) {
465 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeP2PGossipSync) };
469 pub(crate) fn get_native_ref(&self) -> &'static nativeP2PGossipSync {
470 unsafe { &*ObjOps::untweak_ptr(self.inner) }
472 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeP2PGossipSync {
473 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
475 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
476 pub(crate) fn take_inner(mut self) -> *mut nativeP2PGossipSync {
477 assert!(self.is_owned);
478 let ret = ObjOps::untweak_ptr(self.inner);
479 self.inner = core::ptr::null_mut();
483 /// Creates a new tracker of the actual state of the network of channels and nodes,
484 /// assuming an existing [`NetworkGraph`].
485 /// UTXO lookup is used to make sure announced channels exist on-chain, channel data is
486 /// correct, and the announcement is signed with channel owners' keys.
489 pub extern "C" fn P2PGossipSync_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::P2PGossipSync {
490 let mut local_utxo_lookup = { /*utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; if utxo_lookup_opt.is_none() { None } else { Some({ { { utxo_lookup_opt.take() } }})} };
491 let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_utxo_lookup, logger);
492 crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(ret), is_owned: true }
495 /// Adds a provider used to check new announcements. Does not affect
496 /// existing announcements unless they are updated.
497 /// Add, update or remove the provider would replace the current one.
499 pub extern "C" fn P2PGossipSync_add_utxo_lookup(this_arg: &mut crate::lightning::routing::gossip::P2PGossipSync, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) {
500 let mut local_utxo_lookup = { /*utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; if utxo_lookup_opt.is_none() { None } else { Some({ { { utxo_lookup_opt.take() } }})} };
501 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::gossip::nativeP2PGossipSync)) }.add_utxo_lookup(local_utxo_lookup)
504 /// Handles any network updates originating from [`Event`]s.
506 /// [`Event`]: crate::events::Event
508 pub extern "C" fn NetworkGraph_handle_network_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, network_update: &crate::lightning::routing::gossip::NetworkUpdate) {
509 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_network_update(&network_update.to_native())
512 /// Gets the genesis hash for this network graph.
515 pub extern "C" fn NetworkGraph_get_genesis_hash(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::ThirtyTwoBytes {
516 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_genesis_hash();
517 crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
520 /// Verifies the signature of a [`NodeAnnouncement`].
522 /// Returns an error if it is invalid.
524 pub extern "C" fn verify_node_announcement(msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
525 let mut ret = lightning::routing::gossip::verify_node_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1);
526 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() };
530 /// Verifies all signatures included in a [`ChannelAnnouncement`].
532 /// Returns an error if one of the signatures is invalid.
534 pub extern "C" fn verify_channel_announcement(msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
535 let mut ret = lightning::routing::gossip::verify_channel_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1);
536 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() };
540 impl From<nativeP2PGossipSync> for crate::lightning::ln::msgs::RoutingMessageHandler {
541 fn from(obj: nativeP2PGossipSync) -> Self {
542 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
543 let mut ret = P2PGossipSync_as_RoutingMessageHandler(&rust_obj);
544 // 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
545 rust_obj.inner = core::ptr::null_mut();
546 ret.free = Some(P2PGossipSync_free_void);
550 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
551 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
553 pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSync) -> crate::lightning::ln::msgs::RoutingMessageHandler {
554 crate::lightning::ln::msgs::RoutingMessageHandler {
555 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
557 handle_node_announcement: P2PGossipSync_RoutingMessageHandler_handle_node_announcement,
558 handle_channel_announcement: P2PGossipSync_RoutingMessageHandler_handle_channel_announcement,
559 handle_channel_update: P2PGossipSync_RoutingMessageHandler_handle_channel_update,
560 get_next_channel_announcement: P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement,
561 get_next_node_announcement: P2PGossipSync_RoutingMessageHandler_get_next_node_announcement,
562 peer_connected: P2PGossipSync_RoutingMessageHandler_peer_connected,
563 handle_reply_channel_range: P2PGossipSync_RoutingMessageHandler_handle_reply_channel_range,
564 handle_reply_short_channel_ids_end: P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end,
565 handle_query_channel_range: P2PGossipSync_RoutingMessageHandler_handle_query_channel_range,
566 handle_query_short_channel_ids: P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids,
567 processing_queue_high: P2PGossipSync_RoutingMessageHandler_processing_queue_high,
568 provided_node_features: P2PGossipSync_RoutingMessageHandler_provided_node_features,
569 provided_init_features: P2PGossipSync_RoutingMessageHandler_provided_init_features,
570 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
571 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
573 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
579 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 {
580 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
581 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() };
585 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 {
586 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
587 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
591 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 {
592 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
593 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
597 extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement(this_arg: *const c_void, mut starting_point: u64) -> crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
598 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, starting_point);
599 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ::None } else { crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ::Some( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = (ret.unwrap()); let mut local_orig_ret_0_1 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_1.unwrap())) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(orig_ret_0_0), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }) };
603 extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_node_announcement(this_arg: *const c_void, mut starting_point: crate::lightning::routing::gossip::NodeId) -> crate::lightning::ln::msgs::NodeAnnouncement {
604 let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
605 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, local_starting_point);
606 let mut local_ret = crate::lightning::ln::msgs::NodeAnnouncement { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
610 extern "C" fn P2PGossipSync_RoutingMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init, mut inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ {
611 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), init.get_native_ref(), inbound);
612 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
616 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 {
617 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()) });
618 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() };
622 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 {
623 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()) });
624 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() };
628 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 {
629 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()) });
630 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() };
634 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 {
635 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()) });
636 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() };
640 extern "C" fn P2PGossipSync_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
641 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
645 extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
646 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
647 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
650 extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
651 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust());
652 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
655 impl From<nativeP2PGossipSync> for crate::lightning::events::MessageSendEventsProvider {
656 fn from(obj: nativeP2PGossipSync) -> Self {
657 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
658 let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj);
659 // 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
660 rust_obj.inner = core::ptr::null_mut();
661 ret.free = Some(P2PGossipSync_free_void);
665 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
666 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
668 pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::events::MessageSendEventsProvider {
669 crate::lightning::events::MessageSendEventsProvider {
670 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
672 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
677 extern "C" fn P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
678 let mut ret = <nativeP2PGossipSync as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
679 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
684 use lightning::routing::gossip::ChannelUpdateInfo as nativeChannelUpdateInfoImport;
685 pub(crate) type nativeChannelUpdateInfo = nativeChannelUpdateInfoImport;
687 /// Details about one direction of a channel as received within a [`ChannelUpdate`].
690 pub struct ChannelUpdateInfo {
691 /// A pointer to the opaque Rust object.
693 /// Nearly everywhere, inner must be non-null, however in places where
694 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
695 pub inner: *mut nativeChannelUpdateInfo,
696 /// Indicates that this is the only struct which contains the same pointer.
698 /// Rust functions which take ownership of an object provided via an argument require
699 /// this to be true and invalidate the object pointed to by inner.
703 impl Drop for ChannelUpdateInfo {
705 if self.is_owned && !<*mut nativeChannelUpdateInfo>::is_null(self.inner) {
706 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
710 /// Frees any resources used by the ChannelUpdateInfo, if is_owned is set and inner is non-NULL.
712 pub extern "C" fn ChannelUpdateInfo_free(this_obj: ChannelUpdateInfo) { }
714 /// Used only if an object of this type is returned as a trait impl by a method
715 pub(crate) extern "C" fn ChannelUpdateInfo_free_void(this_ptr: *mut c_void) {
716 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo) };
719 impl ChannelUpdateInfo {
720 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUpdateInfo {
721 unsafe { &*ObjOps::untweak_ptr(self.inner) }
723 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUpdateInfo {
724 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
726 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
727 pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdateInfo {
728 assert!(self.is_owned);
729 let ret = ObjOps::untweak_ptr(self.inner);
730 self.inner = core::ptr::null_mut();
734 /// When the last update to the channel direction was issued.
735 /// Value is opaque, as set in the announcement.
737 pub extern "C" fn ChannelUpdateInfo_get_last_update(this_ptr: &ChannelUpdateInfo) -> u32 {
738 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
741 /// When the last update to the channel direction was issued.
742 /// Value is opaque, as set in the announcement.
744 pub extern "C" fn ChannelUpdateInfo_set_last_update(this_ptr: &mut ChannelUpdateInfo, mut val: u32) {
745 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
747 /// Whether the channel can be currently used for payments (in this one direction).
749 pub extern "C" fn ChannelUpdateInfo_get_enabled(this_ptr: &ChannelUpdateInfo) -> bool {
750 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
753 /// Whether the channel can be currently used for payments (in this one direction).
755 pub extern "C" fn ChannelUpdateInfo_set_enabled(this_ptr: &mut ChannelUpdateInfo, mut val: bool) {
756 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
758 /// The difference in CLTV values that you must have when routing through this channel.
760 pub extern "C" fn ChannelUpdateInfo_get_cltv_expiry_delta(this_ptr: &ChannelUpdateInfo) -> u16 {
761 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
764 /// The difference in CLTV values that you must have when routing through this channel.
766 pub extern "C" fn ChannelUpdateInfo_set_cltv_expiry_delta(this_ptr: &mut ChannelUpdateInfo, mut val: u16) {
767 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
769 /// The minimum value, which must be relayed to the next hop via the channel
771 pub extern "C" fn ChannelUpdateInfo_get_htlc_minimum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
772 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
775 /// The minimum value, which must be relayed to the next hop via the channel
777 pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
778 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
780 /// The maximum value which may be relayed to the next hop via the channel.
782 pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
783 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
786 /// The maximum value which may be relayed to the next hop via the channel.
788 pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
789 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
791 /// Fees charged when the channel is used for routing
793 pub extern "C" fn ChannelUpdateInfo_get_fees(this_ptr: &ChannelUpdateInfo) -> crate::lightning::routing::gossip::RoutingFees {
794 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
795 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 }
797 /// Fees charged when the channel is used for routing
799 pub extern "C" fn ChannelUpdateInfo_set_fees(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::routing::gossip::RoutingFees) {
800 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
802 /// Most recent update for the channel received from the network
803 /// Mostly redundant with the data we store in fields explicitly.
804 /// Everything else is useful only for sending out for initial routing sync.
805 /// Not stored if contains excess data to prevent DoS.
807 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
809 pub extern "C" fn ChannelUpdateInfo_get_last_update_message(this_ptr: &ChannelUpdateInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
810 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
811 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 };
814 /// Most recent update for the channel received from the network
815 /// Mostly redundant with the data we store in fields explicitly.
816 /// Everything else is useful only for sending out for initial routing sync.
817 /// Not stored if contains excess data to prevent DoS.
819 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
821 pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
822 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
823 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
825 /// Constructs a new ChannelUpdateInfo given each field
828 pub extern "C" fn ChannelUpdateInfo_new(mut last_update_arg: u32, mut enabled_arg: bool, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: u64, mut fees_arg: crate::lightning::routing::gossip::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> ChannelUpdateInfo {
829 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()) } }) };
830 ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo {
831 last_update: last_update_arg,
832 enabled: enabled_arg,
833 cltv_expiry_delta: cltv_expiry_delta_arg,
834 htlc_minimum_msat: htlc_minimum_msat_arg,
835 htlc_maximum_msat: htlc_maximum_msat_arg,
836 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
837 last_update_message: local_last_update_message_arg,
840 impl Clone for ChannelUpdateInfo {
841 fn clone(&self) -> Self {
843 inner: if <*mut nativeChannelUpdateInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
844 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
850 /// Used only if an object of this type is returned as a trait impl by a method
851 pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
852 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdateInfo)).clone() })) as *mut c_void
855 /// Creates a copy of the ChannelUpdateInfo
856 pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo {
859 /// Checks if two ChannelUpdateInfos contain equal inner contents.
860 /// This ignores pointers and is_owned flags and looks at the values in fields.
861 /// Two objects with NULL inner values will be considered "equal" here.
863 pub extern "C" fn ChannelUpdateInfo_eq(a: &ChannelUpdateInfo, b: &ChannelUpdateInfo) -> bool {
864 if a.inner == b.inner { return true; }
865 if a.inner.is_null() || b.inner.is_null() { return false; }
866 if a.get_native_ref() == b.get_native_ref() { true } else { false }
869 /// Serialize the ChannelUpdateInfo object into a byte array which can be read by ChannelUpdateInfo_read
870 pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::gossip::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z {
871 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
874 pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
875 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) })
878 /// Read a ChannelUpdateInfo from a byte array, created by ChannelUpdateInfo_write
879 pub extern "C" fn ChannelUpdateInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateInfoDecodeErrorZ {
880 let res: Result<lightning::routing::gossip::ChannelUpdateInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
881 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::ChannelUpdateInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
885 use lightning::routing::gossip::ChannelInfo as nativeChannelInfoImport;
886 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
888 /// Details about a channel (both directions).
889 /// Received within a channel announcement.
892 pub struct ChannelInfo {
893 /// A pointer to the opaque Rust object.
895 /// Nearly everywhere, inner must be non-null, however in places where
896 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
897 pub inner: *mut nativeChannelInfo,
898 /// Indicates that this is the only struct which contains the same pointer.
900 /// Rust functions which take ownership of an object provided via an argument require
901 /// this to be true and invalidate the object pointed to by inner.
905 impl Drop for ChannelInfo {
907 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
908 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
912 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
914 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
916 /// Used only if an object of this type is returned as a trait impl by a method
917 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
918 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelInfo) };
922 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
923 unsafe { &*ObjOps::untweak_ptr(self.inner) }
925 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
926 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
928 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
929 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
930 assert!(self.is_owned);
931 let ret = ObjOps::untweak_ptr(self.inner);
932 self.inner = core::ptr::null_mut();
936 /// Protocol features of a channel communicated during its announcement
938 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
939 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
940 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 }
942 /// Protocol features of a channel communicated during its announcement
944 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
945 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
947 /// Source node of the first direction of a channel
949 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
950 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
951 crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false }
953 /// Source node of the first direction of a channel
955 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
956 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
958 /// Details about the first direction of a channel
960 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
962 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
963 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
964 let mut local_inner_val = crate::lightning::routing::gossip::ChannelUpdateInfo { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::gossip::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
967 /// Details about the first direction of a channel
969 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
971 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
972 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
973 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
975 /// Source node of the second direction of a channel
977 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
978 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
979 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 }
981 /// Source node of the second direction of a channel
983 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
984 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
986 /// Details about the second direction of a channel
988 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
990 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
991 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
992 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 };
995 /// Details about the second direction of a channel
997 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
999 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
1000 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1001 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
1003 /// The channel capacity as seen on-chain, if chain lookup is available.
1005 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
1006 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
1007 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() }) };
1010 /// The channel capacity as seen on-chain, if chain lookup is available.
1012 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
1013 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1014 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
1016 /// An initial announcement of the channel
1017 /// Mostly redundant with the data we store in fields explicitly.
1018 /// Everything else is useful only for sending out for initial routing sync.
1019 /// Not stored if contains excess data to prevent DoS.
1021 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1023 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
1024 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1025 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 };
1028 /// An initial announcement of the channel
1029 /// Mostly redundant with the data we store in fields explicitly.
1030 /// Everything else is useful only for sending out for initial routing sync.
1031 /// Not stored if contains excess data to prevent DoS.
1033 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1035 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
1036 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1037 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1039 impl Clone for ChannelInfo {
1040 fn clone(&self) -> Self {
1042 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1043 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1049 /// Used only if an object of this type is returned as a trait impl by a method
1050 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1051 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
1054 /// Creates a copy of the ChannelInfo
1055 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1058 /// Checks if two ChannelInfos contain equal inner contents.
1059 /// This ignores pointers and is_owned flags and looks at the values in fields.
1060 /// Two objects with NULL inner values will be considered "equal" here.
1062 pub extern "C" fn ChannelInfo_eq(a: &ChannelInfo, b: &ChannelInfo) -> bool {
1063 if a.inner == b.inner { return true; }
1064 if a.inner.is_null() || b.inner.is_null() { return false; }
1065 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1067 /// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
1069 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1072 pub extern "C" fn ChannelInfo_get_directional_info(this_arg: &crate::lightning::routing::gossip::ChannelInfo, mut channel_flags: u8) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1073 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_directional_info(channel_flags);
1074 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 };
1079 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1080 pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::gossip::ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1081 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1084 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1085 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1088 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1089 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1090 let res: Result<lightning::routing::gossip::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1091 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::ChannelInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1095 use lightning::routing::gossip::DirectedChannelInfo as nativeDirectedChannelInfoImport;
1096 pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static>;
1098 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
1099 /// source node to a target node.
1102 pub struct DirectedChannelInfo {
1103 /// A pointer to the opaque Rust object.
1105 /// Nearly everywhere, inner must be non-null, however in places where
1106 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1107 pub inner: *mut nativeDirectedChannelInfo,
1108 /// Indicates that this is the only struct which contains the same pointer.
1110 /// Rust functions which take ownership of an object provided via an argument require
1111 /// this to be true and invalidate the object pointed to by inner.
1115 impl Drop for DirectedChannelInfo {
1116 fn drop(&mut self) {
1117 if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
1118 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1122 /// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
1124 pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
1126 /// Used only if an object of this type is returned as a trait impl by a method
1127 pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
1128 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo) };
1131 impl DirectedChannelInfo {
1132 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
1133 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1135 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
1136 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1138 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1139 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelInfo {
1140 assert!(self.is_owned);
1141 let ret = ObjOps::untweak_ptr(self.inner);
1142 self.inner = core::ptr::null_mut();
1146 impl Clone for DirectedChannelInfo {
1147 fn clone(&self) -> Self {
1149 inner: if <*mut nativeDirectedChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1150 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1156 /// Used only if an object of this type is returned as a trait impl by a method
1157 pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1158 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void
1161 /// Creates a copy of the DirectedChannelInfo
1162 pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
1165 /// Returns information for the channel.
1168 pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::ChannelInfo {
1169 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
1170 crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::ChannelInfo<>) as *mut _) }, is_owned: false }
1173 /// Returns the maximum HTLC amount allowed over the channel in the direction.
1176 pub extern "C" fn DirectedChannelInfo_htlc_maximum_msat(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> u64 {
1177 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.htlc_maximum_msat();
1181 /// Returns the [`EffectiveCapacity`] of the channel in the direction.
1183 /// This is either the total capacity from the funding transaction, if known, or the
1184 /// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
1188 pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::EffectiveCapacity {
1189 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
1190 crate::lightning::routing::gossip::EffectiveCapacity::native_into(ret)
1193 /// The effective capacity of a channel for routing purposes.
1195 /// While this may be smaller than the actual channel capacity, amounts greater than
1196 /// [`Self::as_msat`] should not be routed through the channel.
1200 pub enum EffectiveCapacity {
1201 /// The available liquidity in the channel known from being a channel counterparty, and thus a
1204 /// Either the inbound or outbound liquidity depending on the direction, denominated in
1206 liquidity_msat: u64,
1208 /// The maximum HTLC amount in one direction as advertised on the gossip network.
1210 /// The maximum HTLC amount denominated in millisatoshi.
1213 /// The total capacity of the channel as determined by the funding transaction.
1215 /// The funding amount denominated in millisatoshi.
1217 /// The maximum HTLC amount denominated in millisatoshi.
1218 htlc_maximum_msat: u64,
1220 /// A capacity sufficient to route any payment, typically used for private channels provided by
1223 /// The maximum HTLC amount as provided by an invoice route hint.
1225 /// The maximum HTLC amount denominated in millisatoshi.
1228 /// A capacity that is unknown possibly because either the chain state is unavailable to know
1229 /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
1232 use lightning::routing::gossip::EffectiveCapacity as EffectiveCapacityImport;
1233 pub(crate) type nativeEffectiveCapacity = EffectiveCapacityImport;
1235 impl EffectiveCapacity {
1237 pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
1239 EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1240 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1241 nativeEffectiveCapacity::ExactLiquidity {
1242 liquidity_msat: liquidity_msat_nonref,
1245 EffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => {
1246 let mut amount_msat_nonref = Clone::clone(amount_msat);
1247 nativeEffectiveCapacity::AdvertisedMaxHTLC {
1248 amount_msat: amount_msat_nonref,
1251 EffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1252 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1253 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1254 nativeEffectiveCapacity::Total {
1255 capacity_msat: capacity_msat_nonref,
1256 htlc_maximum_msat: htlc_maximum_msat_nonref,
1259 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1260 EffectiveCapacity::HintMaxHTLC {ref amount_msat, } => {
1261 let mut amount_msat_nonref = Clone::clone(amount_msat);
1262 nativeEffectiveCapacity::HintMaxHTLC {
1263 amount_msat: amount_msat_nonref,
1266 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1270 pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
1272 EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1273 nativeEffectiveCapacity::ExactLiquidity {
1274 liquidity_msat: liquidity_msat,
1277 EffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => {
1278 nativeEffectiveCapacity::AdvertisedMaxHTLC {
1279 amount_msat: amount_msat,
1282 EffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1283 nativeEffectiveCapacity::Total {
1284 capacity_msat: capacity_msat,
1285 htlc_maximum_msat: htlc_maximum_msat,
1288 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1289 EffectiveCapacity::HintMaxHTLC {mut amount_msat, } => {
1290 nativeEffectiveCapacity::HintMaxHTLC {
1291 amount_msat: amount_msat,
1294 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1298 pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self {
1300 nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1301 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1302 EffectiveCapacity::ExactLiquidity {
1303 liquidity_msat: liquidity_msat_nonref,
1306 nativeEffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => {
1307 let mut amount_msat_nonref = Clone::clone(amount_msat);
1308 EffectiveCapacity::AdvertisedMaxHTLC {
1309 amount_msat: amount_msat_nonref,
1312 nativeEffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1313 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1314 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1315 EffectiveCapacity::Total {
1316 capacity_msat: capacity_msat_nonref,
1317 htlc_maximum_msat: htlc_maximum_msat_nonref,
1320 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1321 nativeEffectiveCapacity::HintMaxHTLC {ref amount_msat, } => {
1322 let mut amount_msat_nonref = Clone::clone(amount_msat);
1323 EffectiveCapacity::HintMaxHTLC {
1324 amount_msat: amount_msat_nonref,
1327 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1331 pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
1333 nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1334 EffectiveCapacity::ExactLiquidity {
1335 liquidity_msat: liquidity_msat,
1338 nativeEffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => {
1339 EffectiveCapacity::AdvertisedMaxHTLC {
1340 amount_msat: amount_msat,
1343 nativeEffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1344 EffectiveCapacity::Total {
1345 capacity_msat: capacity_msat,
1346 htlc_maximum_msat: htlc_maximum_msat,
1349 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1350 nativeEffectiveCapacity::HintMaxHTLC {mut amount_msat, } => {
1351 EffectiveCapacity::HintMaxHTLC {
1352 amount_msat: amount_msat,
1355 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1359 /// Frees any resources used by the EffectiveCapacity
1361 pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
1362 /// Creates a copy of the EffectiveCapacity
1364 pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
1368 /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
1369 pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
1370 EffectiveCapacity::ExactLiquidity {
1375 /// Utility method to constructs a new AdvertisedMaxHTLC-variant EffectiveCapacity
1376 pub extern "C" fn EffectiveCapacity_advertised_max_htlc(amount_msat: u64) -> EffectiveCapacity {
1377 EffectiveCapacity::AdvertisedMaxHTLC {
1382 /// Utility method to constructs a new Total-variant EffectiveCapacity
1383 pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: u64) -> EffectiveCapacity {
1384 EffectiveCapacity::Total {
1390 /// Utility method to constructs a new Infinite-variant EffectiveCapacity
1391 pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
1392 EffectiveCapacity::Infinite}
1394 /// Utility method to constructs a new HintMaxHTLC-variant EffectiveCapacity
1395 pub extern "C" fn EffectiveCapacity_hint_max_htlc(amount_msat: u64) -> EffectiveCapacity {
1396 EffectiveCapacity::HintMaxHTLC {
1401 /// Utility method to constructs a new Unknown-variant EffectiveCapacity
1402 pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
1403 EffectiveCapacity::Unknown}
1404 /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
1405 /// use when making routing decisions.
1408 pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::gossip::UNKNOWN_CHANNEL_CAPACITY_MSAT;
1409 /// Returns the effective capacity denominated in millisatoshi.
1412 pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &crate::lightning::routing::gossip::EffectiveCapacity) -> u64 {
1413 let mut ret = this_arg.to_native().as_msat();
1418 use lightning::routing::gossip::RoutingFees as nativeRoutingFeesImport;
1419 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1421 /// Fees for routing via a given channel or a node
1424 pub struct RoutingFees {
1425 /// A pointer to the opaque Rust object.
1427 /// Nearly everywhere, inner must be non-null, however in places where
1428 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1429 pub inner: *mut nativeRoutingFees,
1430 /// Indicates that this is the only struct which contains the same pointer.
1432 /// Rust functions which take ownership of an object provided via an argument require
1433 /// this to be true and invalidate the object pointed to by inner.
1437 impl Drop for RoutingFees {
1438 fn drop(&mut self) {
1439 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
1440 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1444 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
1446 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
1448 /// Used only if an object of this type is returned as a trait impl by a method
1449 pub(crate) extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
1450 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoutingFees) };
1454 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1455 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1457 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
1458 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1460 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1461 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
1462 assert!(self.is_owned);
1463 let ret = ObjOps::untweak_ptr(self.inner);
1464 self.inner = core::ptr::null_mut();
1468 /// Flat routing fee in millisatoshis.
1470 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1471 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1474 /// Flat routing fee in millisatoshis.
1476 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1477 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1479 /// Liquidity-based routing fee in millionths of a routed amount.
1480 /// In other words, 10000 is 1%.
1482 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1483 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1486 /// Liquidity-based routing fee in millionths of a routed amount.
1487 /// In other words, 10000 is 1%.
1489 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1490 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1492 /// Constructs a new RoutingFees given each field
1495 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1496 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1497 base_msat: base_msat_arg,
1498 proportional_millionths: proportional_millionths_arg,
1499 }), is_owned: true }
1501 /// Checks if two RoutingFeess contain equal inner contents.
1502 /// This ignores pointers and is_owned flags and looks at the values in fields.
1503 /// Two objects with NULL inner values will be considered "equal" here.
1505 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1506 if a.inner == b.inner { return true; }
1507 if a.inner.is_null() || b.inner.is_null() { return false; }
1508 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1510 impl Clone for RoutingFees {
1511 fn clone(&self) -> Self {
1513 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1514 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1520 /// Used only if an object of this type is returned as a trait impl by a method
1521 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1522 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1525 /// Creates a copy of the RoutingFees
1526 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1529 /// Generates a non-cryptographic 64-bit hash of the RoutingFees.
1531 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1532 if o.inner.is_null() { return 0; }
1533 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1534 #[allow(deprecated)]
1535 let mut hasher = core::hash::SipHasher::new();
1536 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1537 core::hash::Hasher::finish(&hasher)
1540 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1541 pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::gossip::RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1542 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1545 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1546 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1549 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1550 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1551 let res: Result<lightning::routing::gossip::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1552 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::RoutingFees { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1556 use lightning::routing::gossip::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1557 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1559 /// Information received in the latest node_announcement from this node.
1562 pub struct NodeAnnouncementInfo {
1563 /// A pointer to the opaque Rust object.
1565 /// Nearly everywhere, inner must be non-null, however in places where
1566 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1567 pub inner: *mut nativeNodeAnnouncementInfo,
1568 /// Indicates that this is the only struct which contains the same pointer.
1570 /// Rust functions which take ownership of an object provided via an argument require
1571 /// this to be true and invalidate the object pointed to by inner.
1575 impl Drop for NodeAnnouncementInfo {
1576 fn drop(&mut self) {
1577 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1578 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1582 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1584 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1586 /// Used only if an object of this type is returned as a trait impl by a method
1587 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1588 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo) };
1591 impl NodeAnnouncementInfo {
1592 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1593 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1595 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1596 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1598 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1599 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1600 assert!(self.is_owned);
1601 let ret = ObjOps::untweak_ptr(self.inner);
1602 self.inner = core::ptr::null_mut();
1606 /// Protocol features the node announced support for
1608 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1609 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1610 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 }
1612 /// Protocol features the node announced support for
1614 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1615 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1617 /// When the last known update to the node state was issued.
1618 /// Value is opaque, as set in the announcement.
1620 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1621 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1624 /// When the last known update to the node state was issued.
1625 /// Value is opaque, as set in the announcement.
1627 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1628 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1630 /// Color assigned to the node
1632 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1633 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1636 /// Color assigned to the node
1638 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1639 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1641 /// Moniker assigned to the node.
1642 /// May be invalid or malicious (eg control chars),
1643 /// should not be exposed to the user.
1645 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::routing::gossip::NodeAlias {
1646 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1647 crate::lightning::routing::gossip::NodeAlias { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeAlias<>) as *mut _) }, is_owned: false }
1649 /// Moniker assigned to the node.
1650 /// May be invalid or malicious (eg control chars),
1651 /// should not be exposed to the user.
1653 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::routing::gossip::NodeAlias) {
1654 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = *unsafe { Box::from_raw(val.take_inner()) };
1656 /// An initial announcement of the node
1657 /// Mostly redundant with the data we store in fields explicitly.
1658 /// Everything else is useful only for sending out for initial routing sync.
1659 /// Not stored if contains excess data to prevent DoS.
1661 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1663 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1664 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1665 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 };
1668 /// An initial announcement of the node
1669 /// Mostly redundant with the data we store in fields explicitly.
1670 /// Everything else is useful only for sending out for initial routing sync.
1671 /// Not stored if contains excess data to prevent DoS.
1673 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1675 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1676 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1677 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1679 /// Constructs a new NodeAnnouncementInfo given each field
1682 pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::lightning::ln::features::NodeFeatures, mut last_update_arg: u32, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::lightning::routing::gossip::NodeAlias, mut announcement_message_arg: crate::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo {
1683 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()) } }) };
1684 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1685 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1686 last_update: last_update_arg,
1688 alias: *unsafe { Box::from_raw(alias_arg.take_inner()) },
1689 announcement_message: local_announcement_message_arg,
1690 }), is_owned: true }
1692 impl Clone for NodeAnnouncementInfo {
1693 fn clone(&self) -> Self {
1695 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1696 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1702 /// Used only if an object of this type is returned as a trait impl by a method
1703 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1704 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1707 /// Creates a copy of the NodeAnnouncementInfo
1708 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1711 /// Checks if two NodeAnnouncementInfos contain equal inner contents.
1712 /// This ignores pointers and is_owned flags and looks at the values in fields.
1713 /// Two objects with NULL inner values will be considered "equal" here.
1715 pub extern "C" fn NodeAnnouncementInfo_eq(a: &NodeAnnouncementInfo, b: &NodeAnnouncementInfo) -> bool {
1716 if a.inner == b.inner { return true; }
1717 if a.inner.is_null() || b.inner.is_null() { return false; }
1718 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1720 /// Internet-level addresses via which one can connect to the node
1723 pub extern "C" fn NodeAnnouncementInfo_addresses(this_arg: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_NetAddressZ {
1724 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.addresses();
1725 let mut local_ret_clone = Vec::new(); local_ret_clone.extend_from_slice(ret); let mut ret = local_ret_clone; let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); };
1730 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1731 pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1732 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1735 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1736 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1739 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1740 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1741 let res: Result<lightning::routing::gossip::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1742 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeAnnouncementInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1746 use lightning::routing::gossip::NodeAlias as nativeNodeAliasImport;
1747 pub(crate) type nativeNodeAlias = nativeNodeAliasImport;
1749 /// A user-defined name for a node, which may be used when displaying the node in a graph.
1751 /// Since node aliases are provided by third parties, they are a potential avenue for injection
1752 /// attacks. Care must be taken when processing.
1755 pub struct NodeAlias {
1756 /// A pointer to the opaque Rust object.
1758 /// Nearly everywhere, inner must be non-null, however in places where
1759 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1760 pub inner: *mut nativeNodeAlias,
1761 /// Indicates that this is the only struct which contains the same pointer.
1763 /// Rust functions which take ownership of an object provided via an argument require
1764 /// this to be true and invalidate the object pointed to by inner.
1768 impl Drop for NodeAlias {
1769 fn drop(&mut self) {
1770 if self.is_owned && !<*mut nativeNodeAlias>::is_null(self.inner) {
1771 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1775 /// Frees any resources used by the NodeAlias, if is_owned is set and inner is non-NULL.
1777 pub extern "C" fn NodeAlias_free(this_obj: NodeAlias) { }
1779 /// Used only if an object of this type is returned as a trait impl by a method
1780 pub(crate) extern "C" fn NodeAlias_free_void(this_ptr: *mut c_void) {
1781 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAlias) };
1785 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAlias {
1786 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1788 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAlias {
1789 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1791 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1792 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAlias {
1793 assert!(self.is_owned);
1794 let ret = ObjOps::untweak_ptr(self.inner);
1795 self.inner = core::ptr::null_mut();
1800 pub extern "C" fn NodeAlias_get_a(this_ptr: &NodeAlias) -> *const [u8; 32] {
1801 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1805 pub extern "C" fn NodeAlias_set_a(this_ptr: &mut NodeAlias, mut val: crate::c_types::ThirtyTwoBytes) {
1806 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.data;
1808 /// Constructs a new NodeAlias given each field
1811 pub extern "C" fn NodeAlias_new(mut a_arg: crate::c_types::ThirtyTwoBytes) -> NodeAlias {
1812 NodeAlias { inner: ObjOps::heap_alloc(lightning::routing::gossip::NodeAlias (
1814 )), is_owned: true }
1816 impl Clone for NodeAlias {
1817 fn clone(&self) -> Self {
1819 inner: if <*mut nativeNodeAlias>::is_null(self.inner) { core::ptr::null_mut() } else {
1820 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1826 /// Used only if an object of this type is returned as a trait impl by a method
1827 pub(crate) extern "C" fn NodeAlias_clone_void(this_ptr: *const c_void) -> *mut c_void {
1828 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAlias)).clone() })) as *mut c_void
1831 /// Creates a copy of the NodeAlias
1832 pub extern "C" fn NodeAlias_clone(orig: &NodeAlias) -> NodeAlias {
1835 /// Checks if two NodeAliass contain equal inner contents.
1836 /// This ignores pointers and is_owned flags and looks at the values in fields.
1837 /// Two objects with NULL inner values will be considered "equal" here.
1839 pub extern "C" fn NodeAlias_eq(a: &NodeAlias, b: &NodeAlias) -> bool {
1840 if a.inner == b.inner { return true; }
1841 if a.inner.is_null() || b.inner.is_null() { return false; }
1842 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1845 /// Serialize the NodeAlias object into a byte array which can be read by NodeAlias_read
1846 pub extern "C" fn NodeAlias_write(obj: &crate::lightning::routing::gossip::NodeAlias) -> crate::c_types::derived::CVec_u8Z {
1847 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1850 pub(crate) extern "C" fn NodeAlias_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1851 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAlias) })
1854 /// Read a NodeAlias from a byte array, created by NodeAlias_write
1855 pub extern "C" fn NodeAlias_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAliasDecodeErrorZ {
1856 let res: Result<lightning::routing::gossip::NodeAlias, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1857 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeAlias { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1861 use lightning::routing::gossip::NodeInfo as nativeNodeInfoImport;
1862 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1864 /// Details about a node in the network, known from the network announcement.
1867 pub struct NodeInfo {
1868 /// A pointer to the opaque Rust object.
1870 /// Nearly everywhere, inner must be non-null, however in places where
1871 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1872 pub inner: *mut nativeNodeInfo,
1873 /// Indicates that this is the only struct which contains the same pointer.
1875 /// Rust functions which take ownership of an object provided via an argument require
1876 /// this to be true and invalidate the object pointed to by inner.
1880 impl Drop for NodeInfo {
1881 fn drop(&mut self) {
1882 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1883 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1887 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1889 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1891 /// Used only if an object of this type is returned as a trait impl by a method
1892 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1893 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeInfo) };
1897 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1898 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1900 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1901 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1903 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1904 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1905 assert!(self.is_owned);
1906 let ret = ObjOps::untweak_ptr(self.inner);
1907 self.inner = core::ptr::null_mut();
1911 /// All valid channels a node has announced
1913 /// Returns a copy of the field.
1915 pub extern "C" fn NodeInfo_get_channels(this_ptr: &NodeInfo) -> crate::c_types::derived::CVec_u64Z {
1916 let mut inner_val = this_ptr.get_native_mut_ref().channels.clone();
1917 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1918 local_inner_val.into()
1920 /// All valid channels a node has announced
1922 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1923 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1924 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1926 /// More information about a node from node_announcement.
1927 /// Optional because we store a Node entry after learning about it from
1928 /// a channel announcement, but before receiving a node announcement.
1930 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1932 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::NodeAnnouncementInfo {
1933 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1934 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 };
1937 /// More information about a node from node_announcement.
1938 /// Optional because we store a Node entry after learning about it from
1939 /// a channel announcement, but before receiving a node announcement.
1941 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1943 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::NodeAnnouncementInfo) {
1944 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1945 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1947 /// Constructs a new NodeInfo given each field
1950 pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut announcement_info_arg: crate::lightning::routing::gossip::NodeAnnouncementInfo) -> NodeInfo {
1951 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1952 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()) } }) };
1953 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1954 channels: local_channels_arg,
1955 announcement_info: local_announcement_info_arg,
1956 }), is_owned: true }
1958 impl Clone for NodeInfo {
1959 fn clone(&self) -> Self {
1961 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1962 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1968 /// Used only if an object of this type is returned as a trait impl by a method
1969 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1970 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1973 /// Creates a copy of the NodeInfo
1974 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1977 /// Checks if two NodeInfos contain equal inner contents.
1978 /// This ignores pointers and is_owned flags and looks at the values in fields.
1979 /// Two objects with NULL inner values will be considered "equal" here.
1981 pub extern "C" fn NodeInfo_eq(a: &NodeInfo, b: &NodeInfo) -> bool {
1982 if a.inner == b.inner { return true; }
1983 if a.inner.is_null() || b.inner.is_null() { return false; }
1984 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1987 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1988 pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::gossip::NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1989 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1992 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1993 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1996 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1997 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1998 let res: Result<lightning::routing::gossip::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1999 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2003 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
2004 pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
2005 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2008 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2009 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
2012 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
2013 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
2015 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);
2016 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2019 /// Creates a new, empty, network graph.
2022 pub extern "C" fn NetworkGraph_new(mut network: crate::bitcoin::network::Network, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph {
2023 let mut ret = lightning::routing::gossip::NetworkGraph::new(network.into_bitcoin(), logger);
2024 crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
2027 /// Returns a read-only view of the network graph.
2030 pub extern "C" fn NetworkGraph_read_only(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::lightning::routing::gossip::ReadOnlyNetworkGraph {
2031 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
2032 crate::lightning::routing::gossip::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
2035 /// The unix timestamp provided by the most recent rapid gossip sync.
2036 /// It will be set by the rapid sync process after every sync completion.
2039 pub extern "C" fn NetworkGraph_get_last_rapid_gossip_sync_timestamp(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::COption_u32Z {
2040 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_last_rapid_gossip_sync_timestamp();
2041 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() }) };
2045 /// Update the unix timestamp provided by the most recent rapid gossip sync.
2046 /// This should be done automatically by the rapid sync process after every sync completion.
2048 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) {
2049 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.set_last_rapid_gossip_sync_timestamp(last_rapid_gossip_sync_timestamp)
2052 /// For an already known node (from channel announcements), update its stored properties from a
2053 /// given node announcement.
2055 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
2056 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
2057 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2060 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 {
2061 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref());
2062 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() };
2066 /// For an already known node (from channel announcements), update its stored properties from a
2067 /// given node announcement without verifying the associated signatures. Because we aren't
2068 /// given the associated signatures here we cannot relay the node announcement to any of our
2072 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 {
2073 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
2074 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() };
2078 /// Store or update channel info from a channel announcement.
2080 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2081 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2082 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2084 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2085 /// the corresponding UTXO exists on chain and is correctly-formatted.
2088 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2089 let mut local_utxo_lookup = { /*utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; if utxo_lookup_opt.is_none() { None } else { Some({ { { utxo_lookup_opt.take() } }})} };
2090 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_utxo_lookup);
2091 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() };
2095 /// Store or update channel info from a channel announcement.
2097 /// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
2098 /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
2099 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2101 /// This will skip verification of if the channel is actually on-chain.
2104 pub extern "C" fn NetworkGraph_update_channel_from_announcement_no_lookup(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2105 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement_no_lookup(msg.get_native_ref());
2106 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() };
2110 /// Store or update channel info from a channel announcement without verifying the associated
2111 /// signatures. Because we aren't given the associated signatures here we cannot relay the
2112 /// channel announcement to any of our peers.
2114 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2115 /// the corresponding UTXO exists on chain and is correctly-formatted.
2118 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2119 let mut local_utxo_lookup = { /*utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; if utxo_lookup_opt.is_none() { None } else { Some({ { { utxo_lookup_opt.take() } }})} };
2120 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_utxo_lookup);
2121 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() };
2125 /// Update channel from partial announcement data received via rapid gossip sync
2127 /// `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
2128 /// rapid gossip sync server)
2130 /// All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
2133 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 {
2134 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());
2135 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() };
2139 /// Marks a channel in the graph as failed permanently.
2141 /// The channel and any node for which this was their last channel are removed from the graph.
2143 pub extern "C" fn NetworkGraph_channel_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64) {
2144 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed_permanent(short_channel_id)
2147 /// Marks a node in the graph as permanently failed, effectively removing it and its channels
2148 /// from local storage.
2150 pub extern "C" fn NetworkGraph_node_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut node_id: crate::c_types::PublicKey) {
2151 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node_failed_permanent(&node_id.into_rust())
2154 /// Removes information about channels that we haven't heard any updates about in some time.
2155 /// This can be used regularly to prune the network graph of channels that likely no longer
2158 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2159 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2160 /// pruning occur for updates which are at least two weeks old, which we implement here.
2162 /// Note that for users of the `lightning-background-processor` crate this method may be
2163 /// automatically called regularly for you.
2165 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2166 /// in the map for a while so that these can be resynced from gossip in the future.
2168 /// This method is only available with the `std` feature. See
2169 /// [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for `no-std` use.
2171 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking(this_arg: &crate::lightning::routing::gossip::NetworkGraph) {
2172 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking()
2175 /// Removes information about channels that we haven't heard any updates about in some time.
2176 /// This can be used regularly to prune the network graph of channels that likely no longer
2179 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2180 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2181 /// pruning occur for updates which are at least two weeks old, which we implement here.
2183 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2184 /// in the map for a while so that these can be resynced from gossip in the future.
2186 /// This function takes the current unix time as an argument. For users with the `std` feature
2187 /// enabled, [`NetworkGraph::remove_stale_channels_and_tracking`] may be preferable.
2189 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking_with_time(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut current_time_unix: u64) {
2190 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking_with_time(current_time_unix)
2193 /// For an already known (from announcement) channel, update info about one of the directions
2196 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
2197 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
2198 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2200 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2201 /// materially in the future will be rejected.
2204 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 {
2205 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref());
2206 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() };
2210 /// For an already known (from announcement) channel, update info about one of the directions
2211 /// of the channel without verifying the associated signatures. Because we aren't given the
2212 /// associated signatures here we cannot relay the channel update to any of our peers.
2214 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2215 /// materially in the future will be rejected.
2218 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 {
2219 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
2220 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() };
2224 /// Returns information on a channel with the given id.
2226 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2229 pub extern "C" fn ReadOnlyNetworkGraph_channel(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut short_channel_id: u64) -> crate::lightning::routing::gossip::ChannelInfo {
2230 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel(short_channel_id);
2231 let mut local_ret = crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::gossip::ChannelInfo<>) as *mut _ }, is_owned: false };
2235 /// Returns the list of channels in the graph
2238 pub extern "C" fn ReadOnlyNetworkGraph_list_channels(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_u64Z {
2239 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
2240 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { item }); };
2244 /// Returns information on a node with the given id.
2246 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2249 pub extern "C" fn ReadOnlyNetworkGraph_node(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, node_id: &crate::lightning::routing::gossip::NodeId) -> crate::lightning::routing::gossip::NodeInfo {
2250 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node(node_id.get_native_ref());
2251 let mut local_ret = crate::lightning::routing::gossip::NodeInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::gossip::NodeInfo<>) as *mut _ }, is_owned: false };
2255 /// Returns the list of nodes in the graph
2258 pub extern "C" fn ReadOnlyNetworkGraph_list_nodes(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_NodeIdZ {
2259 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_nodes();
2260 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::gossip::NodeId { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
2264 /// Get network addresses by node id.
2265 /// Returns None if the requested node is completely unknown,
2266 /// or if node announcement for the node was never received.
2269 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 {
2270 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust());
2271 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() }) };