Przeglądaj źródła

Mmw list mint info (#1430)

* feat: get mint infos for mmw
tsk 4 tygodni temu
rodzic
commit
bca50ceb91

+ 5 - 0
CHANGELOG.md

@@ -5,6 +5,11 @@
 <!-- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -->
 
 
+## [Unreleased]
+
+### Added
+- cdk: Add `get_all_mint_info` to MultiMintWallet ([thesimplekid]).
+
 ## [0.14.0](https://github.com/cashubtc/cdk/releases/tag/v0.14.0)
 
 ### Summary

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

@@ -663,6 +663,22 @@ impl MultiMintWallet {
         let mint_info = self.inner.fetch_mint_info(&cdk_mint_url).await?;
         Ok(mint_info.map(Into::into))
     }
+
+    /// Get mint info for all wallets
+    ///
+    /// This method loads the mint info for each wallet in the MultiMintWallet
+    /// and returns a map of mint URLs to their corresponding mint info.
+    ///
+    /// Uses cached mint info when available, only fetching from the mint if the cache
+    /// has expired.
+    pub async fn get_all_mint_info(&self) -> Result<MintInfoMap, FfiError> {
+        let mint_infos = self.inner.get_all_mint_info().await?;
+        let mut result = HashMap::new();
+        for (mint_url, mint_info) in mint_infos {
+            result.insert(mint_url.to_string(), mint_info.into());
+        }
+        Ok(result)
+    }
 }
 
 /// Payment request methods for MultiMintWallet
@@ -938,3 +954,6 @@ pub type BalanceMap = HashMap<String, Amount>;
 
 /// Type alias for proofs by mint URL
 pub type ProofsByMint = HashMap<String, Vec<Proof>>;
+
+/// Type alias for mint info by mint URL
+pub type MintInfoMap = HashMap<String, MintInfo>;

+ 2 - 2
crates/cdk-ffi/src/wallet.rs

@@ -111,8 +111,8 @@ impl Wallet {
         Ok(balance.into())
     }
 
-    /// Get mint info
-    pub async fn get_mint_info(&self) -> Result<Option<MintInfo>, FfiError> {
+    /// Get mint info from mint
+    pub async fn fetch_mint_info(&self) -> Result<Option<MintInfo>, FfiError> {
         let info = self.inner.fetch_mint_info().await?;
         Ok(info.map(Into::into))
     }

+ 21 - 0
crates/cdk/src/wallet/multi_mint_wallet.rs

@@ -1842,6 +1842,27 @@ impl MultiMintWallet {
         wallet.fetch_mint_info().await
     }
 
+    /// Get mint info for all wallets
+    ///
+    /// This method loads the mint info for each wallet in the MultiMintWallet
+    /// and returns a map of mint URLs to their corresponding mint info.
+    ///
+    /// Uses cached mint info when available, only fetching from the mint if the cache
+    /// has expired.
+    #[instrument(skip(self))]
+    pub async fn get_all_mint_info(
+        &self,
+    ) -> Result<BTreeMap<MintUrl, crate::nuts::MintInfo>, Error> {
+        let mut mint_infos = BTreeMap::new();
+
+        for (mint_url, wallet) in self.wallets.read().await.iter() {
+            let mint_info = wallet.load_mint_info().await?;
+            mint_infos.insert(mint_url.clone(), mint_info);
+        }
+
+        Ok(mint_infos)
+    }
+
     /// Melt Quote for BIP353 human-readable address
     ///
     /// This method resolves a BIP353 address (e.g., "alice@example.com") to a Lightning offer