X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Frouting%2Fgossip.rs;h=b97a92ec43f5abb778c760bd68b9f5d848e8521b;hb=0ac4dbdb8352c898100b34f0ef8ed9cebfea7786;hp=6284e6c46c582363c378beda6e471996ad1157a3;hpb=11b997c3a0452ea1da5b7b352e7887798105db29;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/routing/gossip.rs b/lightning-c-bindings/src/lightning/routing/gossip.rs index 6284e6c..b97a92e 100644 --- a/lightning-c-bindings/src/lightning/routing/gossip.rs +++ b/lightning-c-bindings/src/lightning/routing/gossip.rs @@ -9,6 +9,7 @@ //! The [`NetworkGraph`] stores the network gossip and [`P2PGossipSync`] fetches it from peers use alloc::str::FromStr; +use alloc::string::String; use core::ffi::c_void; use core::convert::Infallible; use bitcoin::hashes::Hash; @@ -79,7 +80,7 @@ impl Clone for NodeId { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeId_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeId)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeId)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeId @@ -103,7 +104,27 @@ pub extern "C" fn NodeId_as_slice(this_arg: &crate::lightning::routing::gossip:: local_ret } -/// Checks if two NodeIds contain equal inner contents. +/// Get the public key as an array from this NodeId +#[must_use] +#[no_mangle] +pub extern "C" fn NodeId_as_array(this_arg: &crate::lightning::routing::gossip::NodeId) -> *const [u8; 33] { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_array(); + ret +} + +/// Get the public key from this NodeId +#[must_use] +#[no_mangle] +pub extern "C" fn NodeId_as_pubkey(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CResult_PublicKeySecp256k1ErrorZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_pubkey(); + 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() }; + local_ret +} + +/// Get a string which allows debug introspection of a NodeId object +pub extern "C" fn NodeId_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeId }).into()} +/// Generates a non-cryptographic 64-bit hash of the NodeId. #[no_mangle] pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 { if o.inner.is_null() { return 0; } @@ -118,7 +139,7 @@ pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 { pub extern "C" fn NodeId_write(obj: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) }) } @@ -246,7 +267,7 @@ pub enum NetworkUpdate { msg: crate::lightning::ln::msgs::ChannelUpdate, }, /// An error indicating that a channel failed to route a payment, which should be applied via - /// [`NetworkGraph::channel_failed`]. + /// [`NetworkGraph::channel_failed_permanent`] if permanent. ChannelFailure { /// The short channel id of the closed channel. short_channel_id: u64, @@ -318,7 +339,8 @@ impl NetworkUpdate { } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self { + pub(crate) fn from_native(native: &NetworkUpdateImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeNetworkUpdate) }; match native { nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => { let mut msg_nonref = Clone::clone(msg); @@ -375,6 +397,16 @@ pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { } pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn NetworkUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const NetworkUpdate)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn NetworkUpdate_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut NetworkUpdate) }; +} #[no_mangle] /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate { @@ -398,6 +430,9 @@ pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent, } } +/// Get a string which allows debug introspection of a NetworkUpdate object +pub extern "C" fn NetworkUpdate_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NetworkUpdate }).into()} /// Checks if two NetworkUpdates contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. #[no_mangle] @@ -409,6 +444,10 @@ pub extern "C" fn NetworkUpdate_eq(a: &NetworkUpdate, b: &NetworkUpdate) -> bool pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::gossip::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn NetworkUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + NetworkUpdate_write(unsafe { &*(obj as *const NetworkUpdate) }) +} #[no_mangle] /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ { @@ -472,13 +511,13 @@ impl P2PGossipSync { } } /// Creates a new tracker of the actual state of the network of channels and nodes, -/// assuming an existing Network Graph. +/// assuming an existing [`NetworkGraph`]. /// UTXO lookup is used to make sure announced channels exist on-chain, channel data is /// correct, and the announcement is signed with channel owners' keys. #[must_use] #[no_mangle] 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 { - 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() }) } }; + 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() } }})} }; let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_utxo_lookup, logger); crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(ret), is_owned: true } } @@ -487,25 +526,55 @@ pub extern "C" fn P2PGossipSync_new(network_graph: &crate::lightning::routing::g /// existing announcements unless they are updated. /// Add, update or remove the provider would replace the current one. #[no_mangle] -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) { - 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() }) } }; - unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::gossip::nativeP2PGossipSync)) }.add_utxo_lookup(local_utxo_lookup) +pub extern "C" fn P2PGossipSync_add_utxo_lookup(this_arg: &crate::lightning::routing::gossip::P2PGossipSync, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) { + 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() } }})} }; + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.add_utxo_lookup(local_utxo_lookup) } /// Handles any network updates originating from [`Event`]s. +/// Note that this will skip applying any [`NetworkUpdate::ChannelUpdateMessage`] to avoid +/// leaking possibly identifying information of the sender to the public network. /// -/// [`Event`]: crate::util::events::Event +/// [`Event`]: crate::events::Event #[no_mangle] pub extern "C" fn NetworkGraph_handle_network_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, network_update: &crate::lightning::routing::gossip::NetworkUpdate) { unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_network_update(&network_update.to_native()) } +/// Gets the chain hash for this network graph. +#[must_use] +#[no_mangle] +pub extern "C" fn NetworkGraph_get_chain_hash(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_chain_hash(); + crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() } +} + +/// Verifies the signature of a [`NodeAnnouncement`]. +/// +/// Returns an error if it is invalid. +#[no_mangle] +pub extern "C" fn verify_node_announcement(msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = lightning::routing::gossip::verify_node_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1); + 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() }; + local_ret +} + +/// Verifies all signatures included in a [`ChannelAnnouncement`]. +/// +/// Returns an error if one of the signatures is invalid. +#[no_mangle] +pub extern "C" fn verify_channel_announcement(msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = lightning::routing::gossip::verify_channel_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1); + 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() }; + local_ret +} + impl From for crate::lightning::ln::msgs::RoutingMessageHandler { fn from(obj: nativeP2PGossipSync) -> Self { - let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = P2PGossipSync_as_RoutingMessageHandler(&rust_obj); - // 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 - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(P2PGossipSync_free_void); ret } @@ -530,7 +599,7 @@ pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSyn processing_queue_high: P2PGossipSync_RoutingMessageHandler_processing_queue_high, provided_node_features: P2PGossipSync_RoutingMessageHandler_provided_node_features, provided_init_features: P2PGossipSync_RoutingMessageHandler_provided_init_features, - MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider { + MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider { this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events, @@ -615,12 +684,12 @@ extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_init_features(this_ar crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -impl From for crate::lightning::util::events::MessageSendEventsProvider { +impl From for crate::lightning::events::MessageSendEventsProvider { fn from(obj: nativeP2PGossipSync) -> Self { - let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let rust_obj = crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj); - // 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 - rust_obj.inner = core::ptr::null_mut(); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn + core::mem::forget(rust_obj); ret.free = Some(P2PGossipSync_free_void); ret } @@ -628,8 +697,8 @@ impl From for crate::lightning::util::events::MessageSendEv /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg. /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is #[no_mangle] -pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::util::events::MessageSendEventsProvider { - crate::lightning::util::events::MessageSendEventsProvider { +pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::events::MessageSendEventsProvider { + crate::lightning::events::MessageSendEventsProvider { this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events, @@ -638,8 +707,8 @@ pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossi #[must_use] extern "C" fn P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); }; + let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, ); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); }; local_ret.into() } @@ -786,6 +855,8 @@ pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut Chann unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val; } /// Constructs a new ChannelUpdateInfo given each field +/// +/// Note that last_update_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] 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 { @@ -812,13 +883,16 @@ impl Clone for ChannelUpdateInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdateInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelUpdateInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelUpdateInfo pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo { orig.clone() } +/// Get a string which allows debug introspection of a ChannelUpdateInfo object +pub extern "C" fn ChannelUpdateInfo_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::ChannelUpdateInfo }).into()} /// Checks if two ChannelUpdateInfos contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. /// Two objects with NULL inner values will be considered "equal" here. @@ -833,7 +907,7 @@ pub extern "C" fn ChannelUpdateInfo_eq(a: &ChannelUpdateInfo, b: &ChannelUpdateI pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::gossip::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) }) } @@ -1011,13 +1085,16 @@ impl Clone for ChannelInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelInfo pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo { orig.clone() } +/// Get a string which allows debug introspection of a ChannelInfo object +pub extern "C" fn ChannelInfo_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::ChannelInfo }).into()} /// Checks if two ChannelInfos contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. /// Two objects with NULL inner values will be considered "equal" here. @@ -1043,7 +1120,7 @@ pub extern "C" fn ChannelInfo_get_directional_info(this_arg: &crate::lightning:: pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::gossip::ChannelInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) }) } @@ -1118,7 +1195,7 @@ impl Clone for DirectedChannelInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDirectedChannelInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the DirectedChannelInfo @@ -1133,14 +1210,6 @@ pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routi crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::ChannelInfo<>) as *mut _) }, is_owned: false } } -/// Returns the maximum HTLC amount allowed over the channel in the direction. -#[must_use] -#[no_mangle] -pub extern "C" fn DirectedChannelInfo_htlc_maximum_msat(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> u64 { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.htlc_maximum_msat(); - ret -} - /// Returns the [`EffectiveCapacity`] of the channel in the direction. /// /// This is either the total capacity from the funding transaction, if known, or the @@ -1153,6 +1222,9 @@ pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::light crate::lightning::routing::gossip::EffectiveCapacity::native_into(ret) } +/// Get a string which allows debug introspection of a DirectedChannelInfo object +pub extern "C" fn DirectedChannelInfo_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::DirectedChannelInfo }).into()} /// The effective capacity of a channel for routing purposes. /// /// While this may be smaller than the actual channel capacity, amounts greater than @@ -1169,7 +1241,7 @@ pub enum EffectiveCapacity { liquidity_msat: u64, }, /// The maximum HTLC amount in one direction as advertised on the gossip network. - MaximumHTLC { + AdvertisedMaxHTLC { /// The maximum HTLC amount denominated in millisatoshi. amount_msat: u64, }, @@ -1183,6 +1255,11 @@ pub enum EffectiveCapacity { /// A capacity sufficient to route any payment, typically used for private channels provided by /// an invoice. Infinite, + /// The maximum HTLC amount as provided by an invoice route hint. + HintMaxHTLC { + /// The maximum HTLC amount denominated in millisatoshi. + amount_msat: u64, + }, /// A capacity that is unknown possibly because either the chain state is unavailable to know /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network. Unknown, @@ -1200,9 +1277,9 @@ impl EffectiveCapacity { liquidity_msat: liquidity_msat_nonref, } }, - EffectiveCapacity::MaximumHTLC {ref amount_msat, } => { + EffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => { let mut amount_msat_nonref = Clone::clone(amount_msat); - nativeEffectiveCapacity::MaximumHTLC { + nativeEffectiveCapacity::AdvertisedMaxHTLC { amount_msat: amount_msat_nonref, } }, @@ -1215,6 +1292,12 @@ impl EffectiveCapacity { } }, EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite, + EffectiveCapacity::HintMaxHTLC {ref amount_msat, } => { + let mut amount_msat_nonref = Clone::clone(amount_msat); + nativeEffectiveCapacity::HintMaxHTLC { + amount_msat: amount_msat_nonref, + } + }, EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown, } } @@ -1226,8 +1309,8 @@ impl EffectiveCapacity { liquidity_msat: liquidity_msat, } }, - EffectiveCapacity::MaximumHTLC {mut amount_msat, } => { - nativeEffectiveCapacity::MaximumHTLC { + EffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => { + nativeEffectiveCapacity::AdvertisedMaxHTLC { amount_msat: amount_msat, } }, @@ -1238,11 +1321,17 @@ impl EffectiveCapacity { } }, EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite, + EffectiveCapacity::HintMaxHTLC {mut amount_msat, } => { + nativeEffectiveCapacity::HintMaxHTLC { + amount_msat: amount_msat, + } + }, EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown, } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self { + pub(crate) fn from_native(native: &EffectiveCapacityImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeEffectiveCapacity) }; match native { nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => { let mut liquidity_msat_nonref = Clone::clone(liquidity_msat); @@ -1250,9 +1339,9 @@ impl EffectiveCapacity { liquidity_msat: liquidity_msat_nonref, } }, - nativeEffectiveCapacity::MaximumHTLC {ref amount_msat, } => { + nativeEffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => { let mut amount_msat_nonref = Clone::clone(amount_msat); - EffectiveCapacity::MaximumHTLC { + EffectiveCapacity::AdvertisedMaxHTLC { amount_msat: amount_msat_nonref, } }, @@ -1265,6 +1354,12 @@ impl EffectiveCapacity { } }, nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite, + nativeEffectiveCapacity::HintMaxHTLC {ref amount_msat, } => { + let mut amount_msat_nonref = Clone::clone(amount_msat); + EffectiveCapacity::HintMaxHTLC { + amount_msat: amount_msat_nonref, + } + }, nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown, } } @@ -1276,8 +1371,8 @@ impl EffectiveCapacity { liquidity_msat: liquidity_msat, } }, - nativeEffectiveCapacity::MaximumHTLC {mut amount_msat, } => { - EffectiveCapacity::MaximumHTLC { + nativeEffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => { + EffectiveCapacity::AdvertisedMaxHTLC { amount_msat: amount_msat, } }, @@ -1288,6 +1383,11 @@ impl EffectiveCapacity { } }, nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite, + nativeEffectiveCapacity::HintMaxHTLC {mut amount_msat, } => { + EffectiveCapacity::HintMaxHTLC { + amount_msat: amount_msat, + } + }, nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown, } } @@ -1300,6 +1400,16 @@ pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { } pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn EffectiveCapacity_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const EffectiveCapacity)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn EffectiveCapacity_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut EffectiveCapacity) }; +} #[no_mangle] /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity { @@ -1308,9 +1418,9 @@ pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> Effe } } #[no_mangle] -/// Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity -pub extern "C" fn EffectiveCapacity_maximum_htlc(amount_msat: u64) -> EffectiveCapacity { - EffectiveCapacity::MaximumHTLC { +/// Utility method to constructs a new AdvertisedMaxHTLC-variant EffectiveCapacity +pub extern "C" fn EffectiveCapacity_advertised_max_htlc(amount_msat: u64) -> EffectiveCapacity { + EffectiveCapacity::AdvertisedMaxHTLC { amount_msat, } } @@ -1327,9 +1437,19 @@ pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity { EffectiveCapacity::Infinite} #[no_mangle] +/// Utility method to constructs a new HintMaxHTLC-variant EffectiveCapacity +pub extern "C" fn EffectiveCapacity_hint_max_htlc(amount_msat: u64) -> EffectiveCapacity { + EffectiveCapacity::HintMaxHTLC { + amount_msat, + } +} +#[no_mangle] /// Utility method to constructs a new Unknown-variant EffectiveCapacity pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity { EffectiveCapacity::Unknown} +/// Get a string which allows debug introspection of a EffectiveCapacity object +pub extern "C" fn EffectiveCapacity_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::EffectiveCapacity }).into()} /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to /// use when making routing decisions. @@ -1448,14 +1568,17 @@ impl Clone for RoutingFees { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRoutingFees)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RoutingFees pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees { orig.clone() } -/// Checks if two RoutingFeess contain equal inner contents. +/// Get a string which allows debug introspection of a RoutingFees object +pub extern "C" fn RoutingFees_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::RoutingFees }).into()} +/// Generates a non-cryptographic 64-bit hash of the RoutingFees. #[no_mangle] pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 { if o.inner.is_null() { return 0; } @@ -1470,7 +1593,7 @@ pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 { pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::gossip::RoutingFees) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) }) } @@ -1582,21 +1705,6 @@ pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::routing::gossip::NodeAlias) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = *unsafe { Box::from_raw(val.take_inner()) }; } -/// Internet-level addresses via which one can connect to the node -/// -/// Returns a copy of the field. -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_get_addresses(this_ptr: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_NetAddressZ { - let mut inner_val = this_ptr.get_native_mut_ref().addresses.clone(); - let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); }; - local_inner_val.into() -} -/// Internet-level addresses via which one can connect to the node -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val; -} /// An initial announcement of the node /// Mostly redundant with the data we store in fields explicitly. /// Everything else is useful only for sending out for initial routing sync. @@ -1621,17 +1729,17 @@ pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut N unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val; } /// Constructs a new NodeAnnouncementInfo given each field +/// +/// Note that announcement_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -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 addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo { - let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); }; +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 { 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()) } }) }; NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo { features: *unsafe { Box::from_raw(features_arg.take_inner()) }, last_update: last_update_arg, rgb: rgb_arg.data, alias: *unsafe { Box::from_raw(alias_arg.take_inner()) }, - addresses: local_addresses_arg, announcement_message: local_announcement_message_arg, }), is_owned: true } } @@ -1647,13 +1755,16 @@ impl Clone for NodeAnnouncementInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAnnouncementInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeAnnouncementInfo pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo { orig.clone() } +/// Get a string which allows debug introspection of a NodeAnnouncementInfo object +pub extern "C" fn NodeAnnouncementInfo_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeAnnouncementInfo }).into()} /// Checks if two NodeAnnouncementInfos contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. /// Two objects with NULL inner values will be considered "equal" here. @@ -1663,12 +1774,21 @@ pub extern "C" fn NodeAnnouncementInfo_eq(a: &NodeAnnouncementInfo, b: &NodeAnno if a.inner.is_null() || b.inner.is_null() { return false; } if a.get_native_ref() == b.get_native_ref() { true } else { false } } +/// Internet-level addresses via which one can connect to the node +#[must_use] +#[no_mangle] +pub extern "C" fn NodeAnnouncementInfo_addresses(this_arg: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_SocketAddressZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.addresses(); + let mut local_ret_clone = Vec::new(); local_ret_clone.extend_from_slice(ret); let mut ret = local_ret_clone; let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; + local_ret.into() +} + #[no_mangle] /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) }) } @@ -1762,13 +1882,26 @@ impl Clone for NodeAlias { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeAlias_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAlias)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAlias)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeAlias pub extern "C" fn NodeAlias_clone(orig: &NodeAlias) -> NodeAlias { orig.clone() } +/// Get a string which allows debug introspection of a NodeAlias object +pub extern "C" fn NodeAlias_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeAlias }).into()} +/// Generates a non-cryptographic 64-bit hash of the NodeAlias. +#[no_mangle] +pub extern "C" fn NodeAlias_hash(o: &NodeAlias) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two NodeAliass contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. /// Two objects with NULL inner values will be considered "equal" here. @@ -1783,7 +1916,7 @@ pub extern "C" fn NodeAlias_eq(a: &NodeAlias, b: &NodeAlias) -> bool { pub extern "C" fn NodeAlias_write(obj: &crate::lightning::routing::gossip::NodeAlias) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeAlias_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAlias) }) } @@ -1882,6 +2015,8 @@ pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut va unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val; } /// Constructs a new NodeInfo given each field +/// +/// Note that announcement_info_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] 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 { @@ -1904,13 +2039,16 @@ impl Clone for NodeInfo { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeInfo)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeInfo pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo { orig.clone() } +/// Get a string which allows debug introspection of a NodeInfo object +pub extern "C" fn NodeInfo_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::gossip::NodeInfo }).into()} /// Checks if two NodeInfos contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. /// Two objects with NULL inner values will be considered "equal" here. @@ -1925,7 +2063,7 @@ pub extern "C" fn NodeInfo_eq(a: &NodeInfo, b: &NodeInfo) -> bool { pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::gossip::NodeInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) }) } @@ -1941,7 +2079,7 @@ pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types: pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) }) } @@ -2014,8 +2152,8 @@ pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: /// Store or update channel info from a channel announcement. /// -/// You probably don't want to call this directly, instead relying on a P2PGossipSync's -/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept +/// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s +/// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. /// /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify @@ -2023,12 +2161,27 @@ pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: #[must_use] #[no_mangle] 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 { - 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() }) } }; + 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() } }})} }; let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_utxo_lookup); 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() }; local_ret } +/// Store or update channel info from a channel announcement. +/// +/// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s +/// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept +/// routing messages from a source using a protocol other than the lightning P2P protocol. +/// +/// This will skip verification of if the channel is actually on-chain. +#[must_use] +#[no_mangle] +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 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement_no_lookup(msg.get_native_ref()); + 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() }; + local_ret +} + /// Store or update channel info from a channel announcement without verifying the associated /// signatures. Because we aren't given the associated signatures here we cannot relay the /// channel announcement to any of our peers. @@ -2038,7 +2191,7 @@ pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &crate #[must_use] #[no_mangle] 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 { - 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() }) } }; + 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() } }})} }; let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_utxo_lookup); 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() }; local_ret @@ -2058,13 +2211,12 @@ pub extern "C" fn NetworkGraph_add_channel_from_partial_announcement(this_arg: & local_ret } -/// Marks a channel in the graph as failed if a corresponding HTLC fail was sent. -/// If permanent, removes a channel from the local storage. -/// May cause the removal of nodes too, if this was their last channel. -/// If not permanent, makes channels unavailable for routing. +/// Marks a channel in the graph as failed permanently. +/// +/// The channel and any node for which this was their last channel are removed from the graph. #[no_mangle] -pub extern "C" fn NetworkGraph_channel_failed(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) { - unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed(short_channel_id, is_permanent) +pub extern "C" fn NetworkGraph_channel_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64) { + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed_permanent(short_channel_id) } /// Marks a node in the graph as permanently failed, effectively removing it and its channels @@ -2116,8 +2268,8 @@ pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking_with_time(this /// For an already known (from announcement) channel, update info about one of the directions /// of the channel. /// -/// You probably don't want to call this directly, instead relying on a P2PGossipSync's -/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept +/// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s +/// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. /// /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or @@ -2144,6 +2296,20 @@ pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &crate::lightni local_ret } +/// For an already known (from announcement) channel, verify the given [`ChannelUpdate`]. +/// +/// This checks whether the update currently is applicable by [`Self::update_channel`]. +/// +/// If built with `no-std`, any updates with a timestamp more than two weeks in the past or +/// materially in the future will be rejected. +#[must_use] +#[no_mangle] +pub extern "C" fn NetworkGraph_verify_channel_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify_channel_update(msg.get_native_ref()); + 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() }; + local_ret +} + /// Returns information on a channel with the given id. /// /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None @@ -2189,9 +2355,9 @@ pub extern "C" fn ReadOnlyNetworkGraph_list_nodes(this_arg: &crate::lightning::r /// or if node announcement for the node was never received. #[must_use] #[no_mangle] -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 { +pub extern "C" fn ReadOnlyNetworkGraph_get_addresses(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::COption_CVec_SocketAddressZZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust()); - 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() }) }; + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_SocketAddressZZ::None } else { crate::c_types::derived::COption_CVec_SocketAddressZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; local_ret_0.into() }) }; local_ret }