Forráskód Böngészése

fix: ffi get_balances returns WalletKey (#1630)

tsk 3 hete
szülő
commit
f18db60770

+ 1 - 1
crates/cdk-ffi/src/types/amount.rs

@@ -91,7 +91,7 @@ impl From<Amount> for CdkAmount {
 }
 
 /// FFI-compatible Currency Unit
-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, uniffi::Enum)]
+#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, uniffi::Enum)]
 pub enum CurrencyUnit {
     Sat,
     Msat,

+ 30 - 0
crates/cdk-ffi/src/types/wallet.rs

@@ -8,6 +8,7 @@ use super::amount::{Amount, SplitTarget};
 use super::proof::{Proofs, SpendingConditions};
 use crate::error::FfiError;
 use crate::token::Token;
+use crate::{CurrencyUnit, MintUrl};
 
 /// FFI-compatible SendMemo
 #[derive(Debug, Clone, Serialize, Deserialize, uniffi::Record)]
@@ -683,3 +684,32 @@ impl From<cdk::wallet::MeltConfirmOptions> for MeltConfirmOptions {
         }
     }
 }
+
+/// FFI-compatible WalletKey
+#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, uniffi::Record)]
+pub struct WalletKey {
+    /// Mint Url
+    pub mint_url: MintUrl,
+    /// Currency Unit
+    pub unit: CurrencyUnit,
+}
+
+impl TryFrom<WalletKey> for cdk::WalletKey {
+    type Error = FfiError;
+
+    fn try_from(value: WalletKey) -> Result<Self, Self::Error> {
+        Ok(Self {
+            mint_url: value.mint_url.try_into()?,
+            unit: value.unit.into(),
+        })
+    }
+}
+
+impl From<cdk::WalletKey> for WalletKey {
+    fn from(value: cdk::WalletKey) -> Self {
+        Self {
+            mint_url: value.mint_url.into(),
+            unit: value.unit.into(),
+        }
+    }
+}

+ 3 - 3
crates/cdk-ffi/src/wallet_repository.rs

@@ -209,11 +209,11 @@ impl WalletRepository {
     }
 
     /// Get wallet balances for all mints
-    pub async fn get_balances(&self) -> Result<HashMap<String, Amount>, FfiError> {
+    pub async fn get_balances(&self) -> Result<HashMap<WalletKey, Amount>, FfiError> {
         let balances = self.inner.get_balances().await?;
         let mut balance_map = HashMap::new();
-        for (mint_url, amount) in balances {
-            balance_map.insert(mint_url.to_string(), amount.into());
+        for (wallet_key, amount) in balances {
+            balance_map.insert(wallet_key.into(), amount.into());
         }
         Ok(balance_map)
     }

+ 3 - 0
crates/cdk/src/lib.rs

@@ -39,6 +39,9 @@ mod oidc_client;
 #[cfg(feature = "mint")]
 #[doc(hidden)]
 pub use cdk_common::payment as cdk_payment;
+#[cfg(feature = "wallet")]
+#[doc(hidden)]
+pub use cdk_common::wallet::WalletKey;
 /// Re-export amount type
 #[doc(hidden)]
 pub use cdk_common::{