소스 검색

feat: cdk-ffi get wallets (#1333)

tsk 2 달 전
부모
커밋
96e2282bce
2개의 변경된 파일25개의 추가작업 그리고 0개의 파일을 삭제
  1. 18 0
      crates/cdk-ffi/src/multi_mint_wallet.rs
  2. 7 0
      crates/cdk-ffi/src/wallet.rs

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

@@ -516,6 +516,24 @@ impl MultiMintWallet {
         wallets.iter().map(|w| w.mint_url.to_string()).collect()
     }
 
+    /// Get all wallets from MultiMintWallet
+    pub async fn get_wallets(&self) -> Vec<Arc<crate::wallet::Wallet>> {
+        let wallets = self.inner.get_wallets().await;
+        wallets
+            .into_iter()
+            .map(|w| Arc::new(crate::wallet::Wallet::from_inner(Arc::new(w))))
+            .collect()
+    }
+
+    /// Get a specific wallet from MultiMintWallet by mint URL
+    pub async fn get_wallet(&self, mint_url: MintUrl) -> Option<Arc<crate::wallet::Wallet>> {
+        let cdk_mint_url: cdk::mint_url::MintUrl = mint_url.try_into().ok()?;
+        let wallet = self.inner.get_wallet(&cdk_mint_url).await?;
+        Some(Arc::new(crate::wallet::Wallet::from_inner(Arc::new(
+            wallet,
+        ))))
+    }
+
     /// Verify token DLEQ proofs
     pub async fn verify_token_dleq(&self, token: Arc<Token>) -> Result<(), FfiError> {
         let cdk_token = token.inner.clone();

+ 7 - 0
crates/cdk-ffi/src/wallet.rs

@@ -16,6 +16,13 @@ pub struct Wallet {
     inner: Arc<CdkWallet>,
 }
 
+impl Wallet {
+    /// Create a Wallet from an existing CDK wallet (internal use only)
+    pub(crate) fn from_inner(inner: Arc<CdkWallet>) -> Self {
+        Self { inner }
+    }
+}
+
 #[uniffi::export(async_runtime = "tokio")]
 impl Wallet {
     /// Create a new Wallet from mnemonic using WalletDatabase trait