Преглед на файлове

Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
C преди 5 месеца
родител
ревизия
0e1641ea85

+ 2 - 2
crates/cdk-sqlite/src/common.rs

@@ -13,7 +13,7 @@ pub fn create_sqlite_pool(
         (SqliteConnectionManager::file(path), false)
     };
 
-    let manager = manager.with_init(|conn| {
+    let manager = manager.with_init(move |conn| {
         // Apply pragmas
         conn.pragma_update(None, "busy_timeout", 5000)?;
         conn.pragma_update(None, "journal_mode", "wal")?;
@@ -23,7 +23,7 @@ pub fn create_sqlite_pool(
         conn.pragma_update(None, "cache", "shared")?;
 
         #[cfg(feature = "sqlcipher")]
-        conn.pragma_update(None, "key", &password)?;
+        conn.pragma_update(None, "key", password.clone())?;
 
         Ok(())
     });

+ 6 - 0
crates/cdk-sqlite/src/mint/auth/mod.rs

@@ -29,6 +29,12 @@ refinery::embed_migrations!("./src/mint/auth/migrations");
 impl MintSqliteAuthDatabase {
     /// Create new [`MintSqliteAuthDatabase`]
     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)?,
+            "".to_owned(),
+        )?;
+        #[cfg(not(feature = "sqlcipher"))]
         let pool = create_sqlite_pool(path.as_ref().to_str().ok_or(Error::InvalidDbPath)?)?;
         let mut conn = pool.get()?;
 

+ 2 - 2
crates/cdk-sqlite/src/mint/error.rs

@@ -30,8 +30,8 @@ pub enum Error {
     #[error("Internal communication error")]
     Communication,
 
-    /// Invalid resposne from the database thread
-    #[error("Internal communication error")]
+    /// Invalid response from the database thread
+    #[error("Unexpected database response")]
     InvalidDbResponse,
 
     /// Invalid db type

+ 2 - 2
crates/cdk-sqlite/src/mint/mod.rs

@@ -75,13 +75,13 @@ impl MintSqliteDatabase {
             path.as_ref().to_str().ok_or(Error::InvalidDbPath)?,
             password,
         )?;
-        let mut conn = async_rusqlite.get()?;
+        let mut conn = pool.get()?;
 
         migration::migrations::runner().run(&mut *conn)?;
         drop(conn);
 
         Ok(Self {
-            pool: async_rusqlite::AsyncRusqlite::new(async_rusqlite),
+            pool: async_rusqlite::AsyncRusqlite::new(pool),
         })
     }
 

+ 1 - 1
crates/cdk-sqlite/src/wallet/mod.rs

@@ -59,7 +59,7 @@ impl WalletSqliteDatabase {
             pool: create_sqlite_pool(
                 path.as_ref().to_str().ok_or(Error::InvalidDbPath)?,
                 password,
-            ),
+            )?,
         };
         db.migrate()?;
         Ok(db)