fix: set inactive keysets as inactive in sql db

This commit is contained in:
thesimplekid
2024-07-11 21:02:12 +01:00
parent 6d3200c72d
commit 920e5d1fd7

View File

@@ -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> {