Prechádzať zdrojové kódy

fix: set inactive keysets as inactive in sql db

thesimplekid 9 mesiacov pred
rodič
commit
920e5d1fd7
1 zmenil súbory, kde vykonal 17 pridanie a 2 odobranie
  1. 17 2
      crates/cdk-sqlite/src/mint/mod.rs

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

@@ -58,6 +58,20 @@ impl MintDatabase for MintSqliteDatabase {
     type Err = cdk_database::Error;
 
     async fn add_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err> {
+        let mut transaction = self.pool.begin().await.map_err(Error::from)?;
+        sqlx::query(
+            r#"
+UPDATE keyset
+SET active=FALSE
+WHERE unit IS ?;
+        "#,
+        )
+        .bind(unit.to_string())
+        .bind(id.to_string())
+        .execute(&mut transaction)
+        .await
+        .map_err(Error::from)?;
+
         sqlx::query(
             r#"
 UPDATE keyset
@@ -68,11 +82,12 @@ AND id IS ?;
         )
         .bind(unit.to_string())
         .bind(id.to_string())
-        .execute(&self.pool)
+        .execute(&mut transaction)
         .await
-        // TODO: should check if error is not found and return none
         .map_err(Error::from)?;
 
+        transaction.commit().await.map_err(Error::from)?;
+
         Ok(())
     }
     async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err> {