Browse Source

feat: unreserve proofs

thesimplekid 8 months ago
parent
commit
bf9b4dfe54
1 changed files with 26 additions and 0 deletions
  1. 26 0
      crates/cdk/src/wallet/mod.rs

+ 26 - 0
crates/cdk/src/wallet/mod.rs

@@ -137,6 +137,32 @@ impl Wallet {
             .map(|p| p.into_iter().map(|p| p.proof).collect()))
     }
 
+    /// Get reserved [`Proofs`]
+    #[instrument(skip(self))]
+    pub async fn get_reserved_proofs(&self) -> Result<Proofs, Error> {
+        Ok(self
+            .localstore
+            .get_proofs(
+                Some(self.mint_url.clone()),
+                Some(self.unit.clone()),
+                Some(vec![State::Reserved]),
+                None,
+            )
+            .await?
+            .map(|p| p.into_iter().map(|p| p.proof).collect())
+            .unwrap_or_default())
+    }
+
+    /// Return proofs to unspent allowing them to be selected and spent
+    #[instrument(skip(self))]
+    pub async fn unreserve_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Error> {
+        for y in ys {
+            self.localstore.set_proof_state(y, State::Unspent).await?;
+        }
+
+        Ok(())
+    }
+
     /// Add mint to wallet
     #[instrument(skip(self))]
     pub async fn get_mint_info(&self) -> Result<Option<MintInfo>, Error> {