mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-21 06:34:59 +01:00
fix: set inactive keysets as inactive in sql db
This commit is contained in:
@@ -58,6 +58,20 @@ impl MintDatabase for MintSqliteDatabase {
|
|||||||
type Err = cdk_database::Error;
|
type Err = cdk_database::Error;
|
||||||
|
|
||||||
async fn add_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err> {
|
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(
|
sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
UPDATE keyset
|
UPDATE keyset
|
||||||
@@ -68,11 +82,12 @@ AND id IS ?;
|
|||||||
)
|
)
|
||||||
.bind(unit.to_string())
|
.bind(unit.to_string())
|
||||||
.bind(id.to_string())
|
.bind(id.to_string())
|
||||||
.execute(&self.pool)
|
.execute(&mut transaction)
|
||||||
.await
|
.await
|
||||||
// TODO: should check if error is not found and return none
|
|
||||||
.map_err(Error::from)?;
|
.map_err(Error::from)?;
|
||||||
|
|
||||||
|
transaction.commit().await.map_err(Error::from)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err> {
|
async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err> {
|
||||||
|
|||||||
Reference in New Issue
Block a user