diff --git a/bindings/cashu-ffi/src/nuts/nut00/token.rs b/bindings/cashu-ffi/src/nuts/nut00/token.rs index 905349fc5..d66ba5622 100644 --- a/bindings/cashu-ffi/src/nuts/nut00/token.rs +++ b/bindings/cashu-ffi/src/nuts/nut00/token.rs @@ -59,7 +59,7 @@ impl Token { let mint = UncheckedUrl::from_str(&mint)?; let proofs = proofs.into_iter().map(|p| p.as_ref().into()).collect(); - let unit = unit.map(|u| CurrencyUnitSdk::from_str(&u).unwrap_or_default().into()); + let unit = unit.map(|u| CurrencyUnitSdk::from_str(&u).unwrap_or_default()); Ok(Self { inner: TokenSdk::new(mint, proofs, memo, unit)?, @@ -95,7 +95,7 @@ impl Token { impl fmt::Display for Token { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.inner.to_string()) + write!(f, "{}", self.inner) } } diff --git a/bindings/cashu-ffi/src/nuts/nut04/mod.rs b/bindings/cashu-ffi/src/nuts/nut04/mod.rs index 4aa1d0ac8..48cccd321 100644 --- a/bindings/cashu-ffi/src/nuts/nut04/mod.rs +++ b/bindings/cashu-ffi/src/nuts/nut04/mod.rs @@ -26,7 +26,7 @@ impl MintQuoteBolt11Request { pub fn new(amount: Arc, unit: String) -> Self { Self { inner: MintQuoteBolt11RequestSdk { - amount: amount.as_ref().deref().clone(), + amount: *amount.as_ref().deref(), unit: CurrencyUnit::from_str(&unit).unwrap(), }, } @@ -37,7 +37,7 @@ impl MintQuoteBolt11Request { } pub fn unit(&self) -> Arc { - Arc::new(self.inner.clone().unit.into()) + Arc::new(self.inner.clone().unit) } } diff --git a/bindings/cashu-ffi/src/types/bolt11_invoice.rs b/bindings/cashu-ffi/src/types/bolt11_invoice.rs index 9d48a2853..88840f530 100644 --- a/bindings/cashu-ffi/src/types/bolt11_invoice.rs +++ b/bindings/cashu-ffi/src/types/bolt11_invoice.rs @@ -38,6 +38,6 @@ impl Bolt11Invoice { pub fn amount(&self) -> Option> { self.inner .amount_milli_satoshis() - .map(|a| Arc::new(Amount::from(a / 1000).into())) + .map(|a| Arc::new(Amount::from(a / 1000))) } } diff --git a/bindings/cashu-ffi/src/types/melt_quote.rs b/bindings/cashu-ffi/src/types/melt_quote.rs index 052cbd99f..b70923219 100644 --- a/bindings/cashu-ffi/src/types/melt_quote.rs +++ b/bindings/cashu-ffi/src/types/melt_quote.rs @@ -37,10 +37,10 @@ impl MeltQuote { Self { inner: MeltQuoteSdk { id, - amount: amount.as_ref().deref().clone(), + amount: *amount.as_ref().deref(), unit: CurrencyUnit::from_str(&unit).unwrap(), request: request.as_ref().deref().clone(), - fee_reserve: fee_reserve.as_ref().deref().clone(), + fee_reserve: *fee_reserve.as_ref().deref(), paid, expiry, }, diff --git a/bindings/cashu-ffi/src/types/mint_quote.rs b/bindings/cashu-ffi/src/types/mint_quote.rs index 4d59b2e94..7a2a75900 100644 --- a/bindings/cashu-ffi/src/types/mint_quote.rs +++ b/bindings/cashu-ffi/src/types/mint_quote.rs @@ -36,7 +36,7 @@ impl MintQuote { Self { inner: MintQuoteSdk { id, - amount: amount.as_ref().deref().clone(), + amount: *amount.as_ref().deref(), unit: CurrencyUnit::from_str(&unit).unwrap(), request: request.as_ref().deref().clone(), paid, diff --git a/bindings/cashu-sdk-ffi/src/wallet.rs b/bindings/cashu-sdk-ffi/src/wallet.rs index 6e3464b07..cbcf95cbb 100644 --- a/bindings/cashu-sdk-ffi/src/wallet.rs +++ b/bindings/cashu-sdk-ffi/src/wallet.rs @@ -1,5 +1,5 @@ use std::ops::Deref; -use std::sync::{Arc, RwLock}; +use std::sync::Arc; use cashu_ffi::{ BlindedSignature, Bolt11Invoice, CurrencyUnit, MeltQuote, MintQuote, PreMintSecrets, Proof, @@ -11,6 +11,7 @@ use cashu_sdk::url::UncheckedUrl; use cashu_sdk::wallet::Wallet as WalletSdk; use once_cell::sync::Lazy; use tokio::runtime::Runtime; +use tokio::sync::Mutex; use crate::error::Result; use crate::types::{Melted, SendProofs}; @@ -19,7 +20,7 @@ use crate::{Amount, Keys}; static RUNTIME: Lazy = Lazy::new(|| Runtime::new().expect("Can't start Tokio runtime")); pub struct Wallet { - inner: RwLock>, + inner: Mutex>, } impl Wallet { @@ -51,8 +52,8 @@ impl Wallet { pub fn check_proofs_spent(&self, proofs: Vec>) -> Result> { let proofs = RUNTIME.block_on(async { self.inner - .read() - .unwrap() + .lock() + .await .check_proofs_spent(proofs.iter().map(|p| p.as_ref().deref().clone()).collect()) .await })?; @@ -68,8 +69,8 @@ impl Wallet { ) -> Result> { let token = RUNTIME.block_on(async { self.inner - .write() - .unwrap() + .lock() + .await .mint_token(*amount.as_ref().deref(), memo, unit.map(|u| u.into())) .await })?; @@ -80,8 +81,8 @@ impl Wallet { pub fn mint_quote(&self, amount: Arc, unit: CurrencyUnit) -> Result> { let quote = RUNTIME.block_on(async { self.inner - .write() - .unwrap() + .lock() + .await .mint_quote(*amount.as_ref().deref(), unit.into()) .await })?; @@ -90,14 +91,14 @@ impl Wallet { } pub fn mint(&self, quote: String) -> Result>> { - let proofs = RUNTIME.block_on(async { self.inner.write().unwrap().mint("e).await })?; + let proofs = RUNTIME.block_on(async { self.inner.lock().await.mint("e).await })?; Ok(proofs.into_iter().map(|p| Arc::new(p.into())).collect()) } pub fn receive(&self, encoded_token: String) -> Result>> { - let proofs = RUNTIME - .block_on(async { self.inner.write().unwrap().receive(&encoded_token).await })?; + let proofs = + RUNTIME.block_on(async { self.inner.lock().await.receive(&encoded_token).await })?; Ok(proofs.into_iter().map(|p| Arc::new(p.into())).collect()) } @@ -107,24 +108,20 @@ impl Wallet { blinded_messages: Arc, promises: Vec>, ) -> Result>> { - Ok(self - .inner - .read() - .unwrap() - .process_split_response( + let proofs = RUNTIME.block_on(async { + self.inner.lock().await.process_split_response( blinded_messages.as_ref().deref().clone(), promises.iter().map(|p| p.as_ref().into()).collect(), - )? - .into_iter() - .map(|p| Arc::new(p.into())) - .collect()) + ) + })?; + Ok(proofs.into_iter().map(|p| Arc::new(p.into())).collect()) } pub fn send(&self, amount: Arc, proofs: Vec>) -> Result> { let send_proofs = RUNTIME.block_on(async { self.inner - .read() - .unwrap() + .lock() + .await .send( *amount.as_ref().deref(), proofs.iter().map(|p| p.as_ref().deref().clone()).collect(), @@ -142,8 +139,8 @@ impl Wallet { ) -> Result> { let melt_quote = RUNTIME.block_on(async { self.inner - .write() - .unwrap() + .lock() + .await .melt_quote(unit.into(), request.as_ref().deref().clone()) .await })?; @@ -154,8 +151,8 @@ impl Wallet { pub fn melt(&self, quote_id: String, proofs: Vec>) -> Result> { let melted = RUNTIME.block_on(async { self.inner - .write() - .unwrap() + .lock() + .await .melt( "e_id, proofs.iter().map(|p| p.as_ref().deref().clone()).collect(), @@ -172,10 +169,12 @@ impl Wallet { unit: Option, memo: Option, ) -> Result { - Ok(self.inner.read().unwrap().proofs_to_token( - proofs.iter().map(|p| p.as_ref().deref().clone()).collect(), - memo, - unit.map(|u| u.into()), - )?) + Ok(RUNTIME.block_on(async { + self.inner.lock().await.proofs_to_token( + proofs.iter().map(|p| p.as_ref().deref().clone()).collect(), + memo, + unit.map(|u| u.into()), + ) + })?) } } diff --git a/bindings/cashu-sdk-js/src/mint.rs b/bindings/cashu-sdk-js/src/mint.rs index 86e1b4c54..dc380fbaf 100644 --- a/bindings/cashu-sdk-js/src/mint.rs +++ b/bindings/cashu-sdk-js/src/mint.rs @@ -65,8 +65,7 @@ impl JsMint { .inner .keyset(&keyset_id) .ok_or(JsError::new("Unknown Keyset"))? - .clone() - .into(); + .clone(); Ok(KeysResponse { keysets: vec![keyset],