mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-19 13:44:55 +01:00
Enhance add_proofs to fail with a custom error when the proof already exists
This commit is contained in:
@@ -816,6 +816,26 @@ impl MintProofsDatabase for MintSqliteDatabase {
|
||||
|
||||
let current_time = unix_time();
|
||||
|
||||
// Check any previous proof, this query should return None in order to proceed storing
|
||||
// Any result here would error
|
||||
match query(r#"SELECT state FROM proof WHERE y IN (:ys) LIMIT 1"#)
|
||||
.bind_vec(
|
||||
":ys",
|
||||
proofs
|
||||
.iter()
|
||||
.map(|y| y.y().map(|y| y.to_bytes().to_vec()))
|
||||
.collect::<Result<_, _>>()?,
|
||||
)
|
||||
.pluck(&transaction)
|
||||
.await?
|
||||
.map(|state| Ok::<_, Error>(column_as_string!(&state, State::from_str)))
|
||||
.transpose()?
|
||||
{
|
||||
Some(State::Spent) => Err(database::Error::AttemptUpdateSpentProof),
|
||||
Some(_) => Err(database::Error::Duplicate),
|
||||
None => Ok(()), // no previous record
|
||||
}?;
|
||||
|
||||
for proof in proofs {
|
||||
query(
|
||||
r#"
|
||||
|
||||
Reference in New Issue
Block a user