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> {