diff --git a/db/src/indexed_block.rs b/db/src/indexed_block.rs index 5f4af5b7..0f06d3bd 100644 --- a/db/src/indexed_block.rs +++ b/db/src/indexed_block.rs @@ -1,6 +1,6 @@ use primitives::hash::H256; use chain::{Block, OutPoint, TransactionOutput, merkle_root}; -use serialization::Serializable; +use serialization::{Serializable, CompactInteger}; use indexed_header::IndexedBlockHeader; use indexed_transaction::IndexedTransaction; use PreviousTransactionOutputProvider; @@ -50,8 +50,10 @@ impl IndexedBlock { } pub fn size(&self) -> usize { + let header_size = self.header.raw.serialized_size(); + let txs_len_size = CompactInteger::from(self.transactions.len()).serialized_size(); let txs_size = self.transactions.iter().map(|tx| tx.raw.serialized_size()).sum::(); - self.header.raw.serialized_size() + txs_size + header_size + txs_len_size + txs_size } pub fn merkle_root(&self) -> H256 { diff --git a/db/src/indexed_transaction.rs b/db/src/indexed_transaction.rs index 950566f3..6ac70e2c 100644 --- a/db/src/indexed_transaction.rs +++ b/db/src/indexed_transaction.rs @@ -37,7 +37,8 @@ impl<'a> PreviousTransactionOutputProvider for &'a [IndexedTransaction] { fn previous_transaction_output(&self, prevout: &OutPoint) -> Option { self.iter() .find(|tx| tx.hash == prevout.hash) - .map(|tx| tx.raw.outputs[prevout.index as usize].clone()) + .and_then(|tx| tx.raw.outputs.get(prevout.index as usize)) + .cloned() } fn is_spent(&self, _prevout: &OutPoint) -> bool {