From 1b6487dec0ee884f57df6756ff013d992fcf3c4b Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Sat, 8 Jul 2023 13:59:30 -0400 Subject: [PATCH] add pending to `nut07` check spendable --- src/mint.rs | 11 ++++++++--- src/nuts/nut07.rs | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mint.rs b/src/mint.rs index 69dea8ba..9b1aecc4 100644 --- a/src/mint.rs +++ b/src/mint.rs @@ -19,6 +19,7 @@ pub struct Mint { pub active_keyset: nut02::mint::KeySet, pub inactive_keysets: HashMap, pub spent_secrets: HashSet, + pub pending_secrets: HashSet, } impl Mint { @@ -33,6 +34,7 @@ impl Mint { active_keyset: nut02::mint::KeySet::generate(secret, derivation_path, max_order), inactive_keysets, spent_secrets, + pending_secrets: HashSet::new(), } } @@ -183,12 +185,15 @@ impl Mint { &self, check_spendable: &CheckSpendableRequest, ) -> Result { - let mut spendable = vec![]; + let mut spendable = Vec::with_capacity(check_spendable.proofs.len()); + let mut pending = Vec::with_capacity(check_spendable.proofs.len()); + for proof in &check_spendable.proofs { - spendable.push(!self.spent_secrets.contains(&proof.secret)) + spendable.push(!self.spent_secrets.contains(&proof.secret)); + pending.push(!self.pending_secrets.contains(&proof.secret)); } - Ok(CheckSpendableResponse { spendable }) + Ok(CheckSpendableResponse { spendable, pending }) } pub fn verify_melt_request(&mut self, melt_request: &MeltRequest) -> Result<(), Error> { diff --git a/src/nuts/nut07.rs b/src/nuts/nut07.rs index ffbd6466..0e10334b 100644 --- a/src/nuts/nut07.rs +++ b/src/nuts/nut07.rs @@ -17,4 +17,5 @@ pub struct CheckSpendableResponse { /// booleans indicating whether the provided Proof is still spendable. /// In same order as provided proofs pub spendable: Vec, + pub pending: Vec, }