|
|
@@ -15,7 +15,6 @@ use std::sync::Arc;
|
|
|
|
|
|
use async_trait::async_trait;
|
|
|
use bitcoin::bip32::DerivationPath;
|
|
|
-use cdk_common::database::locked_row::LockedRows;
|
|
|
use cdk_common::database::mint::{
|
|
|
CompletedOperationsDatabase, CompletedOperationsTransaction, SagaDatabase, SagaTransaction,
|
|
|
};
|
|
|
@@ -79,7 +78,61 @@ where
|
|
|
RM: DatabasePool + 'static,
|
|
|
{
|
|
|
inner: ConnectionWithTransaction<RM::Connection, PooledResource<RM>>,
|
|
|
- locked_records: LockedRows,
|
|
|
+ #[cfg(feature = "testing")]
|
|
|
+ locked_records: crate::LockedRows,
|
|
|
+}
|
|
|
+
|
|
|
+impl<RM> SQLTransaction<RM>
|
|
|
+where
|
|
|
+ RM: DatabasePool + 'static,
|
|
|
+{
|
|
|
+ /// Lock a record for modification (only active when testing feature is enabled)
|
|
|
+ #[cfg(feature = "testing")]
|
|
|
+ #[inline(always)]
|
|
|
+ fn lock_record<T: Into<crate::RowId>>(&mut self, record_id: T) {
|
|
|
+ self.locked_records.lock(record_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Lock a record for modification (no-op when testing feature is disabled)
|
|
|
+ #[cfg(not(feature = "testing"))]
|
|
|
+ #[inline(always)]
|
|
|
+ fn lock_record<T>(&mut self, _record_id: T) {}
|
|
|
+
|
|
|
+ /// Lock multiple records for modification (only active when testing feature is enabled)
|
|
|
+ #[cfg(feature = "testing")]
|
|
|
+ #[inline(always)]
|
|
|
+ fn lock_records<T: Into<crate::RowId>>(&mut self, records: Vec<T>) {
|
|
|
+ self.locked_records.lock_many(records);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Lock multiple records for modification (no-op when testing feature is disabled)
|
|
|
+ #[cfg(not(feature = "testing"))]
|
|
|
+ #[inline(always)]
|
|
|
+ fn lock_records<T>(&mut self, _records: Vec<T>) {}
|
|
|
+
|
|
|
+ /// Verify records are locked (only active when testing feature is enabled)
|
|
|
+ #[cfg(feature = "testing")]
|
|
|
+ #[inline(always)]
|
|
|
+ fn verify_locked<T: Into<crate::RowId>>(&self, record_id: T) {
|
|
|
+ self.locked_records.is_locked(record_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Verify records are locked (no-op when testing feature is disabled)
|
|
|
+ #[cfg(not(feature = "testing"))]
|
|
|
+ #[inline(always)]
|
|
|
+ fn verify_locked<T>(&self, _record_id: T) {}
|
|
|
+
|
|
|
+ /// Verify multiple records are locked (only active when testing feature is enabled)
|
|
|
+ #[cfg(feature = "testing")]
|
|
|
+ #[inline(always)]
|
|
|
+ fn verify_locked_many<T: Into<crate::RowId>>(&self, records: Vec<T>) {
|
|
|
+ self.locked_records.is_locked_many(records);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Verify multiple records are locked (no-op when testing feature is disabled)
|
|
|
+ #[cfg(not(feature = "testing"))]
|
|
|
+ #[inline(always)]
|
|
|
+ fn verify_locked_many<T>(&self, _records: Vec<T>) {}
|
|
|
}
|
|
|
|
|
|
impl<RM> SQLMintDatabase<RM>
|
|
|
@@ -144,7 +197,7 @@ where
|
|
|
|
|
|
for proof in proofs {
|
|
|
let y = proof.y()?;
|
|
|
- self.locked_records.lock(y);
|
|
|
+ self.lock_record(y);
|
|
|
|
|
|
query(
|
|
|
r#"
|
|
|
@@ -180,7 +233,7 @@ where
|
|
|
ys: &[PublicKey],
|
|
|
new_state: State,
|
|
|
) -> Result<Vec<Option<State>>, Self::Err> {
|
|
|
- self.locked_records.is_locked_many(ys.to_owned())?;
|
|
|
+ self.verify_locked_many(ys.to_owned());
|
|
|
|
|
|
let mut current_states = get_current_states(&self.inner, ys, true).await?;
|
|
|
|
|
|
@@ -302,7 +355,7 @@ where
|
|
|
.into_iter()
|
|
|
.map(|row| {
|
|
|
sql_row_to_proof(row).inspect(|row| {
|
|
|
- let _ = row.y().map(|c| self.locked_records.lock(c));
|
|
|
+ let _ = row.y().map(|c| self.lock_record(c));
|
|
|
})
|
|
|
})
|
|
|
.collect::<Result<Vec<Proof>, _>>()?
|
|
|
@@ -345,8 +398,7 @@ where
|
|
|
get_current_states(&self.inner, ys, true)
|
|
|
.await
|
|
|
.inspect(|public_keys| {
|
|
|
- self.locked_records
|
|
|
- .lock_many(public_keys.keys().collect::<Vec<_>>());
|
|
|
+ self.lock_records(public_keys.keys().collect::<Vec<_>>());
|
|
|
})?;
|
|
|
|
|
|
Ok(ys.iter().map(|y| current_states.remove(y)).collect())
|
|
|
@@ -745,6 +797,7 @@ where
|
|
|
self.pool.get().map_err(|e| Error::Database(Box::new(e)))?,
|
|
|
)
|
|
|
.await?,
|
|
|
+ #[cfg(feature = "testing")]
|
|
|
locked_records: Default::default(),
|
|
|
};
|
|
|
|
|
|
@@ -1035,7 +1088,7 @@ where
|
|
|
amount_paid: Amount,
|
|
|
payment_id: String,
|
|
|
) -> Result<mint::MintQuote, Self::Err> {
|
|
|
- self.locked_records.is_locked("e.id)?;
|
|
|
+ self.verify_locked("e.id);
|
|
|
if amount_paid == Amount::ZERO {
|
|
|
tracing::warn!("Amount payments of zero amount should not be recorded.");
|
|
|
return Err(Error::Duplicate);
|
|
|
@@ -1115,7 +1168,7 @@ where
|
|
|
mut quote: mint::MintQuote,
|
|
|
amount_issued: Amount,
|
|
|
) -> Result<mint::MintQuote, Self::Err> {
|
|
|
- self.locked_records.is_locked("e.id)?;
|
|
|
+ self.verify_locked("e.id);
|
|
|
|
|
|
let new_amount_issued = quote
|
|
|
.increment_amount_issued(amount_issued)
|
|
|
@@ -1183,7 +1236,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
.execute(&self.inner)
|
|
|
.await?;
|
|
|
|
|
|
- self.locked_records.lock("e.id);
|
|
|
+ self.lock_record("e.id);
|
|
|
|
|
|
Ok(quote)
|
|
|
}
|
|
|
@@ -1232,7 +1285,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
.execute(&self.inner)
|
|
|
.await?;
|
|
|
|
|
|
- self.locked_records.lock("e.id);
|
|
|
+ self.lock_record("e.id);
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
@@ -1370,7 +1423,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
.await
|
|
|
.inspect(|quote| {
|
|
|
quote.as_ref().inspect(|mint_quote| {
|
|
|
- self.locked_records.lock(&mint_quote.id);
|
|
|
+ self.lock_record(&mint_quote.id);
|
|
|
});
|
|
|
})
|
|
|
}
|
|
|
@@ -1383,7 +1436,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
.await
|
|
|
.inspect(|quote| {
|
|
|
quote.as_ref().inspect(|melt_quote| {
|
|
|
- self.locked_records.lock(&melt_quote.id);
|
|
|
+ self.lock_record(&melt_quote.id);
|
|
|
});
|
|
|
})
|
|
|
}
|
|
|
@@ -1396,7 +1449,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
.await
|
|
|
.inspect(|quote| {
|
|
|
quote.as_ref().inspect(|mint_quote| {
|
|
|
- self.locked_records.lock(&mint_quote.id);
|
|
|
+ self.lock_record(&mint_quote.id);
|
|
|
});
|
|
|
})
|
|
|
}
|
|
|
@@ -1409,7 +1462,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
.await
|
|
|
.inspect(|quote| {
|
|
|
quote.as_ref().inspect(|mint_quote| {
|
|
|
- self.locked_records.lock(&mint_quote.id);
|
|
|
+ self.lock_record(&mint_quote.id);
|
|
|
});
|
|
|
})
|
|
|
}
|
|
|
@@ -2181,6 +2234,7 @@ where
|
|
|
self.pool.get().map_err(|e| Error::Database(Box::new(e)))?,
|
|
|
)
|
|
|
.await?,
|
|
|
+ #[cfg(feature = "testing")]
|
|
|
locked_records: Default::default(),
|
|
|
}))
|
|
|
}
|
|
|
@@ -2475,6 +2529,7 @@ where
|
|
|
self.pool.get().map_err(|e| Error::Database(Box::new(e)))?,
|
|
|
)
|
|
|
.await?,
|
|
|
+ #[cfg(feature = "testing")]
|
|
|
locked_records: Default::default(),
|
|
|
};
|
|
|
|