Răsfoiți Sursa

Restore WalletDbBackend

Cesar Rodas 2 luni în urmă
părinte
comite
b9f0e63e08
1 a modificat fișierele cu 15 adăugiri și 9 ștergeri
  1. 15 9
      crates/cdk-ffi/src/database.rs

+ 15 - 9
crates/cdk-ffi/src/database.rs

@@ -1444,22 +1444,28 @@ impl WalletDatabaseTransaction for FfiWalletTransaction {
 
 /// FFI-safe database type enum
 #[derive(uniffi::Enum, Clone)]
-pub enum WalletDatabaseType {
+pub enum WalletDbBackend {
     Sqlite {
-        db: Arc<WalletSqliteDatabase>,
+        path: String,
     },
     #[cfg(feature = "postgres")]
     Postgres {
-        db: Arc<WalletPostgresDatabase>,
+        url: String,
     },
 }
 
-impl WalletDatabaseType {
-    pub fn as_trait(&self) -> Arc<dyn WalletDatabase> {
-        match self {
-            WalletDatabaseType::Sqlite { db } => db.clone() as Arc<dyn WalletDatabase>,
-            #[cfg(feature = "postgres")]
-            WalletDatabaseType::Postgres { db } => db.clone() as Arc<dyn WalletDatabase>,
+/// Factory helpers returning a CDK wallet database behind the FFI trait
+#[uniffi::export]
+pub fn create_wallet_db(backend: WalletDbBackend) -> Result<Arc<dyn WalletDatabase>, FfiError> {
+    match backend {
+        WalletDbBackend::Sqlite { path } => {
+            let sqlite = WalletSqliteDatabase::new(path)?;
+            Ok(sqlite as Arc<dyn WalletDatabase>)
+        }
+        #[cfg(feature = "postgres")]
+        WalletDbBackend::Postgres { url } => {
+            let pg = WalletPostgresDatabase::new(url)?;
+            Ok(pg as Arc<dyn WalletDatabase>)
         }
     }
 }