mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 23:55:01 +01:00
fix: dont update proof state if already spent
This commit is contained in:
@@ -590,6 +590,20 @@ impl MintDatabase for MintRedbDatabase {
|
||||
.map_err(Error::from)?;
|
||||
|
||||
for y in ys {
|
||||
let current_state;
|
||||
|
||||
{
|
||||
match table.get(y.to_bytes()).map_err(Error::from)? {
|
||||
Some(state) => {
|
||||
current_state =
|
||||
Some(serde_json::from_str(state.value()).map_err(Error::from)?)
|
||||
}
|
||||
None => current_state = None,
|
||||
}
|
||||
}
|
||||
states.push(current_state);
|
||||
|
||||
if current_state != Some(State::Spent) {
|
||||
match table
|
||||
.insert(y.to_bytes(), state_str.as_str())
|
||||
.map_err(Error::from)?
|
||||
@@ -601,6 +615,7 @@ impl MintDatabase for MintRedbDatabase {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
write_txn.commit().map_err(Error::from)?;
|
||||
|
||||
|
||||
@@ -584,6 +584,7 @@ WHERE y=?;
|
||||
|
||||
let proofs_state = proofs_state.to_string();
|
||||
for y in ys {
|
||||
let current_state;
|
||||
let y = y.to_bytes().to_vec();
|
||||
let rec = sqlx::query(
|
||||
r#"
|
||||
@@ -599,15 +600,19 @@ WHERE y=?;
|
||||
match rec {
|
||||
Ok(rec) => {
|
||||
let state: String = rec.get("state");
|
||||
let state = State::from_str(&state).map_err(Error::from)?;
|
||||
states.push(Some(state));
|
||||
current_state = Some(State::from_str(&state).map_err(Error::from)?);
|
||||
}
|
||||
Err(err) => match err {
|
||||
sqlx::Error::RowNotFound => states.push(None),
|
||||
sqlx::Error::RowNotFound => {
|
||||
current_state = None;
|
||||
}
|
||||
_ => return Err(Error::SQLX(err).into()),
|
||||
},
|
||||
};
|
||||
|
||||
states.push(current_state);
|
||||
|
||||
if current_state != Some(State::Spent) {
|
||||
sqlx::query(
|
||||
r#"
|
||||
UPDATE proof SET state = ? WHERE y = ?
|
||||
@@ -619,6 +624,7 @@ WHERE y=?;
|
||||
.await
|
||||
.map_err(Error::from)?;
|
||||
}
|
||||
}
|
||||
|
||||
transaction.commit().await.map_err(Error::from)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user