From 0bfcdf822f10073030cf18c62a98add258ed9715 Mon Sep 17 00:00:00 2001 From: elnosh Date: Fri, 12 Apr 2024 13:45:44 -0500 Subject: [PATCH] add mutiny-server commands to justfile --- justfile | 11 + mutiny-server/.gitignore | 2 +- mutiny-server/Cargo.lock | 272 ++++++++++++++-------- mutiny-server/Cargo.toml | 6 +- mutiny-server/src/config.rs | 2 +- mutiny-server/src/main.rs | 6 +- mutiny-server/src/{sled.rs => rocksdb.rs} | 85 +++---- mutiny-server/src/routes.rs | 4 +- 8 files changed, 232 insertions(+), 156 deletions(-) rename mutiny-server/src/{sled.rs => rocksdb.rs} (67%) diff --git a/justfile b/justfile index 318e9cb85..de74bccce 100644 --- a/justfile +++ b/justfile @@ -38,14 +38,25 @@ clippy: cargo clippy --all-features --tests --package mutiny-core --target=wasm32-unknown-unknown -- -D warnings cargo clippy --all-features --tests --package mutiny-core --target=aarch64-apple-darwin -- -D warnings cargo clippy --all-features --tests --package mutiny-wasm -- -D warnings + cd mutiny-server && cargo clippy --all-features --tests --target=aarch64-apple-darwin -- -D warnings [linux] clippy: cargo clippy --all-features --tests --package mutiny-core --target=wasm32-unknown-unknown -- -D warnings cargo clippy --all-features --tests --package mutiny-core --target=x86_64-unknown-linux-gnu -- -D warnings cargo clippy --all-features --tests --package mutiny-wasm -- -D warnings + cd mutiny-server && cargo clippy --all-features --tests --target=x86_64-unknown-linux-gnu -- -D warnings clippy-nix: cargo clippy --all-features --tests --package mutiny-core --target=wasm32-unknown-unknown -- -D warnings cargo clippy --all-features --tests --package mutiny-core --target=aarch64-unknown-linux-gnu -- -D warnings cargo clippy --all-features --tests --package mutiny-wasm -- -D warnings + cd mutiny-server && cargo clippy --all-features --tests --target=aarch64-unknown-linux-gnu -- -D warnings + +[macos] +run-signet: + cd mutiny-server && RUST_LOG=info cargo run --target aarch64-apple-darwin -- --lsp-url "https://signet-lsp.mutinywallet.com" + +[linux] +run-signet: + cd mutiny-server && RUST_LOG=info cargo run --target x86_64-unknown-linux-gnu -- --lsp-url "https://signet-lsp.mutinywallet.com" \ No newline at end of file diff --git a/mutiny-server/.gitignore b/mutiny-server/.gitignore index a81b1e8b0..8b7bf6b1c 100644 --- a/mutiny-server/.gitignore +++ b/mutiny-server/.gitignore @@ -1,2 +1,2 @@ # default database file -sled.db \ No newline at end of file +rocksdb \ No newline at end of file diff --git a/mutiny-server/Cargo.lock b/mutiny-server/Cargo.lock index ca5d47965..85bf5f80f 100644 --- a/mutiny-server/Cargo.lock +++ b/mutiny-server/Cargo.lock @@ -487,6 +487,26 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags 2.5.0", + "cexpr", + "clang-sys", + "itertools 0.12.1", + "lazy_static", + "lazycell", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.58", +] + [[package]] name = "bip21" version = "0.3.1" @@ -559,8 +579,9 @@ checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" [[package]] name = "bitcoin-waila" -version = "0.4.1" -source = "git+https://github.com/mutinywallet/bitcoin-waila?rev=1d6c416fc0abaa2efa78e3dcf28450975d8f7bfe#1d6c416fc0abaa2efa78e3dcf28450975d8f7bfe" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0360146aaf278fbef5f34b7c83ff889cb5b43742af261bf0ee75b653ad1e495d" dependencies = [ "bip21", "bitcoin 0.30.2", @@ -733,6 +754,17 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "cbc" version = "0.1.2" @@ -747,6 +779,19 @@ name = "cc" version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +dependencies = [ + "jobserver", + "libc", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] [[package]] name = "cfg-if" @@ -831,6 +876,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "4.5.4" @@ -920,24 +976,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc32fast" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.19" @@ -1606,16 +1644,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "funty" version = "2.0.0" @@ -1721,15 +1749,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -1769,6 +1788,12 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "gloo-net" version = "0.4.0" @@ -2357,6 +2382,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685a7d121ee3f65ae4fddd72b25a04bb36b6af81bc0828f7d5434c0fe60fa3a2" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -2499,18 +2533,61 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libloading" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +dependencies = [ + "cfg-if", + "windows-targets 0.52.4", +] + [[package]] name = "libm" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "librocksdb-sys" +version = "0.16.0+8.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce3d60bc059831dc1c83903fb45c103f75db65c5a7bf22272764d9cc683e348c" +dependencies = [ + "bindgen", + "bzip2-sys", + "cc", + "glob", + "libc", + "libz-sys", + "lz4-sys", + "zstd-sys", +] + +[[package]] +name = "libz-sys" +version = "1.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e143b5e666b2695d28f6bca6497720813f699c9602dd7f5cac91008b8ada7f9" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "lightning" version = "0.0.118" @@ -2683,6 +2760,16 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "lz4-sys" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d27b317e207b10f69f5e75494119e391a96f48861ae870d1da6edac98ca900" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "macro_rules_attribute" version = "0.2.0" @@ -2736,6 +2823,12 @@ dependencies = [ "unicase", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniscript" version = "9.0.2" @@ -2778,8 +2871,9 @@ dependencies = [ [[package]] name = "moksha-core" -version = "0.2.0-beta" -source = "git+https://github.com/ngutech21/moksha?rev=18d99977965662d46ccec29fecdb0ce493745917#18d99977965662d46ccec29fecdb0ce493745917" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4923b0e31fd02fe8ebc2f58ed0909c8e1d90f0b5153948d3940e634421240c30" dependencies = [ "anyhow", "base64 0.21.7", @@ -2808,7 +2902,7 @@ dependencies = [ [[package]] name = "mutiny-core" -version = "0.6.3" +version = "0.6.4" dependencies = [ "aes", "aes-gcm", @@ -2887,10 +2981,10 @@ dependencies = [ "mutiny-core", "pretty_env_logger", "reqwest", + "rocksdb", "serde", "serde_json", "shutdown", - "sled", "tokio", ] @@ -2918,6 +3012,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e664971378a3987224f7a0e10059782035e89899ae403718ee07de85bec42afe" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nostr" version = "0.29.1" @@ -3181,17 +3285,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -3199,21 +3292,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.9", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -3224,7 +3303,7 @@ checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.4.1", + "redox_syscall", "smallvec", "windows-targets 0.48.5", ] @@ -3494,15 +3573,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -3632,6 +3702,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rocksdb" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bd13e55d6d7b8cd0ea569161127567cd587676c99f4472f779a0279aa60a7a7" +dependencies = [ + "libc", + "librocksdb-sys", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -4070,6 +4150,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "shutdown" version = "0.2.1" @@ -4109,22 +4195,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "sled" -version = "0.34.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935" -dependencies = [ - "crc32fast", - "crossbeam-epoch", - "crossbeam-utils", - "fs2", - "fxhash", - "libc", - "log", - "parking_lot 0.11.2", -] - [[package]] name = "smallvec" version = "1.13.2" @@ -4377,7 +4447,7 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot 0.12.1", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -5208,3 +5278,13 @@ dependencies = [ "quote", "syn 2.0.58", ] + +[[package]] +name = "zstd-sys" +version = "2.0.10+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/mutiny-server/Cargo.toml b/mutiny-server/Cargo.toml index 27e958ae8..341c082e9 100644 --- a/mutiny-server/Cargo.toml +++ b/mutiny-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mutiny-server" -version = "0.6.4" +version = "0.6.6" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -20,10 +20,10 @@ pretty_env_logger = "0.5.0" serde_json = { version = "^1.0" } shutdown = "0.2.1" futures-util = { version = "0.3", default-features = false } -sled = "0.34.7" tokio = { version = "1.36.0", features = ["full"] } reqwest = { version = "0.11", features = ["json"] } serde = { version = "1.0.196", features = ["derive"] } +rocksdb = "0.22.0" [patch.crates-io] -lightning = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" } \ No newline at end of file +lightning = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" } diff --git a/mutiny-server/src/config.rs b/mutiny-server/src/config.rs index 21a4a7f40..d8d7beeab 100644 --- a/mutiny-server/src/config.rs +++ b/mutiny-server/src/config.rs @@ -6,7 +6,7 @@ use std::str::FromStr; #[command(version, author, about)] /// Mutiny Wallet pub struct Config { - #[clap(default_value_t = String::from("sled.db"), long)] + #[clap(default_value_t = String::from("rocksdb"), long)] /// Location of database file pub db_file: String, #[clap(long)] diff --git a/mutiny-server/src/main.rs b/mutiny-server/src/main.rs index 03afc49bd..0aa8ecb80 100644 --- a/mutiny-server/src/main.rs +++ b/mutiny-server/src/main.rs @@ -2,11 +2,11 @@ mod config; mod extractor; +mod rocksdb; mod routes; -mod sled; use crate::config::Config; -use crate::sled::SledStorage; +use crate::rocksdb::RocksDB; use axum::http::{StatusCode, Uri}; use axum::routing::{get, post}; use axum::{Extension, Router}; @@ -25,7 +25,7 @@ async fn main() -> anyhow::Result<()> { let config: Config = Config::parse(); let network = config.network(); - let storage = SledStorage::new(&config.db_file, config.password.clone())?; + let storage = RocksDB::new(&config.db_file, config.password.clone())?; let mnemonic = match storage.get_mnemonic() { Ok(Some(mnemonic)) => mnemonic, diff --git a/mutiny-server/src/sled.rs b/mutiny-server/src/rocksdb.rs similarity index 67% rename from mutiny-server/src/sled.rs rename to mutiny-server/src/rocksdb.rs index 5bbf537b6..f11c4e204 100644 --- a/mutiny-server/src/sled.rs +++ b/mutiny-server/src/rocksdb.rs @@ -1,35 +1,27 @@ use anyhow::anyhow; use async_trait::async_trait; -use bitcoin::hashes::serde::{Deserialize, Serialize}; use futures_util::lock::Mutex; use mutiny_core::encrypt::{encryption_key_from_pass, Cipher}; use mutiny_core::error::MutinyError; use mutiny_core::storage::{DelayedKeyValueItem, DeviceLock, IndexItem, MutinyStorage}; use mutiny_core::vss::MutinyVssClient; -use sled::IVec; +use rocksdb::{IteratorMode, WriteBatchWithTransaction, DB}; +use serde::{Deserialize, Serialize}; use std::collections::{BTreeSet, HashMap}; use std::sync::{Arc, RwLock}; #[derive(Clone)] -pub struct SledStorage { +pub struct RocksDB { pub(crate) password: Option, pub cipher: Option, - db: sled::Db, + db: Arc, delayed_keys: Arc>>, activity_index: Arc>>, } -impl SledStorage { +impl RocksDB { pub fn new(db_file: &str, password: Option) -> anyhow::Result { - let db = { - match sled::open(db_file) { - Ok(db) => db, - Err(_) => { - std::fs::create_dir_all(db_file)?; - sled::open(db_file)? - } - } - }; + let db = DB::open_default(db_file)?; let cipher = password .as_ref() @@ -40,20 +32,15 @@ impl SledStorage { Ok(Self { password, cipher, - db, + db: Arc::new(db), delayed_keys: Arc::new(Mutex::new(HashMap::new())), activity_index: Arc::new(RwLock::new(BTreeSet::new())), }) } } -fn ivec_to_string(vec: IVec) -> Result { - String::from_utf8(vec.to_vec()) - .map_err(|e| MutinyError::Other(anyhow!("Failed to decode value to string: {e}"))) -} - #[async_trait] -impl MutinyStorage for SledStorage { +impl MutinyStorage for RocksDB { fn password(&self) -> Option<&str> { self.password.as_deref() } @@ -71,16 +58,16 @@ impl MutinyStorage for SledStorage { } fn set(&self, items: Vec<(String, impl Serialize)>) -> Result<(), MutinyError> { - let mut batch = sled::Batch::default(); + let mut batch = WriteBatchWithTransaction::::default(); for (key, value) in items { let json = serde_json::to_string(&value).map_err(|e| { MutinyError::Other(anyhow!("Error serializing value: {e} for key: {key}")) })?; - batch.insert(key.as_str(), json.as_bytes()); + batch.put(key.as_bytes(), json.as_bytes()); } self.db - .apply_batch(batch) - .map_err(|e| MutinyError::Other(anyhow!("Error inserting keys: into sled: {e}")))?; + .write(batch) + .map_err(|e| MutinyError::Other(anyhow!("Error inserting keys to db: {e}")))?; Ok(()) } @@ -95,13 +82,12 @@ impl MutinyStorage for SledStorage { { let key = key.as_ref(); - if let Some(value) = self.db.get(key).map_err(|e| { - MutinyError::Other(anyhow!("Failed to read value ({key}) from sled db: {e}")) - })? { - // convert from bytes to deserialized value - let str = ivec_to_string(value)?; - let json: T = serde_json::from_str(&str)?; - + if let Some(value) = self + .db + .get(key) + .map_err(|e| MutinyError::Other(anyhow!("Failed to read value ({key}) from db: {e}")))? + { + let json: T = serde_json::from_slice(value.as_ref())?; return Ok(Some(json)); } @@ -110,15 +96,15 @@ impl MutinyStorage for SledStorage { fn delete(&self, keys: &[impl AsRef]) -> Result<(), MutinyError> { // start batch operation - let mut batch = sled::Batch::default(); + let mut batch = WriteBatchWithTransaction::::default(); for key in keys { - let key = key.as_ref(); - batch.remove(key); + batch.delete(key.as_ref()) } + // apply batch to delete all keys self.db - .apply_batch(batch) - .map_err(|e| MutinyError::Other(anyhow!("Error removing keys: from sled: {e}")))?; + .write(batch) + .map_err(|e| MutinyError::Other(anyhow!("Error removing keys from db: {e}")))?; Ok(()) } @@ -127,26 +113,25 @@ impl MutinyStorage for SledStorage { Ok(()) } - // TODO fn stop(&self) {} - // TODO fn connected(&self) -> Result { Ok(true) } fn scan_keys(&self, prefix: &str, suffix: Option<&str>) -> Result, MutinyError> { - Ok(self - .db - .iter() - .keys() - .filter_map(|key| key.ok()) - .map(ivec_to_string) - .filter_map(Result::ok) - .filter(|key| { - key.starts_with(prefix) && (suffix.is_none() || key.ends_with(suffix.unwrap())) - }) - .collect()) + let iter = self.db.iterator(IteratorMode::Start); + + let mut keys: Vec = vec![]; + for item in iter { + let (key, _) = + item.map_err(|e| MutinyError::Other(anyhow!("Error reading keys from db: {e}")))?; + let key = String::from_utf8(key.into_vec())?; + if key.starts_with(prefix) && (suffix.is_none() || key.ends_with(suffix.unwrap())) { + keys.push(key); + } + } + Ok(keys) } fn change_password( diff --git a/mutiny-server/src/routes.rs b/mutiny-server/src/routes.rs index 4931e7277..394f33b50 100644 --- a/mutiny-server/src/routes.rs +++ b/mutiny-server/src/routes.rs @@ -1,6 +1,6 @@ use crate::extractor::Form; -use crate::sled::SledStorage; +use crate::rocksdb::RocksDB; use axum::extract::Path; use axum::http::StatusCode; use axum::{Extension, Json}; @@ -16,7 +16,7 @@ use std::str::FromStr; #[derive(Clone)] pub struct State { - pub mutiny_wallet: MutinyWallet, + pub mutiny_wallet: MutinyWallet, } pub async fn new_address(