X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Frouting%2Fnetwork_graph.rs;h=ba872b30dfe6c07260f96ed67c5aaf8f9ddced55;hb=d773151e7f46a97f359640e6f33acbec9b2506e8;hp=89f20fd4889487224864a0846ce22b2a70e0e6c0;hpb=353e29aedd2227a1a3a6811df1d73606f63a687e;p=rust-lightning diff --git a/lightning-c-bindings/src/routing/network_graph.rs b/lightning-c-bindings/src/routing/network_graph.rs index 89f20fd4..ba872b30 100644 --- a/lightning-c-bindings/src/routing/network_graph.rs +++ b/lightning-c-bindings/src/routing/network_graph.rs @@ -84,7 +84,7 @@ impl LockedNetworkGraph { } use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport; -type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport; +type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport; /// Receives and validates network updates from peers, /// stores authentic and relevant data as a network graph. @@ -131,8 +131,9 @@ impl NetGraphMsgHandler { /// channel owners' keys. #[must_use] #[no_mangle] -pub extern "C" fn NetGraphMsgHandler_new(mut chain_monitor: crate::chain::chaininterface::ChainWatchInterface, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler { - let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(chain_monitor, logger); +pub extern "C" fn NetGraphMsgHandler_new(chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler { + let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) }; + let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(local_chain_access, logger); NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true } } @@ -140,8 +141,9 @@ pub extern "C" fn NetGraphMsgHandler_new(mut chain_monitor: crate::chain::chaini /// assuming an existing Network Graph. #[must_use] #[no_mangle] -pub extern "C" fn NetGraphMsgHandler_from_net_graph(mut chain_monitor: crate::chain::chaininterface::ChainWatchInterface, mut logger: crate::util::logger::Logger, mut network_graph: crate::routing::network_graph::NetworkGraph) -> NetGraphMsgHandler { - let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(chain_monitor, logger, *unsafe { Box::from_raw(network_graph.take_ptr()) }); +pub extern "C" fn NetGraphMsgHandler_from_net_graph(chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger, mut network_graph: crate::routing::network_graph::NetworkGraph) -> NetGraphMsgHandler { + let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) }; + let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_ptr()) }); NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true } } @@ -214,7 +216,7 @@ extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcemen local_ret.into() } #[must_use] -extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync(this_arg: *const c_void, _node_id: crate::c_types::PublicKey) -> bool { +extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync(this_arg: *const c_void, mut _node_id: crate::c_types::PublicKey) -> bool { let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.should_request_full_sync(&_node_id.into_rust()); ret } @@ -374,6 +376,17 @@ impl ChannelInfo { ret } } +/// Protocol features of a channel communicated during its announcement +#[no_mangle] +pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::ln::features::ChannelFeatures { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features; + crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } +} +/// Protocol features of a channel communicated during its announcement +#[no_mangle] +pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::ln::features::ChannelFeatures) { + unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_ptr()) }; +} /// Source node of the first direction of a channel #[no_mangle] pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey { @@ -586,6 +599,17 @@ impl NodeAnnouncementInfo { ret } } +/// Protocol features the node announced support for +#[no_mangle] +pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features; + crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } +} +/// Protocol features the node announced support for +#[no_mangle] +pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::features::NodeFeatures) { + unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_ptr()) }; +} /// When the last known update to the node state was issued. /// Value is opaque, as set in the announcement. #[no_mangle] @@ -650,6 +674,20 @@ pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut N let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) }; unsafe { &mut *this_ptr.inner }.announcement_message = local_val; } +#[must_use] +#[no_mangle] +pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::ln::features::NodeFeatures, mut last_update_arg: u32, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::c_types::ThirtyTwoBytes, mut addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::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() }); }; + let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_ptr()) } }) }; + NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo { + features: *unsafe { Box::from_raw(features_arg.take_ptr()) }, + last_update: last_update_arg, + rgb: rgb_arg.data, + alias: alias_arg.data, + addresses: local_addresses_arg, + announcement_message: local_announcement_message_arg, + })), is_owned: true } +} #[no_mangle] pub extern "C" fn NodeAnnouncementInfo_write(obj: *const NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })