diff --git a/src/index.rs b/src/index.rs index de854d4..dbf41ea 100644 --- a/src/index.rs +++ b/src/index.rs @@ -6,7 +6,7 @@ use bitcoin::network::serialize::{deserialize, serialize}; use bitcoin::util::hash::Sha256dHash; use crypto::digest::Digest; use crypto::sha2::Sha256; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::iter::FromIterator; use std::sync::RwLock; @@ -198,7 +198,7 @@ pub fn index_block(block: &Block, height: usize) -> Vec { rows } -fn last_indexed_block(blockhash: &Sha256dHash) -> Row { +pub fn last_indexed_block(blockhash: &Sha256dHash) -> Row { // Store last indexed block (i.e. all previous blocks were indexed) Row { key: b"L".to_vec(), @@ -206,6 +206,15 @@ fn last_indexed_block(blockhash: &Sha256dHash) -> Row { } } +pub fn read_indexed_blockhashes(store: &ReadStore) -> HashSet { + let mut result = HashSet::new(); + for row in store.scan(b"B") { + let key: BlockKey = bincode::deserialize(&row.key).unwrap(); + result.insert(deserialize(&key.hash).unwrap()); + } + result +} + fn read_indexed_headers(store: &ReadStore) -> HeaderList { let latest_blockhash: Sha256dHash = match store.get(b"L") { // latest blockheader persisted in the DB.