From a0c2c26da5040da9a2f87b0de087dd3e1a53aa15 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Fri, 26 Jul 2024 19:43:26 +0200 Subject: [PATCH 1/2] gossip_map: add meta information Signed-off-by: Vincenzo Palazzo --- gossip_map/Cargo.toml | 12 +++++++++--- gossip_map/README.md | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 gossip_map/README.md diff --git a/gossip_map/Cargo.toml b/gossip_map/Cargo.toml index 15516f3..dc86f0c 100644 --- a/gossip_map/Cargo.toml +++ b/gossip_map/Cargo.toml @@ -1,7 +1,13 @@ [package] name = "clightningrpc_gossip_map" -version = "0.1.0" +version = "0.0.1-beta.2" edition = "2021" +description = "Crate that provides a plugin API to give the possibility to implement a plugin in Rust" +license = "CC0-1.0" +homepage = "https://github.com/laanwj/rust-clightning-rpc" +repository = "https://github.com/laanwj/rust-clightning-rpc.git" +keywords = [ "plugin", "cln", "rpc", "lightning", "bitcoin" ] +readme = "README.md" [dependencies] anyhow = "1" @@ -9,8 +15,8 @@ log = "0.4.21" byteorder = "1.4.3" hex = "0.4.3" bitcoin = { version = "0.30.0" } -fundamentals = { git = "https://github.com/lnspec-tools/ln-fundamentals.git", branch = "macros/fix_fixed_read" } -fundamentals-derive = { git = "https://github.com/lnspec-tools/ln-fundamentals.git", branch = "macros/fix_fixed_read" } +fundamentals = { version = "0.0.1-alpha.4" } +fundamentals-derive = { version = "0.0.1-alpha.2"} [dev-dependencies] anyhow = "1.0.70" diff --git a/gossip_map/README.md b/gossip_map/README.md new file mode 100644 index 0000000..73acc74 --- /dev/null +++ b/gossip_map/README.md @@ -0,0 +1,16 @@ +# gossip map + +Core Lightning Gossip Map parser to access the gossip map with rust. + +## Example + +``` rust +fn main() { + let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../contrib/gossip_store"); + let pubkey = "03e2408a49f07d2f4083a47344138ef89e7617e63919202c92aa8d49b574a560ae"; + let map = GossipMap::from_file(path); + assert!(map.is_ok(), "{:?}", map); + let map = map.unwrap(); + assert!(map.get_node(pubkey).is_some(), "node with id `{pubkey}` not found!"); +} +``` From 5d3dfab01150d11cf83612685ca0899fc325ea30 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Mon, 29 Jul 2024 08:30:26 +0200 Subject: [PATCH 2/2] map: make the struct public Reported-by: @tareknaser Signed-off-by: Vincenzo Palazzo --- gossip_map/src/lib.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/gossip_map/src/lib.rs b/gossip_map/src/lib.rs index 6a59ad2..8bfb2bb 100644 --- a/gossip_map/src/lib.rs +++ b/gossip_map/src/lib.rs @@ -26,9 +26,8 @@ use crate::gossip_types::{GossipChannel, GossipNode, GossipNodeId, GossipStoredH /// Gossip map implementation, that allow you to manage the gossip_store /// written by core lightning. #[derive(Debug)] -struct GossipMap { - // FIXME: make this optional - path: String, +pub struct GossipMap { + path: Option, version: u8, stream: Option>, nodes: HashMap, @@ -41,7 +40,7 @@ impl GossipMap { pub fn new(version: u8) -> Self { log::debug!("gossip map version `{version}`"); GossipMap { - path: "".to_owned(), + path: None, version, stream: None, nodes: HashMap::new(), @@ -55,7 +54,7 @@ impl GossipMap { let gossip_store = File::open(file_name)?; let stream = BufReader::new(gossip_store); let mut gossip_map = GossipMap { - path: file_name.to_owned(), + path: Some(file_name.to_owned()), version: 0, stream: Some(stream), nodes: HashMap::new(), @@ -76,13 +75,21 @@ impl GossipMap { } /// add a node announcement message inside the gossip map - fn add_node_announcement(&mut self, node_announce: NodeAnnouncement) {} + fn add_node_announcement(&mut self, node_announce: NodeAnnouncement) { + unimplemented!() + } /// add a channel announcement message inside the gossip map. - fn add_channel_announcement(&mut self, channel_announce: ChannelAnnouncement) {} + fn add_channel_announcement(&mut self, channel_announce: ChannelAnnouncement) { + unimplemented!() + } fn refresh(&mut self) -> anyhow::Result<()> { - let gossip_store = File::open(self.path.clone())?; + let gossip_store = File::open( + self.path + .as_ref() + .ok_or(anyhow::anyhow!("Gossip map not found"))?, + )?; let mut stream = BufReader::new(gossip_store); let version = u8::from_wire(&mut stream)? as u16;