فهرست منبع

refactor: removed unneeded structs from nut07 state change

thesimplekid 1 سال پیش
والد
کامیت
7006594933

+ 1 - 2
crates/cashu-sdk/src/client/minreq_client.rs

@@ -1,7 +1,5 @@
 //! Minreq http Client
 
-use std::println;
-
 use async_trait::async_trait;
 use cashu::nuts::{
     BlindedMessage, CurrencyUnit, KeySet, KeysResponse, KeysetResponse, MeltBolt11Request,
@@ -11,6 +9,7 @@ use cashu::nuts::{
 };
 #[cfg(feature = "nut07")]
 use cashu::nuts::{CheckStateRequest, CheckStateResponse};
+#[cfg(feature = "nut07")]
 use cashu::secret::Secret;
 use cashu::{Amount, Bolt11Invoice};
 use serde_json::Value;

+ 1 - 0
crates/cashu-sdk/src/client/mod.rs

@@ -8,6 +8,7 @@ use cashu::nuts::{
     MeltQuoteBolt11Response, MintBolt11Response, MintInfo, MintQuoteBolt11Response, PreMintSecrets,
     Proof, SwapRequest, SwapResponse,
 };
+#[cfg(feature = "nut07")]
 use cashu::secret::Secret;
 use cashu::{utils, Amount};
 use serde::{Deserialize, Serialize};

+ 3 - 17
crates/cashu-sdk/src/mint/mod.rs

@@ -2,7 +2,7 @@ use std::collections::HashSet;
 
 use cashu::dhke::{sign_message, verify_message};
 #[cfg(feature = "nut07")]
-use cashu::nuts::nut07::State;
+use cashu::nuts::nut07::{ProofState, State};
 use cashu::nuts::{
     BlindedMessage, BlindedSignature, MeltBolt11Request, MeltBolt11Response, Proof, SwapRequest,
     SwapResponse, *,
@@ -373,26 +373,12 @@ impl<L: LocalStore> Mint<L> {
         &self,
         check_spendable: &CheckStateRequest,
     ) -> Result<CheckStateResponse, Error> {
-        use cashu::nuts::nut07::ProofState;
-
         let mut states = Vec::with_capacity(check_spendable.secrets.len());
 
         for secret in &check_spendable.secrets {
-            let state = if self
-                .localstore
-                .get_spent_proof(secret)
-                .await
-                .unwrap()
-                .is_some()
-            {
+            let state = if self.localstore.get_spent_proof(secret).await?.is_some() {
                 State::Spent
-            } else if self
-                .localstore
-                .get_pending_proof(secret)
-                .await
-                .unwrap()
-                .is_some()
-            {
+            } else if self.localstore.get_pending_proof(secret).await?.is_some() {
                 State::Pending
             } else {
                 State::Unspent

+ 0 - 58
crates/cashu/src/nuts/nut00.rs

@@ -428,64 +428,6 @@ impl PartialOrd for Proof {
     }
 }
 
-impl From<Proof> for mint::Proof {
-    fn from(proof: Proof) -> Self {
-        Self {
-            amount: Some(proof.amount),
-            secret: proof.secret,
-            c: Some(proof.c),
-            keyset_id: Some(proof.keyset_id),
-        }
-    }
-}
-
-impl TryFrom<mint::Proof> for Proof {
-    type Error = Error;
-
-    fn try_from(mint_proof: mint::Proof) -> Result<Proof, Self::Error> {
-        Ok(Self {
-            keyset_id: mint_proof.keyset_id.ok_or(Error::MissingProofField)?,
-            amount: mint_proof.amount.ok_or(Error::MissingProofField)?,
-            secret: mint_proof.secret,
-            c: mint_proof.c.ok_or(Error::MissingProofField)?,
-        })
-    }
-}
-
-pub mod mint {
-    use serde::{Deserialize, Serialize};
-
-    use super::PublicKey;
-    use crate::nuts::nut02::Id;
-    use crate::secret::Secret;
-    use crate::Amount;
-
-    /// Proofs [NUT-00]
-    #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-    pub struct Proof {
-        /// Amount in satoshi
-        #[serde(skip_serializing)]
-        pub amount: Option<Amount>,
-        /// Secret message
-        #[serde(skip_serializing)]
-        pub secret: Secret,
-        /// Unblinded signature
-        #[serde(rename = "C")]
-        pub c: Option<PublicKey>,
-        /// `Keyset id`
-        #[serde(skip_serializing)]
-        #[serde(rename = "id")]
-        pub keyset_id: Option<Id>,
-    }
-
-    /// List of proofs
-    pub type Proofs = Vec<Proof>;
-
-    pub fn mint_proofs_from_proofs(proofs: crate::nuts::Proofs) -> Proofs {
-        proofs.iter().map(|p| p.to_owned().into()).collect()
-    }
-}
-
 #[cfg(test)]
 mod tests {
     use std::str::FromStr;