2016-11-29 03:07:11 -08:00
|
|
|
use chain_verifier::ChainVerifier;
|
|
|
|
use super::TransactionError;
|
|
|
|
use db::IndexedBlock;
|
|
|
|
|
|
|
|
pub struct Task<'a> {
|
|
|
|
block: &'a IndexedBlock,
|
2016-11-29 08:03:59 -08:00
|
|
|
block_height: u32,
|
2016-11-29 03:07:11 -08:00
|
|
|
from: usize,
|
|
|
|
to: usize,
|
|
|
|
result: Result<(), TransactionCheckError>,
|
|
|
|
}
|
|
|
|
|
|
|
|
type TransactionCheckError = (usize, TransactionError);
|
|
|
|
|
|
|
|
impl<'a> Task<'a> {
|
2016-11-29 08:03:59 -08:00
|
|
|
pub fn new(block: &'a IndexedBlock, block_height: u32, from: usize, to: usize) -> Self {
|
2016-11-29 03:07:11 -08:00
|
|
|
Task {
|
|
|
|
block: block,
|
2016-11-29 08:03:59 -08:00
|
|
|
block_height: block_height,
|
2016-11-29 03:07:11 -08:00
|
|
|
from: from,
|
|
|
|
to: to,
|
|
|
|
result: Ok(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn progress(&mut self, verifier: &ChainVerifier) {
|
|
|
|
for index in self.from..self.to {
|
2016-11-29 08:03:59 -08:00
|
|
|
if let Err(e) = verifier.verify_transaction(self.block, self.block_height, self.block.header().time, self.block.transaction_at(index).1, index) {
|
2016-11-29 03:07:11 -08:00
|
|
|
self.result = Err((index, e))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.result = Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn result(self) -> Result<(), TransactionCheckError> {
|
|
|
|
self.result
|
|
|
|
}
|
|
|
|
}
|