Cesar Rodas 4 сар өмнө
parent
commit
996f04309e

+ 5 - 1
crates/cdk-mintd/src/main.rs

@@ -124,7 +124,7 @@ async fn main() -> anyhow::Result<()> {
             #[cfg(not(feature = "sqlcipher"))]
             let sqlite_db = MintSqliteDatabase::new(&sql_db_path).await?;
             #[cfg(feature = "sqlcipher")]
-            let sqlite_db = MintSqliteDatabase::new(&sql_db_path, args.password).await?;
+            let sqlite_db = MintSqliteDatabase::new(&sql_db_path, args.password.clone()).await?;
 
             let db = Arc::new(sqlite_db);
             MintBuilder::new()
@@ -405,7 +405,11 @@ async fn main() -> anyhow::Result<()> {
             match settings.database.engine {
                 DatabaseEngine::Sqlite => {
                     let sql_db_path = work_dir.join("cdk-mintd-auth.sqlite");
+                    #[cfg(not(feature = "sqlcipher"))]
                     let sqlite_db = MintSqliteAuthDatabase::new(&sql_db_path).await?;
+                    #[cfg(feature = "sqlcipher")]
+                    let sqlite_db =
+                        MintSqliteAuthDatabase::new(&sql_db_path, args.password).await?;
 
                     Arc::new(sqlite_db)
                 }

+ 1 - 1
crates/cdk-sqlite/src/mint/async_rusqlite.rs

@@ -195,7 +195,7 @@ fn rusqlite_spawn_worker_threads(
         let rx = receiver.clone();
         let inflight_requests = inflight_requests.clone();
         spawn(move || loop {
-            while let Ok((conn, sql, reply_to)) = rx.lock().unwrap().recv() {
+            while let Ok((conn, sql, reply_to)) = rx.lock().expect("failed to acquire").recv() {
                 tracing::info!("Execute query: {}", sql.sql);
                 let result = process_query(&conn, sql);
                 let _ = match result {

+ 13 - 4
crates/cdk-sqlite/src/mint/auth/mod.rs

@@ -30,14 +30,23 @@ mod migrations;
 
 impl MintSqliteAuthDatabase {
     /// Create new [`MintSqliteAuthDatabase`]
+    #[cfg(not(feature = "sqlcipher"))]
     pub async fn new<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
-        #[cfg(feature = "sqlcipher")]
+        let pool = create_sqlite_pool(path.as_ref().to_str().ok_or(Error::InvalidDbPath)?);
+        migrate(pool.get()?.deref_mut(), migrations::MIGRATIONS)?;
+
+        Ok(Self {
+            pool: AsyncRusqlite::new(pool),
+        })
+    }
+
+    /// Create new [`MintSqliteAuthDatabase`]
+    #[cfg(feature = "sqlcipher")]
+    pub async fn new<P: AsRef<Path>>(path: P, password: String) -> Result<Self, Error> {
         let pool = create_sqlite_pool(
             path.as_ref().to_str().ok_or(Error::InvalidDbPath)?,
-            "".to_owned(),
+            password,
         );
-        #[cfg(not(feature = "sqlcipher"))]
-        let pool = create_sqlite_pool(path.as_ref().to_str().ok_or(Error::InvalidDbPath)?);
         migrate(pool.get()?.deref_mut(), migrations::MIGRATIONS)?;
 
         Ok(Self {