|
@@ -506,51 +506,75 @@ VALUES (?, ?, ?, ?, ?, ?, ?);
|
|
|
transaction.commit().await.map_err(Error::from)?;
|
|
|
Ok(())
|
|
|
}
|
|
|
- async fn get_spent_proof_by_secret(&self, secret: &Secret) -> Result<Option<Proof>, Self::Err> {
|
|
|
- let rec = sqlx::query(
|
|
|
- r#"
|
|
|
+ async fn get_spent_proofs_by_secrets(
|
|
|
+ &self,
|
|
|
+ secrets: &[Secret],
|
|
|
+ ) -> Result<Vec<Option<Proof>>, Self::Err> {
|
|
|
+ let mut transaction = self.pool.begin().await.map_err(Error::from)?;
|
|
|
+
|
|
|
+ let mut proofs = Vec::with_capacity(secrets.len());
|
|
|
+
|
|
|
+ for secret in secrets {
|
|
|
+ let rec = sqlx::query(
|
|
|
+ r#"
|
|
|
SELECT *
|
|
|
FROM proof
|
|
|
WHERE secret=?
|
|
|
AND state="SPENT";
|
|
|
"#,
|
|
|
- )
|
|
|
- .bind(secret.to_string())
|
|
|
- .fetch_one(&self.pool)
|
|
|
- .await;
|
|
|
+ )
|
|
|
+ .bind(secret.to_string())
|
|
|
+ .fetch_one(&mut transaction)
|
|
|
+ .await;
|
|
|
|
|
|
- let rec = match rec {
|
|
|
- Ok(rec) => rec,
|
|
|
- Err(err) => match err {
|
|
|
- sqlx::Error::RowNotFound => return Ok(None),
|
|
|
- _ => return Err(Error::SQLX(err).into()),
|
|
|
- },
|
|
|
- };
|
|
|
+ match rec {
|
|
|
+ Ok(rec) => {
|
|
|
+ proofs.push(Some(sqlite_row_to_proof(rec)?));
|
|
|
+ }
|
|
|
+ Err(err) => match err {
|
|
|
+ sqlx::Error::RowNotFound => proofs.push(None),
|
|
|
+ _ => return Err(Error::SQLX(err).into()),
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+ transaction.commit().await.map_err(Error::from)?;
|
|
|
|
|
|
- Ok(Some(sqlite_row_to_proof(rec)?))
|
|
|
+ Ok(proofs)
|
|
|
}
|
|
|
- async fn get_spent_proof_by_y(&self, y: &PublicKey) -> Result<Option<Proof>, Self::Err> {
|
|
|
- let rec = sqlx::query(
|
|
|
- r#"
|
|
|
+ async fn get_spent_proofs_by_ys(
|
|
|
+ &self,
|
|
|
+ ys: &[PublicKey],
|
|
|
+ ) -> Result<Vec<Option<Proof>>, Self::Err> {
|
|
|
+ let mut transaction = self.pool.begin().await.map_err(Error::from)?;
|
|
|
+
|
|
|
+ let mut proofs = Vec::with_capacity(ys.len());
|
|
|
+ for y in ys {
|
|
|
+ let rec = sqlx::query(
|
|
|
+ r#"
|
|
|
SELECT *
|
|
|
FROM proof
|
|
|
WHERE y=?
|
|
|
AND state="SPENT";
|
|
|
"#,
|
|
|
- )
|
|
|
- .bind(y.to_bytes().to_vec())
|
|
|
- .fetch_one(&self.pool)
|
|
|
- .await;
|
|
|
+ )
|
|
|
+ .bind(y.to_bytes().to_vec())
|
|
|
+ .fetch_one(&mut transaction)
|
|
|
+ .await;
|
|
|
|
|
|
- let rec = match rec {
|
|
|
- Ok(rec) => rec,
|
|
|
- Err(err) => match err {
|
|
|
- sqlx::Error::RowNotFound => return Ok(None),
|
|
|
- _ => return Err(Error::SQLX(err).into()),
|
|
|
- },
|
|
|
- };
|
|
|
+ match rec {
|
|
|
+ Ok(rec) => {
|
|
|
+ proofs.push(Some(sqlite_row_to_proof(rec)?));
|
|
|
+ }
|
|
|
+ Err(err) => match err {
|
|
|
+ sqlx::Error::RowNotFound => proofs.push(None),
|
|
|
+ _ => return Err(Error::SQLX(err).into()),
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ transaction.commit().await.map_err(Error::from)?;
|
|
|
|
|
|
- Ok(Some(sqlite_row_to_proof(rec)?))
|
|
|
+ Ok(proofs)
|
|
|
}
|
|
|
|
|
|
async fn add_pending_proofs(&self, proofs: Proofs) -> Result<(), Self::Err> {
|
|
@@ -578,53 +602,72 @@ VALUES (?, ?, ?, ?, ?, ?, ?);
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
- async fn get_pending_proof_by_secret(
|
|
|
+ async fn get_pending_proofs_by_secrets(
|
|
|
&self,
|
|
|
- secret: &Secret,
|
|
|
- ) -> Result<Option<Proof>, Self::Err> {
|
|
|
- let rec = sqlx::query(
|
|
|
- r#"
|
|
|
+ secrets: &[Secret],
|
|
|
+ ) -> Result<Vec<Option<Proof>>, Self::Err> {
|
|
|
+ let mut transaction = self.pool.begin().await.map_err(Error::from)?;
|
|
|
+
|
|
|
+ let mut proofs = Vec::with_capacity(secrets.len());
|
|
|
+
|
|
|
+ for secret in secrets {
|
|
|
+ let rec = sqlx::query(
|
|
|
+ r#"
|
|
|
SELECT *
|
|
|
FROM proof
|
|
|
WHERE secret=?
|
|
|
AND state="PENDING";
|
|
|
"#,
|
|
|
- )
|
|
|
- .bind(secret.to_string())
|
|
|
- .fetch_one(&self.pool)
|
|
|
- .await;
|
|
|
+ )
|
|
|
+ .bind(secret.to_string())
|
|
|
+ .fetch_one(&mut transaction)
|
|
|
+ .await;
|
|
|
+ match rec {
|
|
|
+ Ok(rec) => {
|
|
|
+ proofs.push(Some(sqlite_row_to_proof(rec)?));
|
|
|
+ }
|
|
|
+ Err(err) => match err {
|
|
|
+ sqlx::Error::RowNotFound => proofs.push(None),
|
|
|
+ _ => return Err(Error::SQLX(err).into()),
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+ transaction.commit().await.map_err(Error::from)?;
|
|
|
+ Ok(proofs)
|
|
|
+ }
|
|
|
+ async fn get_pending_proofs_by_ys(
|
|
|
+ &self,
|
|
|
+ ys: &[PublicKey],
|
|
|
+ ) -> Result<Vec<Option<Proof>>, Self::Err> {
|
|
|
+ let mut transaction = self.pool.begin().await.map_err(Error::from)?;
|
|
|
|
|
|
- let rec = match rec {
|
|
|
- Ok(rec) => rec,
|
|
|
- Err(err) => match err {
|
|
|
- sqlx::Error::RowNotFound => return Ok(None),
|
|
|
- _ => return Err(Error::SQLX(err).into()),
|
|
|
- },
|
|
|
- };
|
|
|
+ let mut proofs = Vec::with_capacity(ys.len());
|
|
|
|
|
|
- Ok(Some(sqlite_row_to_proof(rec)?))
|
|
|
- }
|
|
|
- async fn get_pending_proof_by_y(&self, y: &PublicKey) -> Result<Option<Proof>, Self::Err> {
|
|
|
- let rec = sqlx::query(
|
|
|
- r#"
|
|
|
+ for y in ys {
|
|
|
+ let rec = sqlx::query(
|
|
|
+ r#"
|
|
|
SELECT *
|
|
|
FROM proof
|
|
|
WHERE y=?
|
|
|
AND state="PENDING";
|
|
|
"#,
|
|
|
- )
|
|
|
- .bind(y.to_bytes().to_vec())
|
|
|
- .fetch_one(&self.pool)
|
|
|
- .await;
|
|
|
+ )
|
|
|
+ .bind(y.to_bytes().to_vec())
|
|
|
+ .fetch_one(&mut transaction)
|
|
|
+ .await;
|
|
|
|
|
|
- let rec = match rec {
|
|
|
- Ok(rec) => rec,
|
|
|
- Err(err) => match err {
|
|
|
- sqlx::Error::RowNotFound => return Ok(None),
|
|
|
- _ => return Err(Error::SQLX(err).into()),
|
|
|
- },
|
|
|
- };
|
|
|
- Ok(Some(sqlite_row_to_proof(rec)?))
|
|
|
+ match rec {
|
|
|
+ Ok(rec) => {
|
|
|
+ proofs.push(Some(sqlite_row_to_proof(rec)?));
|
|
|
+ }
|
|
|
+ Err(err) => match err {
|
|
|
+ sqlx::Error::RowNotFound => proofs.push(None),
|
|
|
+ _ => return Err(Error::SQLX(err).into()),
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ Ok(proofs)
|
|
|
}
|
|
|
async fn remove_pending_proofs(&self, secrets: Vec<&Secret>) -> Result<(), Self::Err> {
|
|
|
let mut transaction = self.pool.begin().await.map_err(Error::from)?;
|