X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Frouting%2Fgossip.rs;h=6284e6c46c582363c378beda6e471996ad1157a3;hb=11b997c3a0452ea1da5b7b352e7887798105db29;hp=3a7943bd28aa0041f20b3b71f4264146bf52e08d;hpb=a21177846ed75d66f68a1603f768410f07a65791;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 3a7943b..6284e6c 100644 --- a/lightning-c-bindings/src/lightning/routing/gossip.rs +++ b/lightning-c-bindings/src/lightning/routing/gossip.rs @@ -6,7 +6,7 @@ // license as that which applies to the original source files from which this // source was automatically generated. -//! The top-level network map tracking logic lives here. +//! The [`NetworkGraph`] stores the network gossip and [`P2PGossipSync`] fetches it from peers use alloc::str::FromStr; use core::ffi::c_void; @@ -49,7 +49,7 @@ pub extern "C" fn NodeId_free(this_obj: 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_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeId); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeId) }; } #[allow(unused)] impl NodeId { @@ -162,7 +162,7 @@ pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNetworkGraph) }; } #[allow(unused)] impl NetworkGraph { @@ -213,7 +213,7 @@ pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph) }; } #[allow(unused)] impl ReadOnlyNetworkGraph { @@ -272,22 +272,22 @@ impl NetworkUpdate { pub(crate) fn to_native(&self) -> nativeNetworkUpdate { match self { NetworkUpdate::ChannelUpdateMessage {ref msg, } => { - let mut msg_nonref = (*msg).clone(); + let mut msg_nonref = Clone::clone(msg); nativeNetworkUpdate::ChannelUpdateMessage { msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, } }, NetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => { - let mut short_channel_id_nonref = (*short_channel_id).clone(); - let mut is_permanent_nonref = (*is_permanent).clone(); + let mut short_channel_id_nonref = Clone::clone(short_channel_id); + let mut is_permanent_nonref = Clone::clone(is_permanent); nativeNetworkUpdate::ChannelFailure { short_channel_id: short_channel_id_nonref, is_permanent: is_permanent_nonref, } }, NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut is_permanent_nonref = (*is_permanent).clone(); + let mut node_id_nonref = Clone::clone(node_id); + let mut is_permanent_nonref = Clone::clone(is_permanent); nativeNetworkUpdate::NodeFailure { node_id: node_id_nonref.into_rust(), is_permanent: is_permanent_nonref, @@ -321,22 +321,22 @@ impl NetworkUpdate { pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self { match native { nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => { - let mut msg_nonref = (*msg).clone(); + let mut msg_nonref = Clone::clone(msg); NetworkUpdate::ChannelUpdateMessage { msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true }, } }, nativeNetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => { - let mut short_channel_id_nonref = (*short_channel_id).clone(); - let mut is_permanent_nonref = (*is_permanent).clone(); + let mut short_channel_id_nonref = Clone::clone(short_channel_id); + let mut is_permanent_nonref = Clone::clone(is_permanent); NetworkUpdate::ChannelFailure { short_channel_id: short_channel_id_nonref, is_permanent: is_permanent_nonref, } }, nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut is_permanent_nonref = (*is_permanent).clone(); + let mut node_id_nonref = Clone::clone(node_id); + let mut is_permanent_nonref = Clone::clone(is_permanent); NetworkUpdate::NodeFailure { node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), is_permanent: is_permanent_nonref, @@ -418,16 +418,13 @@ pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_t } use lightning::routing::gossip::P2PGossipSync as nativeP2PGossipSyncImport; -pub(crate) type nativeP2PGossipSync = nativeP2PGossipSyncImport<&'static lightning::routing::gossip::NetworkGraph, crate::lightning::chain::Access, crate::lightning::util::logger::Logger>; +pub(crate) type nativeP2PGossipSync = nativeP2PGossipSyncImport<&'static lightning::routing::gossip::NetworkGraph, crate::lightning::routing::utxo::UtxoLookup, crate::lightning::util::logger::Logger>; /// Receives and validates network updates from peers, /// stores authentic and relevant data as a network graph. /// This network graph is then used for routing payments. /// Provides interface to help with initial routing sync by /// serving historical announcements. -/// -/// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the -/// [`NetworkGraph`]. #[must_use] #[repr(C)] pub struct P2PGossipSync { @@ -456,7 +453,7 @@ pub extern "C" fn P2PGossipSync_free(this_obj: P2PGossipSync) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn P2PGossipSync_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeP2PGossipSync); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeP2PGossipSync) }; } #[allow(unused)] impl P2PGossipSync { @@ -476,14 +473,13 @@ impl P2PGossipSync { } /// Creates a new tracker of the actual state of the network of channels and nodes, /// assuming an existing Network Graph. -/// Chain monitor is used to make sure announced channels exist on-chain, -/// channel data is correct, and that the announcement is signed with -/// channel owners' keys. +/// 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 chain_access: crate::c_types::derived::COption_AccessZ, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::P2PGossipSync { - let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } }; - let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_chain_access, logger); +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 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 } } @@ -491,34 +487,17 @@ 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_chain_access(this_arg: &mut crate::lightning::routing::gossip::P2PGossipSync, mut chain_access: crate::c_types::derived::COption_AccessZ) { - let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } }; - unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::gossip::nativeP2PGossipSync)) }.add_chain_access(local_chain_access) +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) } -impl From for crate::lightning::util::events::EventHandler { - fn from(obj: nativeNetworkGraph) -> Self { - let mut rust_obj = NetworkGraph { inner: ObjOps::heap_alloc(obj), is_owned: true }; - let mut ret = NetworkGraph_as_EventHandler(&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(); - ret.free = Some(NetworkGraph_free_void); - ret - } -} -/// Constructs a new EventHandler which calls the relevant methods on this_arg. -/// This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is +/// Handles any network updates originating from [`Event`]s. +/// +/// [`Event`]: crate::util::events::Event #[no_mangle] -pub extern "C" fn NetworkGraph_as_EventHandler(this_arg: &NetworkGraph) -> crate::lightning::util::events::EventHandler { - crate::lightning::util::events::EventHandler { - this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, - free: None, - handle_event: NetworkGraph_EventHandler_handle_event, - } -} - -extern "C" fn NetworkGraph_EventHandler_handle_event(this_arg: *const c_void, event: &crate::lightning::util::events::Event) { - >::handle_event(unsafe { &mut *(this_arg as *mut nativeNetworkGraph) }, &event.to_native()) +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()) } impl From for crate::lightning::ln::msgs::RoutingMessageHandler { @@ -548,6 +527,7 @@ pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSyn handle_reply_short_channel_ids_end: P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end, handle_query_channel_range: P2PGossipSync_RoutingMessageHandler_handle_query_channel_range, handle_query_short_channel_ids: P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids, + 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 { @@ -583,15 +563,15 @@ extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement( local_ret } #[must_use] -extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_node_announcement(this_arg: *const c_void, mut starting_point: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::NodeAnnouncement { - let mut local_starting_point_base = if starting_point.is_null() { None } else { Some( { starting_point.into_rust() }) }; let mut local_starting_point = local_starting_point_base.as_ref(); +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 { + let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) }; let mut ret = >::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, local_starting_point); 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 }; local_ret } #[must_use] -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) -> crate::c_types::derived::CResult_NoneNoneZ { - let mut ret = >::peer_connected(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), init.get_native_ref()); +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 { + let mut ret = >::peer_connected(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), init.get_native_ref(), inbound); 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() }; local_ret } @@ -620,6 +600,11 @@ extern "C" fn P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids local_ret } #[must_use] +extern "C" fn P2PGossipSync_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool { + let mut ret = >::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, ); + ret +} +#[must_use] extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures { let mut ret = >::provided_node_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, ); crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } @@ -691,7 +676,7 @@ pub extern "C" fn ChannelUpdateInfo_free(this_obj: 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_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo) }; } #[allow(unused)] impl ChannelUpdateInfo { @@ -893,7 +878,7 @@ pub extern "C" fn ChannelInfo_free(this_obj: 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_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelInfo) }; } #[allow(unused)] impl ChannelInfo { @@ -1103,7 +1088,7 @@ pub extern "C" fn DirectedChannelInfo_free(this_obj: 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_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo) }; } #[allow(unused)] impl DirectedChannelInfo { @@ -1148,17 +1133,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 information for the direction. -/// -/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None -#[must_use] -#[no_mangle] -pub extern "C" fn DirectedChannelInfo_direction(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.direction(); - 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 }; - local_ret -} - /// Returns the maximum HTLC amount allowed over the channel in the direction. #[must_use] #[no_mangle] @@ -1204,7 +1178,7 @@ pub enum EffectiveCapacity { /// The funding amount denominated in millisatoshi. capacity_msat: u64, /// The maximum HTLC amount denominated in millisatoshi. - htlc_maximum_msat: crate::c_types::derived::COption_u64Z, + htlc_maximum_msat: u64, }, /// A capacity sufficient to route any payment, typically used for private channels provided by /// an invoice. @@ -1221,24 +1195,23 @@ impl EffectiveCapacity { pub(crate) fn to_native(&self) -> nativeEffectiveCapacity { match self { EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => { - let mut liquidity_msat_nonref = (*liquidity_msat).clone(); + let mut liquidity_msat_nonref = Clone::clone(liquidity_msat); nativeEffectiveCapacity::ExactLiquidity { liquidity_msat: liquidity_msat_nonref, } }, EffectiveCapacity::MaximumHTLC {ref amount_msat, } => { - let mut amount_msat_nonref = (*amount_msat).clone(); + let mut amount_msat_nonref = Clone::clone(amount_msat); nativeEffectiveCapacity::MaximumHTLC { amount_msat: amount_msat_nonref, } }, EffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => { - let mut capacity_msat_nonref = (*capacity_msat).clone(); - let mut htlc_maximum_msat_nonref = (*htlc_maximum_msat).clone(); - let mut local_htlc_maximum_msat_nonref = if htlc_maximum_msat_nonref.is_some() { Some( { htlc_maximum_msat_nonref.take() }) } else { None }; + let mut capacity_msat_nonref = Clone::clone(capacity_msat); + let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat); nativeEffectiveCapacity::Total { capacity_msat: capacity_msat_nonref, - htlc_maximum_msat: local_htlc_maximum_msat_nonref, + htlc_maximum_msat: htlc_maximum_msat_nonref, } }, EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite, @@ -1259,10 +1232,9 @@ impl EffectiveCapacity { } }, EffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => { - let mut local_htlc_maximum_msat = if htlc_maximum_msat.is_some() { Some( { htlc_maximum_msat.take() }) } else { None }; nativeEffectiveCapacity::Total { capacity_msat: capacity_msat, - htlc_maximum_msat: local_htlc_maximum_msat, + htlc_maximum_msat: htlc_maximum_msat, } }, EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite, @@ -1273,24 +1245,23 @@ impl EffectiveCapacity { pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self { match native { nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => { - let mut liquidity_msat_nonref = (*liquidity_msat).clone(); + let mut liquidity_msat_nonref = Clone::clone(liquidity_msat); EffectiveCapacity::ExactLiquidity { liquidity_msat: liquidity_msat_nonref, } }, nativeEffectiveCapacity::MaximumHTLC {ref amount_msat, } => { - let mut amount_msat_nonref = (*amount_msat).clone(); + let mut amount_msat_nonref = Clone::clone(amount_msat); EffectiveCapacity::MaximumHTLC { amount_msat: amount_msat_nonref, } }, nativeEffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => { - let mut capacity_msat_nonref = (*capacity_msat).clone(); - let mut htlc_maximum_msat_nonref = (*htlc_maximum_msat).clone(); - let mut local_htlc_maximum_msat_nonref = if htlc_maximum_msat_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { htlc_maximum_msat_nonref.unwrap() }) }; + let mut capacity_msat_nonref = Clone::clone(capacity_msat); + let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat); EffectiveCapacity::Total { capacity_msat: capacity_msat_nonref, - htlc_maximum_msat: local_htlc_maximum_msat_nonref, + htlc_maximum_msat: htlc_maximum_msat_nonref, } }, nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite, @@ -1311,10 +1282,9 @@ impl EffectiveCapacity { } }, nativeEffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => { - let mut local_htlc_maximum_msat = if htlc_maximum_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { htlc_maximum_msat.unwrap() }) }; EffectiveCapacity::Total { capacity_msat: capacity_msat, - htlc_maximum_msat: local_htlc_maximum_msat, + htlc_maximum_msat: htlc_maximum_msat, } }, nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite, @@ -1346,7 +1316,7 @@ pub extern "C" fn EffectiveCapacity_maximum_htlc(amount_msat: u64) -> EffectiveC } #[no_mangle] /// Utility method to constructs a new Total-variant EffectiveCapacity -pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: crate::c_types::derived::COption_u64Z) -> EffectiveCapacity { +pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: u64) -> EffectiveCapacity { EffectiveCapacity::Total { capacity_msat, htlc_maximum_msat, @@ -1406,7 +1376,7 @@ pub extern "C" fn RoutingFees_free(this_obj: 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_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoutingFees) }; } #[allow(unused)] impl RoutingFees { @@ -1424,13 +1394,13 @@ impl RoutingFees { ret } } -/// Flat routing fee in satoshis +/// Flat routing fee in millisatoshis. #[no_mangle] pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 { let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat; *inner_val } -/// Flat routing fee in satoshis +/// Flat routing fee in millisatoshis. #[no_mangle] pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val; @@ -1544,7 +1514,7 @@ pub extern "C" fn NodeAnnouncementInfo_free(this_obj: 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_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo) }; } #[allow(unused)] impl NodeAnnouncementInfo { @@ -1745,7 +1715,7 @@ pub extern "C" fn NodeAlias_free(this_obj: 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_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAlias); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAlias) }; } #[allow(unused)] impl NodeAlias { @@ -1857,7 +1827,7 @@ pub extern "C" fn NodeInfo_free(this_obj: 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_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeInfo) }; } #[allow(unused)] impl NodeInfo { @@ -1890,27 +1860,6 @@ pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate: let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val; } -/// Lowest fees enabling routing via any of the enabled, known channels to a node. -/// The two fields (flat and proportional fee) are independent, -/// meaning they don't have to refer to the same channel. -/// -/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None -#[no_mangle] -pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::RoutingFees { - let mut inner_val = &mut this_ptr.get_native_mut_ref().lowest_inbound_channel_fees; - let mut local_inner_val = crate::lightning::routing::gossip::RoutingFees { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::gossip::RoutingFees<>) as *mut _ }, is_owned: false }; - local_inner_val -} -/// Lowest fees enabling routing via any of the enabled, known channels to a node. -/// The two fields (flat and proportional fee) are independent, -/// meaning they don't have to refer to the same channel. -/// -/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None -#[no_mangle] -pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::RoutingFees) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.lowest_inbound_channel_fees = local_val; -} /// More information about a node from node_announcement. /// Optional because we store a Node entry after learning about it from /// a channel announcement, but before receiving a node announcement. @@ -1935,13 +1884,11 @@ pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut va /// Constructs a new NodeInfo given each field #[must_use] #[no_mangle] -pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::lightning::routing::gossip::RoutingFees, mut announcement_info_arg: crate::lightning::routing::gossip::NodeAnnouncementInfo) -> NodeInfo { +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 { let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); }; - let mut local_lowest_inbound_channel_fees_arg = if lowest_inbound_channel_fees_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(lowest_inbound_channel_fees_arg.take_inner()) } }) }; 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()) } }) }; NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo { channels: local_channels_arg, - lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg, announcement_info: local_announcement_info_arg, }), is_owned: true } } @@ -2009,8 +1956,8 @@ pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::li /// Creates a new, empty, network graph. #[must_use] #[no_mangle] -pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph { - let mut ret = lightning::routing::gossip::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), logger); +pub extern "C" fn NetworkGraph_new(mut network: crate::bitcoin::network::Network, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph { + let mut ret = lightning::routing::gossip::NetworkGraph::new(network.into_bitcoin(), logger); crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true } } @@ -2071,13 +2018,13 @@ pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: /// 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 `chain::Access` object is provided via `chain_access`, it will be called to verify +/// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify /// the corresponding UTXO exists on chain and is correctly-formatted. #[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 chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ { - let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } }; - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_chain_access); +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 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 } @@ -2086,13 +2033,13 @@ pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &crate /// signatures. Because we aren't given the associated signatures here we cannot relay the /// channel announcement to any of our peers. /// -/// If a `chain::Access` object is provided via `chain_access`, it will be called to verify +/// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify /// the corresponding UTXO exists on chain and is correctly-formatted. #[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 chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ { - let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } }; - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_chain_access); +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 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 }