From f5f108ff897557065987b1c853e4fbeeba25a161 Mon Sep 17 00:00:00 2001 From: Steffen <99717310+ngutech21@users.noreply.github.com> Date: Sat, 23 Mar 2024 08:52:08 +0100 Subject: [PATCH] chore: delete fedimint-crate (#260) --- .env.example | 3 - Cargo.lock | 38 ++-- Cargo.toml | 11 - README.md | 1 - moksha-fedimint/.cargo/config.toml | 3 - moksha-fedimint/Cargo.toml | 42 ---- moksha-fedimint/src/bin/fedimint-cli.rs | 31 --- moksha-fedimint/src/lib.rs | 256 ------------------------ 8 files changed, 19 insertions(+), 366 deletions(-) delete mode 100644 moksha-fedimint/.cargo/config.toml delete mode 100644 moksha-fedimint/Cargo.toml delete mode 100644 moksha-fedimint/src/bin/fedimint-cli.rs delete mode 100644 moksha-fedimint/src/lib.rs diff --git a/.env.example b/.env.example index e99f5580..7152c01a 100644 --- a/.env.example +++ b/.env.example @@ -79,6 +79,3 @@ MINT_LND_TLS_CERT_BASE64="base64 encoded tls cert" # (optional) enable tracing with open telemetry #MINT_TRACING_ENDPOINT="http://127.0.0.1:4318" - -### environment variables for the fedimint-cli -CLI_FEDIMINT_CONNECTION="fed...." \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 57208fa2..704d614b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,9 +273,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -476,9 +476,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" @@ -1144,7 +1144,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.2.5", + "indexmap 2.2.6", "slab", "tokio", "tokio-util", @@ -1163,7 +1163,7 @@ dependencies = [ "futures-sink", "futures-util", "http 1.1.0", - "indexmap 2.2.5", + "indexmap 2.2.6", "slab", "tokio", "tokio-util", @@ -1478,9 +1478,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.5" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown 0.14.3", @@ -1502,7 +1502,7 @@ dependencies = [ "moksha-mint", "moksha-wallet", "rand", - "reqwest 0.12.0", + "reqwest 0.12.1", "secp256k1 0.27.0", "serde", "tempfile", @@ -2161,7 +2161,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.2.5", + "indexmap 2.2.6", ] [[package]] @@ -2493,9 +2493,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", @@ -2579,9 +2579,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58b48d98d932f4ee75e541614d32a7f44c889b72bd9c2e04d95edd135989df88" +checksum = "e333b1eb9fe677f6893a9efcb0d277a2d3edd83f358a236b657c32301dc6e5f6" dependencies = [ "base64 0.21.7", "bytes", @@ -2955,7 +2955,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.2.5", + "indexmap 2.2.6", "serde", "serde_derive", "serde_json", @@ -3138,7 +3138,7 @@ dependencies = [ "futures-util", "hashlink", "hex", - "indexmap 2.2.5", + "indexmap 2.2.6", "log", "memchr", "once_cell", @@ -3420,9 +3420,9 @@ dependencies = [ [[package]] name = "testcontainers-modules" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0334776e1e8ee7c504a922c5236daf865ffe413aa630d84ae91dcce0b10bc3" +checksum = "204d1c7516bfdc8a01bb85d3e30145e5bbeb2351812e5e8aa6971769109b45b5" dependencies = [ "testcontainers", ] @@ -3979,7 +3979,7 @@ version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "272ebdfbc99111033031d2f10e018836056e4d2c8e2acda76450ec7974269fa7" dependencies = [ - "indexmap 2.2.5", + "indexmap 2.2.6", "serde", "serde_json", "utoipa-gen", diff --git a/Cargo.toml b/Cargo.toml index c19eb1f5..dde3288f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,18 +62,7 @@ activeperl = "*" [workspace.metadata.dist.github-custom-runners] x86_64-unknown-linux-gnu = "ubuntu-22.04" -#[patch.crates-io] -#secp256k1-zkp = { git = "https://github.com/dpc/rust-secp256k1-zkp/", branch = "sanket-pr" } -#ring = { git = "https://github.com/dpc/ring", rev = "5493e7e76d0d8fb1d3cbb0be9c4944700741b802" } - [profile.dev.package] -#secp256k1-zkp = { opt-level = 3 } -#bls12_381 = { opt-level = 3 } -#secp256k1-zkp-sys = { opt-level = 3 } -#fedimint-threshold-crypto = { opt-level = 3 } -#ff = { opt-level = 3 } -#group = { opt-level = 3 } -#pairing = { opt-level = 3 } secp256k1 = { opt-level = 3 } secp256k1-sys = { opt-level = 3 } bitcoin_hashes = { opt-level = 3 } diff --git a/README.md b/README.md index b8f6e529..1c711ddc 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,6 @@ Implemented [NUTs](https://github.com/cashubtc/nuts/): - [moksha-wallet](./moksha-wallet) Cashu wallet library - [moksha-cli](./moksha-wallet) Cashu cli wallet - [moksha-mint](./moksha-mint) Cashu mint server. Handles minting, melting and token requests. -- [moksha-fedimint](./moksha-fedimint) Fedimint wrapper for the cashu wallet - [integrationtests](./integrationtests) Spins up a mint and runs integration tests against it. ## Usage diff --git a/moksha-fedimint/.cargo/config.toml b/moksha-fedimint/.cargo/config.toml deleted file mode 100644 index 0e3c92f5..00000000 --- a/moksha-fedimint/.cargo/config.toml +++ /dev/null @@ -1,3 +0,0 @@ -# this is needed by fedimint since v 0.2.0 -[build] -rustflags = ["--cfg", "tokio_unstable"] diff --git a/moksha-fedimint/Cargo.toml b/moksha-fedimint/Cargo.toml deleted file mode 100644 index 85da8931..00000000 --- a/moksha-fedimint/Cargo.toml +++ /dev/null @@ -1,42 +0,0 @@ -[package] -name = "moksha-fedimint" -version = "0.2.1" -edition = "2021" -repository = "https://github.com/ngutech21/moksha" -license = "MIT" -description = "A fedimint client for moksha" -publish = false - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[lib] -name = "moksha_fedimint" -path = "src/lib.rs" - -[package.metadata.docs.rs] -rustc-args = ["--cfg", "tokio_unstable"] - -[dependencies] -dotenvy = "0.15.7" -base64 = "0.21.5" -anyhow = { version = "1.0.75", features = ["backtrace"] } -serde_json = "1.0.108" -lightning-invoice = { version = "0.21.0", features = ["serde"] } -fedimint-client = { git = "https://github.com/fedimint/fedimint", tag = "v0.1.5" } -fedimint-core = { git = "https://github.com/fedimint/fedimint", tag = "v0.1.5" } -fedimint-mint-client = { git = "https://github.com/fedimint/fedimint", tag = "v0.1.5" } -fedimint-ln-client = { git = "https://github.com/fedimint/fedimint", tag = "v0.1.5" } -fedimint-wallet-client = { git = "https://github.com/fedimint/fedimint", tag = "v0.1.5" } -futures = "0.3.29" - -[target.'cfg(not(target_family="wasm"))'.dependencies] -tokio = { version = "1.35.0", features = ["rt", "tracing"] } -fedimint-rocksdb = { git = "https://github.com/fedimint/fedimint", tag = "v0.1.5" } - -[target.'cfg(target_family = "wasm")'.dependencies] -wasm-bindgen-futures = "0.4" -# getrandom is transitive dependency of rand -# on wasm, we need to enable the js backend -# see https://docs.rs/getrandom/latest/getrandom/#indirect-dependencies and https://docs.rs/getrandom/latest/getrandom/#webassembly-support -getrandom = { version = "0.2.11", features = ["js"] } -ring = { version = "0.16.20", features = ["wasm32_unknown_unknown_js", "wasm32_c"] } diff --git a/moksha-fedimint/src/bin/fedimint-cli.rs b/moksha-fedimint/src/bin/fedimint-cli.rs deleted file mode 100644 index df5eb34f..00000000 --- a/moksha-fedimint/src/bin/fedimint-cli.rs +++ /dev/null @@ -1,31 +0,0 @@ -#[cfg(not(target_arch = "wasm32"))] -#[tokio::main] -async fn main() -> anyhow::Result<()> { - dotenvy::dotenv().ok(); - - let connection = std::env::var("CLI_FEDIMINT_CONNECTION")?; - let workdir = workdir()?; - if !moksha_fedimint::FedimintWallet::is_initialized(&workdir) { - moksha_fedimint::FedimintWallet::connect(workdir.clone(), &connection).await?; - } - - let wallet = moksha_fedimint::FedimintWallet::new(workdir.clone()).await?; - println!("Wallet is initialized"); - let balance = wallet.balance().await?; - println!("Balance: {}", balance); - - let (operation_id, invoice) = wallet.get_mint_payment_request(1_000).await?; - println!("Invoice: \n{}", invoice); - wallet.mint(operation_id).await?; - Ok(()) -} - -#[cfg(target_arch = "wasm32")] -fn main() {} - -#[cfg(not(target_arch = "wasm32"))] -fn workdir() -> anyhow::Result { - use std::str::FromStr; - let base_dir = std::env::var("CARGO_MANIFEST_DIR")?; - std::path::PathBuf::from_str(&format!("{base_dir}/data")).map_err(|e| anyhow::anyhow!(e)) -} diff --git a/moksha-fedimint/src/lib.rs b/moksha-fedimint/src/lib.rs deleted file mode 100644 index 38855ebc..00000000 --- a/moksha-fedimint/src/lib.rs +++ /dev/null @@ -1,256 +0,0 @@ -use anyhow::Result; - -use fedimint_client::module::init::{ClientModuleInitRegistry, IClientModuleInit}; -use fedimint_client::secret::PlainRootSecretStrategy; -use fedimint_client::sm::OperationId; -use fedimint_client::ClientBuilder; -use fedimint_core::api::{GlobalFederationApi, InviteCode}; -use fedimint_core::encoding::Encodable; -use fedimint_core::module::registry::ModuleDecoderRegistry; -use fedimint_core::{ - api::{IGlobalFederationApi, WsFederationApi}, - config::ClientConfig, -}; -use fedimint_core::{Amount, TieredMulti}; -use fedimint_ln_client::{ - LightningClientExt, LightningClientGen, LnPayState, LnReceiveState, PayType, -}; -use fedimint_mint_client::{ - MintClientExt, MintClientGen, MintClientModule, OOBNotes, SpendableNote, -}; -use fedimint_wallet_client::WalletClientGen; -use lightning_invoice::Invoice; -use std::fs::create_dir_all; -use std::fs::File; -use std::path::{Path, PathBuf}; -use std::time::Duration; -use std::{str::FromStr, sync::Arc}; - -use futures::StreamExt; - -const CLIENT_CFG: &str = "client.json"; - -#[derive(Clone)] -pub struct FedimintWallet { - client: fedimint_client::Client, -} - -impl FedimintWallet { - pub async fn new(workdir: PathBuf) -> anyhow::Result { - Ok(Self { - client: Self::create_client(&workdir).await?, - }) - } - - pub async fn connect(workdir: PathBuf, connect: &str) -> anyhow::Result<()> { - let connect_obj = InviteCode::from_str(connect)?; - let api = Arc::new(WsFederationApi::from_invite_code(&[connect_obj.clone()])) - as Arc; - let cfg: ClientConfig = api.download_client_config(&connect_obj).await?; - create_dir_all(workdir.clone())?; - let cfg_path = workdir.join(CLIENT_CFG); - let writer = File::options() - .create_new(true) - .write(true) - .open(cfg_path)?; - serde_json::to_writer_pretty(writer, &cfg)?; - Ok(()) - } - - pub async fn get_mint_payment_request(&self, amount: u64) -> anyhow::Result<(String, Invoice)> { - self.client.select_active_gateway().await?; - - let (operation_id, invoice) = self - .client - .create_bolt11_invoice(Amount::from_sats(amount), "test".to_owned(), None) - .await?; - Ok((operation_id.to_string(), invoice)) - } - - pub async fn pay_ln_invoice(&self, invoice: String) -> anyhow::Result { - self.client.select_active_gateway().await?; - - let ln_invoice = Invoice::from_str(&invoice)?; - - let (pay_types, _) = self.client.pay_bolt11_invoice(ln_invoice).await?; - let PayType::Lightning(operation_id) = pay_types else { - unreachable!("paying invoice over lightning"); - }; - let mut updates = self - .client - .subscribe_ln_pay(operation_id) - .await? - .into_stream(); - - loop { - match updates.next().await { - // FIXME return enum - Some(LnPayState::Success { preimage: _ }) => { - return Ok(true); - } - Some(LnPayState::Refunded { gateway_error }) => { - return Err(anyhow::anyhow!("refunded {gateway_error}")); - } - None => return Err(anyhow::anyhow!("Lightning send failed")), - _ => {} - } - } - } - - pub async fn receive_token(&self, tokens: String) -> anyhow::Result { - let notes: OOBNotes = OOBNotes::from_str(&tokens)?; - - let total_amount = notes.total_amount().msats / 1_000; - - let operation_id = self.client.reissue_external_notes(notes, ()).await?; - let mut updates = self - .client - .subscribe_reissue_external_notes(operation_id) - .await - .unwrap() - .into_stream(); - - while let Some(update) = updates.next().await { - if let fedimint_mint_client::ReissueExternalNotesState::Failed(e) = update { - return Err(anyhow::Error::msg(format!("Reissue failed: {e}"))); - } - } - Ok(total_amount) - } - - pub fn serialize_ecash(c: &TieredMulti) -> String { - let mut bytes = Vec::new(); - Encodable::consensus_encode(c, &mut bytes).expect("encodes correctly"); - use base64::{engine::general_purpose, Engine as _}; - general_purpose::STANDARD.encode(&bytes) - } - - pub async fn send_tokens( - &self, - min_amount: u64, - try_cancel_after: Duration, - ) -> anyhow::Result { - let (_, notes) = self - .client - .spend_notes(Amount::from_sats(min_amount), try_cancel_after, ()) - .await?; - Ok(notes.to_string()) - } - - pub async fn mint(&self, operation_id: String) -> anyhow::Result<()> { - self.client.select_active_gateway().await?; - - let mut updates = self - .client - .subscribe_ln_receive(OperationId::from_str(&operation_id)?) - .await? - .into_stream(); - while let Some(update) = updates.next().await { - match update { - LnReceiveState::Claimed => { - return Ok(()); - } - LnReceiveState::Canceled { reason } => { - return Err(reason.into()); - } - _ => {} - } - } - Err(anyhow::anyhow!("Something went wrong")) - } - - pub async fn balance(&self) -> anyhow::Result { - let (mint_client, _) = self - .client - .get_first_module::(&fedimint_mint_client::KIND); - let summary = mint_client - .get_wallet_summary( - &mut self - .client - .db() - .begin_transaction() - .await - .with_module_prefix(1), - ) - .await; - Ok(summary.total_amount().msats / 1_000) - } - - async fn create_client(workdir: &Path) -> Result { - let mut registry = ClientModuleInitRegistry::new(); - registry.attach(LightningClientGen); - registry.attach(MintClientGen); - registry.attach(WalletClientGen::default()); - - let client = Self::build_client_ng(®istry, None, workdir).await?; - let config = client.get_config().clone(); - Self::load_decoders(&config, ®istry); - - Ok(client) - } - - async fn build_client_ng( - module_inits: &ClientModuleInitRegistry, - invite_code: Option, - workdir: &Path, - ) -> anyhow::Result { - let client_builder = - Self::build_client_ng_builder(module_inits, invite_code, workdir).await?; - client_builder.build::().await - } - - async fn build_client_ng_builder( - module_inits: &ClientModuleInitRegistry, - invite_code: Option, - _workdir: &Path, - ) -> anyhow::Result { - #[cfg(not(target_arch = "wasm32"))] - let db = Self::load_db(_workdir)?; - - #[cfg(target_arch = "wasm32")] - let db = fedimint_core::db::mem_impl::MemDatabase::default(); - - let mut client_builder = ClientBuilder::default(); - client_builder.with_module_inits(module_inits.clone()); - client_builder.with_primary_module(1); - if let Some(invite_code) = invite_code { - client_builder.with_invite_code(invite_code); - } - client_builder.with_database(db); - - Ok(client_builder) - } - - // FIXME: this is a hack - pub fn is_initialized(workdir: &Path) -> bool { - workdir.join(CLIENT_CFG).exists() - } - - #[cfg(not(target_arch = "wasm32"))] - fn load_db(workdir: &Path) -> anyhow::Result { - let db_path = workdir.join("client.db"); - println!("DB path: {:?}", db_path); - fedimint_rocksdb::RocksDb::open(db_path.to_str().unwrap()).map_err(anyhow::Error::new) - } - - fn load_decoders( - cfg: &ClientConfig, - module_inits: &ClientModuleInitRegistry, - ) -> ModuleDecoderRegistry { - ModuleDecoderRegistry::new(cfg.clone().modules.into_iter().filter_map( - |(id, module_cfg)| { - let kind = module_cfg.kind().clone(); - module_inits.get(&kind).map(|module_init| { - ( - id, - kind, - IClientModuleInit::decoder( - AsRef::::as_ref(module_init), - ), - ) - }) - }, - )) - .with_fallback() - } -}