Browse Source

Address feedback

Cesar Rodas 5 months ago
parent
commit
f0070249f0
2 changed files with 17 additions and 2 deletions
  1. 15 0
      crates/cdk-sqlite/src/mint/async_rusqlite.rs
  2. 2 2
      crates/cdk-sqlite/src/mint/mod.rs

+ 15 - 0
crates/cdk-sqlite/src/mint/async_rusqlite.rs

@@ -138,8 +138,19 @@ fn process_query(conn: &Connection, sql: InnerStatement) -> Result<DbResponse, E
     })
 }
 
+/// # Rusqlite main worker
+///
+/// This function takes ownership of a pool of connections to SQLite, executes SQL statements, and
+/// returns the results or number of affected rows to the caller. All communications are done
+/// through channels. This function is synchronous, but a thread pool exists to execute queries, and
+/// SQLite will coordinate data access. Transactions are executed in the main and it takes ownership
+/// of the main thread until it is finalized
+///
+/// This is meant to be called in their thread, as it will not exit the loop until the communication
+/// channel is closed.
 fn rusqlite_worker(
     mut receiver: mpsc::Receiver<DbRequest>,
+
     pool: Arc<Pool<SqliteConnectionManager>>,
 ) {
     while let Some(request) = receiver.blocking_recv() {
@@ -240,8 +251,10 @@ fn rusqlite_worker(
 
 #[async_trait::async_trait]
 pub trait DatabaseExecutor {
+    /// Returns the connection to the database thread (or the on-going transaction)
     fn get_queue_sender(&self) -> mpsc::Sender<DbRequest>;
 
+    /// Executes a query and returns the affected rows
     async fn execute(&self, mut statement: InnerStatement) -> Result<usize, Error> {
         let (sender, receiver) = oneshot::channel();
         statement.expected_response = ExpectedSqlResponse::AffectedRows;
@@ -257,6 +270,7 @@ pub trait DatabaseExecutor {
         }
     }
 
+    /// Runs the query and returns the first row or None
     async fn fetch_one(&self, mut statement: InnerStatement) -> Result<Option<Vec<Column>>, Error> {
         let (sender, receiver) = oneshot::channel();
         statement.expected_response = ExpectedSqlResponse::SingleRow;
@@ -272,6 +286,7 @@ pub trait DatabaseExecutor {
         }
     }
 
+    /// Runs the query and returns the first row or None
     async fn fetch_all(&self, mut statement: InnerStatement) -> Result<Vec<Vec<Column>>, Error> {
         let (sender, receiver) = oneshot::channel();
         statement.expected_response = ExpectedSqlResponse::ManyRows;

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

@@ -1008,14 +1008,14 @@ impl MintSignaturesDatabase for MintSqliteDatabase {
     async fn add_blind_signatures(
         &self,
         blinded_messages: &[PublicKey],
-        blinded_signatures: &[BlindSignature],
+        blind_signatures: &[BlindSignature],
         quote_id: Option<Uuid>,
     ) -> Result<(), Self::Err> {
         let transaction = self.pool.begin().await?;
 
         let current_time = unix_time();
 
-        for (message, signature) in blinded_messages.iter().zip(blinded_signatures) {
+        for (message, signature) in blinded_messages.iter().zip(blind_signatures) {
             query(
                 r#"
                     INSERT INTO blind_signature