1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00

Allow loading indexed block hashes

This commit is contained in:
Roman Zeyde 2018-06-25 10:46:05 +03:00
parent f3d0384caa
commit 2625070cef
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

View File

@ -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<Row> {
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<Sha256dHash> {
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.