Consolidate validation in Block and Transaction (#1354)

* Consolidate validation in Block and Transaction

Introduce TransactionBody which is included into block and tx.
Fixes #1333
This commit is contained in:
hashmap
2018-08-15 23:14:48 +02:00
committed by GitHub
parent 37fa413329
commit 99a66c1960
20 changed files with 570 additions and 476 deletions
+6 -5
View File
@@ -53,7 +53,7 @@ where
let mut txs = vec![];
for x in &self.entries {
for kernel in &x.tx.kernels {
for kernel in x.tx.kernels() {
// rehash each kernel to calculate the block specific short_id
let short_id = kernel.short_id(&cb.hash(), cb.nonce);
@@ -97,7 +97,8 @@ where
to_state: PoolEntryState,
extra_tx: Option<Transaction>,
) -> Result<Vec<Transaction>, PoolError> {
let entries = &mut self.entries
let entries = &mut self
.entries
.iter_mut()
.filter(|x| x.state == from_state)
.collect::<Vec<_>>();
@@ -189,8 +190,8 @@ where
fn remaining_transactions(&self, block: &Block) -> Vec<Transaction> {
self.entries
.iter()
.filter(|x| !x.tx.kernels.iter().any(|y| block.kernels.contains(y)))
.filter(|x| !x.tx.inputs.iter().any(|y| block.inputs.contains(y)))
.filter(|x| !x.tx.kernels().iter().any(|y| block.kernels().contains(y)))
.filter(|x| !x.tx.inputs().iter().any(|y| block.inputs().contains(y)))
.map(|x| x.tx.clone())
.collect()
}
@@ -205,7 +206,7 @@ where
// Check each transaction in the pool
for entry in &self.entries {
let entry_kernel_set = entry.tx.kernels.iter().cloned().collect::<HashSet<_>>();
let entry_kernel_set = entry.tx.kernels().iter().cloned().collect::<HashSet<_>>();
if entry_kernel_set.is_subset(&kernel_set) {
found_txs.push(entry.tx.clone());
}