Просмотр исходного кода

Add MultiMintWallet function to check proofs state (#1374)

David Caseria 2 месяцев назад
Родитель
Сommit
64d575d5c7
2 измененных файлов с 34 добавлено и 1 удалено
  1. 19 0
      crates/cdk-ffi/src/multi_mint_wallet.rs
  2. 15 1
      crates/cdk/src/wallet/multi_mint_wallet.rs

+ 19 - 0
crates/cdk-ffi/src/multi_mint_wallet.rs

@@ -248,6 +248,25 @@ impl MultiMintWallet {
         Ok(proofs_by_mint)
     }
 
+    /// Check the state of proofs at a specific mint
+    pub async fn check_proofs_state(
+        &self,
+        mint_url: MintUrl,
+        proofs: Proofs,
+    ) -> Result<Vec<ProofState>, FfiError> {
+        let cdk_mint_url: cdk::mint_url::MintUrl = mint_url.try_into()?;
+        let cdk_proofs: Result<Vec<cdk::nuts::Proof>, _> =
+            proofs.into_iter().map(|p| p.try_into()).collect();
+        let cdk_proofs = cdk_proofs?;
+
+        let states = self
+            .inner
+            .check_proofs_state(&cdk_mint_url, cdk_proofs)
+            .await?;
+
+        Ok(states.into_iter().map(|s| s.into()).collect())
+    }
+
     /// Receive token
     pub async fn receive(
         &self,

+ 15 - 1
crates/cdk/src/wallet/multi_mint_wallet.rs

@@ -25,7 +25,7 @@ use crate::amount::SplitTarget;
 use crate::mint_url::MintUrl;
 use crate::nuts::nut00::ProofsMethods;
 use crate::nuts::nut23::QuoteState;
-use crate::nuts::{CurrencyUnit, MeltOptions, Proof, Proofs, SpendingConditions, Token};
+use crate::nuts::{CurrencyUnit, MeltOptions, Proof, Proofs, SpendingConditions, State, Token};
 use crate::types::Melted;
 #[cfg(all(feature = "tor", not(target_arch = "wasm32")))]
 use crate::wallet::mint_connector::transport::tor_transport::TorAsync;
@@ -616,6 +616,20 @@ impl MultiMintWallet {
         Ok(mint_proofs)
     }
 
+    /// NUT-07 Check the state of proofs with a specific mint
+    #[instrument(skip(self, proofs))]
+    pub async fn check_proofs_state(
+        &self,
+        mint_url: &MintUrl,
+        proofs: Proofs,
+    ) -> Result<Vec<State>, Error> {
+        let wallet = self.get_wallet(mint_url).await.ok_or(Error::UnknownMint {
+            mint_url: mint_url.to_string(),
+        })?;
+        let states = wallet.check_proofs_spent(proofs).await?;
+        Ok(states.into_iter().map(|s| s.state).collect())
+    }
+
     /// List transactions
     #[instrument(skip(self))]
     pub async fn list_transactions(