basic processing

This commit is contained in:
NikVolf 2016-10-18 16:59:59 +03:00
parent e50402fb14
commit 891f5e8e3f
2 changed files with 19 additions and 1 deletions

View File

@ -54,6 +54,14 @@ pub enum Chain {
Orphan,
}
/// block status within the queue
pub enum BlockStatus {
Valid,
Invalid,
Pending,
Absent,
}
/// Verification result
pub type VerificationResult = Result<Chain, Error>;

View File

@ -2,7 +2,7 @@
use chain::{Block, BlockHeader};
use primitives::hash::H256;
use super::{Chain, Verify};
use super::{Chain, Verify, BlockStatus};
use linked_hash_map::LinkedHashMap;
use parking_lot::RwLock;
use std::collections::HashSet;
@ -18,6 +18,7 @@ impl VerifiedBlock {
}
}
/// Verification queue
pub struct Queue {
verifier: Box<Verify>,
items: RwLock<LinkedHashMap<H256, Block>>,
@ -26,6 +27,7 @@ pub struct Queue {
}
impl Queue {
/// Process one block in the queue
pub fn process(&self) {
let (hash, block) = {
let mut items = self.items.write();
@ -48,4 +50,12 @@ impl Queue {
}
}
}
/// Query block status
pub fn block_status(&self, hash: &H256) {
if self.invalid.read().contains_key(hash) { BlockStatus::Invalid }
else if self.verified.read().contains_key(hash) { BlockStatus::Valid }
else if self.items.read().contains_key(hash) { BlockStatus::Pending }
else { BlockStatus::Absent }
}
}