From 507f236e41fb5d6e3bcce740264967fd695c6586 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Tue, 12 Sep 2023 09:24:31 -0700 Subject: [PATCH] fix initial get --- signer/Cargo.toml | 1 + signer/src/kvv.rs | 17 +++++++++-------- vls-mqtt/Cargo.toml | 3 ++- vls-mqtt/src/persist.rs | 12 ++++++------ 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/signer/Cargo.toml b/signer/Cargo.toml index d09d064..c963978 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -29,6 +29,7 @@ serde = { version = "1.0.168", default-features = false, features = ["derive"] } hex = { version = "0.4.3", default-features = false } anyhow = { version = "1", default-features = false } fsdb = { git = "https://github.com/Evanfeenstra/fsdb.git", rev = "13f66653ec3c14280fc8ab330108c710c1df3006", optional = true } +# fsdb = { path = "../../fsdb", optional = true } thiserror = "1.0.44" # vls vls-protocol-signer = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "4b2a00975a5c7ccdbcedf6dcf44728b90b296064", default-features = false, features = ["secp-lowmemory"] } diff --git a/signer/src/kvv.rs b/signer/src/kvv.rs index 2dbb9f9..22b0221 100644 --- a/signer/src/kvv.rs +++ b/signer/src/kvv.rs @@ -39,7 +39,7 @@ impl FsKVVStore { let mut versions = BTreeMap::new(); let fulllist = bucket.list_all().expect("could not list bucket"); for path in fulllist { - match bucket.get(&path) { + match bucket.get_raw(&path) { Ok(item) => { let (version, _) = Self::decode_vv(&item); versions.insert(path, version); @@ -167,15 +167,16 @@ impl KVVStore for FsKVVStore { .list(prefix) .map_err(|_| Error::Internal("could not list".to_string()))?; let mut result = Vec::new(); - for mut item in items { - if item.starts_with("/") { - item.remove(0); - } - let key = format!("{}/{}", prefix, item); - log::info!("LIST RES {:?}", key); + for item in items { + let sep = if prefix.ends_with("/") { + "".to_string() + } else { + "/".to_string() + }; + let key = format!("{}{}{}", prefix, sep, item); let vv = self .db - .get(&key) + .get_raw(&key) .map_err(|_| Error::Internal("could not get".to_string()))?; let (version, value) = Self::decode_vv(&vv); result.push(KVV(key, (version, value))); diff --git a/vls-mqtt/Cargo.toml b/vls-mqtt/Cargo.toml index 27f3481..3ce0f8f 100644 --- a/vls-mqtt/Cargo.toml +++ b/vls-mqtt/Cargo.toml @@ -18,7 +18,8 @@ rumqttc = { version = "0.21.0", features = ["url"] } dotenv = "0.15.0" fern = "0.6" chrono = "0.4" -fsdb = { version = "0.1.11" } +fsdb = { version = "0.1.15" } +# fsdb = { path = "../../fsdb" } anyhow = "1" rand = "0.8.5" diff --git a/vls-mqtt/src/persist.rs b/vls-mqtt/src/persist.rs index bd14e6c..1f6f9e5 100644 --- a/vls-mqtt/src/persist.rs +++ b/vls-mqtt/src/persist.rs @@ -31,13 +31,13 @@ impl ControlPersist for ControlPersister { Ok(u64::from_be_bytes(r)) } fn set_nonce(&mut self, nonce: u64) -> Result<()> { - Ok(self.nonce.put("nonce", nonce.to_be_bytes())?) + Ok(self.nonce.put("nonce", &nonce.to_be_bytes())?) } fn read_config(&self) -> Result { Ok(self.config.get("config")?) } fn write_config(&mut self, conf: Config) -> Result<()> { - Ok(self.config.put("config", conf)?) + Ok(self.config.put("config", &conf)?) } fn remove_config(&mut self) -> Result<()> { Ok(self.config.remove("config")?) @@ -46,7 +46,7 @@ impl ControlPersist for ControlPersister { Ok(self.seed.get("seed")?) } fn write_seed(&mut self, s: [u8; 32]) -> Result<()> { - Ok(self.seed.put("seed", s)?) + Ok(self.seed.put("seed", &s)?) } fn remove_seed(&mut self) -> Result<()> { Ok(self.seed.remove("seed")?) @@ -55,13 +55,13 @@ impl ControlPersist for ControlPersister { Ok(self.id.get("id")?) } fn write_id(&mut self, id: String) -> Result<()> { - Ok(self.id.put("id", id)?) + Ok(self.id.put("id", &id)?) } fn read_policy(&self) -> Result { Ok(self.policy.get("policy")?) } fn write_policy(&mut self, pol: Policy) -> Result<()> { - Ok(self.policy.put("policy", pol)?) + Ok(self.policy.put("policy", &pol)?) } fn remove_policy(&mut self) -> Result<()> { Ok(self.policy.remove("policy")?) @@ -70,6 +70,6 @@ impl ControlPersist for ControlPersister { Ok(self.velocity.get("velocity")?) } fn write_velocity(&mut self, v: Velocity) -> Result<()> { - Ok(self.velocity.put("velocity", v)?) + Ok(self.velocity.put("velocity", &v)?) } }