Skip to content

Commit

Permalink
fix: set inactive keysets as inactive in sql db
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jul 11, 2024
1 parent 6d3200c commit 920e5d1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/cdk-sqlite/src/mint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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> {
Expand Down

0 comments on commit 920e5d1

Please sign in to comment.