Skip to content

Commit

Permalink
sdk: unfreeze UTXOs on proposal deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Apr 11, 2024
1 parent a525dd5 commit be6fc3e
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion crates/smartvaults-sdk/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,27 @@ impl SmartVaultsStorage {
proposals.insert(proposal_id, internal);
}

/// Delete proposal and unfreeze UTXOs
pub async fn delete_proposal(&self, proposal_id: &EventId) -> bool {
let mut proposals = self.proposals.write().await;
proposals.remove(proposal_id).is_some()
match proposals.remove(proposal_id) {
Some(p) => {
// Unfreeze UTXOs
self.unfreeze_utxos(
p.policy_id,
p.proposal
.psbt()
.unsigned_tx
.input
.iter()
.map(|txin| txin.previous_output),
)
.await;

true
}
None => false,
}
}

/// Get proposals
Expand Down Expand Up @@ -815,6 +833,18 @@ impl SmartVaultsStorage {
.extend(utxos);
}

pub async fn unfreeze_utxos<I>(&self, policy_id: EventId, utxos: I)
where
I: IntoIterator<Item = OutPoint> + Clone,
{
let mut frozed_utxos = self.frozed_utxos.write().await;
frozed_utxos.entry(policy_id).and_modify(|set| {
for utxo in utxos.into_iter() {
set.remove(&utxo);
}
});
}

pub async fn get_frozen_utxos(&self, policy_id: &EventId) -> HashSet<OutPoint> {
self.frozed_utxos
.read()
Expand Down

0 comments on commit be6fc3e

Please sign in to comment.