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
This commit is contained in:
Yeastplume 2017-11-20 10:38:49 +00:00 committed by GitHub
parent e20975136e
commit 6ad403fbf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -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),

View file

@ -239,6 +239,12 @@ impl Chain {
}
}
/// Checks whether an output is unspent
pub fn is_unspent(&self, output_ref: &Commitment) -> Result<bool, Error> {
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> {