From 6ad403fbf8ae7d5d7d6eb49a10c93bc6f82de1b3 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Mon, 20 Nov 2017 10:38:49 +0000 Subject: [PATCH] Wallet recovery return unspent only (#340) * beginning to add wallet restore... api endpoints and basic restore * basic restore working, still missing features * rustfmt * large speed up to output search, should be more or less working * properly mark coinbase status * ensure only unspent utxos are returned from sumtree --- api/src/handlers.rs | 3 ++- chain/src/chain.rs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/src/handlers.rs b/api/src/handlers.rs index 69cecfe4d..02aa1571b 100644 --- a/api/src/handlers.rs +++ b/api/src/handlers.rs @@ -118,7 +118,8 @@ impl UtxoHandler { let outputs = block .outputs .iter() - .map(|k| OutputSwitch::from_output(k, &header)) + .filter(|c|self.chain.is_unspent(&c.commit).unwrap()) + .map(|k|OutputSwitch::from_output(k, &header)) .collect(); BlockOutputs { header: BlockHeaderInfo::from_header(&header), diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 786609bac..32635804e 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -239,6 +239,12 @@ impl Chain { } } + /// Checks whether an output is unspent + pub fn is_unspent(&self, output_ref: &Commitment) -> Result { + let sumtrees = self.sumtrees.read().unwrap(); + sumtrees.is_unspent(output_ref) + } + /// Sets the sumtree roots on a brand new block by applying the block on the /// current sumtree state. pub fn set_sumtree_roots(&self, b: &mut Block) -> Result<(), Error> {