From 1515f68748bb534c6255ebd0ada6b545f4cd215a Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Sun, 31 Aug 2014 16:35:30 -0700 Subject: [PATCH] Minor cleanup of utxoset input checking --- src/blockdata/utxoset.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/blockdata/utxoset.rs b/src/blockdata/utxoset.rs index 6d438a3..ffd76da 100644 --- a/src/blockdata/utxoset.rs +++ b/src/blockdata/utxoset.rs @@ -253,28 +253,23 @@ impl UtxoSet { } } - let mut skipped_genesis = false; - for tx in block.txdata.iter() { + for tx in block.txdata.iter().skip(1) { let txid = tx.bitcoin_hash(); // Put the removed utxos into the stxo cache, in case we need to rewind - if skipped_genesis { - self.spent_txos.get_mut(spent_idx).reserve_additional(tx.input.len()); - for (n, input) in tx.input.iter().enumerate() { - let taken = self.take_utxo(input.prev_hash, input.prev_index); - match taken { - Some(txo) => { self.spent_txos.get_mut(spent_idx).push(((txid, n as u32), txo)); } - None => { - if validation >= TxoValidation { - self.rewind(block); - return Err(InvalidTx(txid, - InputNotFound(input.prev_hash, input.prev_index))); - } + self.spent_txos.get_mut(spent_idx).reserve_additional(tx.input.len()); + for (n, input) in tx.input.iter().enumerate() { + let taken = self.take_utxo(input.prev_hash, input.prev_index); + match taken { + Some(txo) => { self.spent_txos.get_mut(spent_idx).push(((txid, n as u32), txo)); } + None => { + if validation >= TxoValidation { + self.rewind(block); + return Err(InvalidTx(txid, + InputNotFound(input.prev_hash, input.prev_index))); } } } } - skipped_genesis = true; - } // If we made it here, success! Ok(())