mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-07 06:56:07 +01:00
Reclaim unspent proofs by reverting transaction (#774)
* Reclaim unspent proofs by reverting transaction * Change fn signatore to return unit
This commit is contained in:
@@ -234,6 +234,9 @@ pub enum Error {
|
||||
/// Invalid transaction id
|
||||
#[error("Invalid transaction id")]
|
||||
InvalidTransactionId,
|
||||
/// Transaction not found
|
||||
#[error("Transaction not found")]
|
||||
TransactionNotFound,
|
||||
/// Custom Error
|
||||
#[error("`{0}`")]
|
||||
Custom(String),
|
||||
|
||||
@@ -28,4 +28,30 @@ impl Wallet {
|
||||
|
||||
Ok(transaction)
|
||||
}
|
||||
|
||||
/// Revert a transaction
|
||||
pub async fn revert_transaction(&self, id: TransactionId) -> Result<(), Error> {
|
||||
let tx = self
|
||||
.localstore
|
||||
.get_transaction(id)
|
||||
.await?
|
||||
.ok_or(Error::TransactionNotFound)?;
|
||||
|
||||
if tx.direction != TransactionDirection::Outgoing {
|
||||
return Err(Error::InvalidTransactionDirection);
|
||||
}
|
||||
|
||||
let pending_spent_proofs = self
|
||||
.get_pending_spent_proofs()
|
||||
.await?
|
||||
.into_iter()
|
||||
.filter(|p| match p.y() {
|
||||
Ok(y) => tx.ys.contains(&y),
|
||||
Err(_) => false,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
self.reclaim_unspent(pending_spent_proofs).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user