Browse Source

chore: clippy

thesimplekid 1 year ago
parent
commit
c21f059101

+ 2 - 1
Cargo.toml

@@ -29,4 +29,5 @@ url = "2.3.1"
 tokio = { version = "1", default-features = false }
 tracing = "0.1"
 tracing-subscriber = "0.3"
-uniffi = "0.24"
+uniffi = "0.24"
+

+ 1 - 1
bindings/cashu-ffi/src/error.rs

@@ -52,7 +52,7 @@ impl From<ParseOrSemanticError> for CashuError {
 impl From<cashu::nuts::nut02::Error> for CashuError {
     fn from(err: cashu::nuts::nut02::Error) -> Self {
         Self::Generic {
-            err: "Nut 2 error".to_string(),
+            err: err.to_string(),
         }
     }
 }

+ 1 - 1
bindings/cashu-ffi/src/nuts/nut00/blinded_signature.rs

@@ -23,7 +23,7 @@ impl BlindedSignature {
     }
 
     pub fn id(&self) -> Arc<Id> {
-        Arc::new(self.inner.id.clone().into())
+        Arc::new(self.inner.id.into())
     }
 
     pub fn amount(&self) -> Arc<Amount> {

+ 5 - 5
bindings/cashu-ffi/src/nuts/nut00/proof.rs

@@ -27,7 +27,7 @@ impl Proof {
                 amount: *amount.as_ref().deref(),
                 secret: secret.as_ref().deref().clone(),
                 c: c.as_ref().deref().clone(),
-                id: id.map(|id| id.as_ref().deref().clone()),
+                id: id.map(|id| *id.as_ref().deref()),
             },
         }
     }
@@ -45,7 +45,7 @@ impl Proof {
     }
 
     pub fn id(&self) -> Option<Arc<Id>> {
-        self.inner.id.clone().map(|id| Arc::new(id.into()))
+        self.inner.id.map(|id| Arc::new(id.into()))
     }
 }
 
@@ -55,7 +55,7 @@ impl From<&Proof> for ProofSdk {
             amount: *proof.amount().as_ref().deref(),
             secret: proof.secret().as_ref().deref().clone(),
             c: proof.c().deref().into(),
-            id: proof.id().map(|id| id.as_ref().deref().clone()),
+            id: proof.id().map(|id| *id.as_ref().deref()),
         }
     }
 }
@@ -100,7 +100,7 @@ pub mod mint {
                     amount: amount.map(|a| *a.as_ref().deref()),
                     secret: secret.as_ref().deref().clone(),
                     c: c.map(|c| c.as_ref().into()),
-                    id: id.map(|id| id.as_ref().deref().clone()),
+                    id: id.map(|id| *id.as_ref().deref()),
                 },
             }
         }
@@ -118,7 +118,7 @@ pub mod mint {
         }
 
         pub fn id(&self) -> Option<Arc<Id>> {
-            self.inner.id.clone().map(|id| Arc::new(id.into()))
+            self.inner.id.map(|id| Arc::new(id.into()))
         }
     }
 

+ 2 - 2
bindings/cashu-ffi/src/nuts/nut02/key_set.rs

@@ -53,14 +53,14 @@ impl KeySet {
     pub fn new(id: Arc<Id>, keys: Arc<Keys>) -> Self {
         Self {
             inner: KeySetSdk {
-                id: id.as_ref().deref().clone(),
+                id: *id.as_ref().deref(),
                 keys: keys.as_ref().deref().clone(),
             },
         }
     }
 
     pub fn id(&self) -> Arc<Id> {
-        Arc::new(self.inner.id.clone().into())
+        Arc::new(self.inner.id.into())
     }
 
     pub fn keys(&self) -> Arc<Keys> {

+ 6 - 0
bindings/cashu-ffi/src/types/secret.rs

@@ -13,6 +13,12 @@ impl Deref for Secret {
     }
 }
 
+impl Default for Secret {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Secret {
     pub fn new() -> Self {
         Self {

+ 1 - 1
bindings/cashu-sdk-ffi/src/lib.rs

@@ -17,7 +17,7 @@ mod ffi {
     pub use crate::client::Client;
     pub use crate::error::CashuSdkError;
     pub use crate::mint::Mint;
-    pub use crate::types::{FeeReserve, Melted, ProofsStatus, SendProofs};
+    pub use crate::types::{Melted, ProofsStatus, SendProofs};
     pub use crate::wallet::Wallet;
 
     // UDL

+ 5 - 8
bindings/cashu-sdk-ffi/src/mint.rs

@@ -4,17 +4,14 @@ use std::{
     sync::{Arc, RwLock},
 };
 
-use cashu_sdk::mint::Mint as MintSdk;
-
-use cashu_sdk::nuts::nut02::Id as IdSdk;
-use fee_reserve::FeeReserve;
-
-use crate::{error::Result, types::fee_reserve};
 use cashu_ffi::{
     Amount, CheckSpendableRequest, CheckSpendableResponse, Id, KeySet, KeySetResponse, MeltRequest,
-    MeltResponse, MintKeySet, MintRequest, PostMintResponse, Proof, Secret, SplitRequest,
-    SplitResponse,
+    MeltResponse, MintKeySet, MintRequest, PostMintResponse, Secret, SplitRequest, SplitResponse,
 };
+use cashu_sdk::mint::Mint as MintSdk;
+use cashu_sdk::nuts::nut02::Id as IdSdk;
+
+use crate::error::Result;
 
 pub struct Mint {
     inner: RwLock<MintSdk>,

+ 0 - 19
bindings/cashu-sdk-ffi/src/types/fee_reserve.rs

@@ -1,19 +0,0 @@
-use std::{ops::Deref, sync::Arc};
-
-use cashu_ffi::Amount;
-use cashu_sdk::mint::FeeReserve as FeeReserveSdk;
-
-pub struct FeeReserve {
-    inner: FeeReserveSdk,
-}
-
-impl FeeReserve {
-    pub fn new(min_fee_reserve: Arc<Amount>, percent_fee_reserve: f32) -> Self {
-        Self {
-            inner: FeeReserveSdk {
-                min_fee_reserve: *min_fee_reserve.as_ref().deref(),
-                percent_fee_reserve,
-            },
-        }
-    }
-}

+ 0 - 2
bindings/cashu-sdk-ffi/src/types/mod.rs

@@ -1,9 +1,7 @@
-pub mod fee_reserve;
 pub mod melted;
 pub mod proofs_status;
 pub mod send_proofs;
 
-pub use fee_reserve::FeeReserve;
 pub use melted::Melted;
 pub use proofs_status::ProofsStatus;
 pub use send_proofs::SendProofs;

+ 10 - 0
crates/cashu/src/nuts/nut02.rs

@@ -2,6 +2,7 @@
 // https://github.com/cashubtc/nuts/blob/main/02.md
 
 use std::collections::HashSet;
+use std::fmt;
 
 use base64::{engine::general_purpose, Engine as _};
 use bitcoin::hashes::sha256;
@@ -17,6 +18,15 @@ pub enum Error {
     Length,
 }
 
+impl fmt::Display for Error {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match self {
+            Self::Length => write!(f, "NUT02: Id invalid length"),
+            Self::Base64(err) => write!(f, "NUT02: {:?}", err),
+        }
+    }
+}
+
 /// A keyset ID is an identifier for a specific keyset. It can be derived by
 /// anyone who knows the set of public keys of a mint. The keyset ID **CAN**
 /// be stored in a Cashu token such that the token can be used to identify