mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 23:55:01 +01:00
feat: add remove proofs to mint db
This commit is contained in:
@@ -86,8 +86,14 @@ pub trait Database {
|
||||
/// Get [`MintKeySetInfo`]s
|
||||
async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
|
||||
|
||||
/// Add spent [`Proofs`]
|
||||
/// Add [`Proofs`]
|
||||
async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
|
||||
/// Remove [`Proofs`]
|
||||
async fn remove_proofs(
|
||||
&self,
|
||||
ys: &[PublicKey],
|
||||
quote_id: Option<Uuid>,
|
||||
) -> Result<(), Self::Err>;
|
||||
/// Get [`Proofs`] by ys
|
||||
async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
|
||||
/// Get ys by quote id
|
||||
|
||||
@@ -534,6 +534,36 @@ impl MintDatabase for MintRedbDatabase {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_proofs(
|
||||
&self,
|
||||
ys: &[PublicKey],
|
||||
quote_id: Option<Uuid>,
|
||||
) -> Result<(), Self::Err> {
|
||||
let write_txn = self.db.begin_write().map_err(Error::from)?;
|
||||
|
||||
{
|
||||
let mut proofs_table = write_txn.open_table(PROOFS_TABLE).map_err(Error::from)?;
|
||||
|
||||
for y in ys {
|
||||
proofs_table.remove(&y.to_bytes()).map_err(Error::from)?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(quote_id) = quote_id {
|
||||
let mut quote_proofs_table = write_txn
|
||||
.open_multimap_table(QUOTE_PROOFS_TABLE)
|
||||
.map_err(Error::from)?;
|
||||
|
||||
quote_proofs_table
|
||||
.remove_all(quote_id.as_bytes())
|
||||
.map_err(Error::from)?;
|
||||
}
|
||||
|
||||
write_txn.commit().map_err(Error::from)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err> {
|
||||
let read_txn = self.db.begin_read().map_err(Error::from)?;
|
||||
let table = read_txn.open_table(PROOFS_TABLE).map_err(Error::from)?;
|
||||
|
||||
@@ -780,6 +780,33 @@ VALUES (?, ?, ?, ?, ?, ?, ?, ?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_proofs(
|
||||
&self,
|
||||
ys: &[PublicKey],
|
||||
_quote_id: Option<Uuid>,
|
||||
) -> Result<(), Self::Err> {
|
||||
let mut transaction = self.pool.begin().await.map_err(Error::from)?;
|
||||
|
||||
let sql = format!(
|
||||
"DELETE FROM proof WHERE y IN ({})",
|
||||
std::iter::repeat("?")
|
||||
.take(ys.len())
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
);
|
||||
|
||||
ys.iter()
|
||||
.fold(sqlx::query(&sql), |query, y| {
|
||||
query.bind(y.to_bytes().to_vec())
|
||||
})
|
||||
.execute(&mut transaction)
|
||||
.await
|
||||
.map_err(Error::from)?;
|
||||
|
||||
transaction.commit().await.map_err(Error::from)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err> {
|
||||
let mut transaction = self.pool.begin().await.map_err(Error::from)?;
|
||||
|
||||
|
||||
@@ -284,6 +284,27 @@ impl MintDatabase for MintMemoryDatabase {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_proofs(
|
||||
&self,
|
||||
ys: &[PublicKey],
|
||||
quote_id: Option<Uuid>,
|
||||
) -> Result<(), Self::Err> {
|
||||
{
|
||||
let mut db_proofs = self.proofs.write().await;
|
||||
|
||||
ys.iter().for_each(|y| {
|
||||
db_proofs.remove(&y.to_bytes());
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(quote_id) = quote_id {
|
||||
let mut quote_proofs = self.quote_proofs.lock().await;
|
||||
quote_proofs.remove("e_id);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err> {
|
||||
let spent_proofs = self.proofs.read().await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user