From f3a559824c486df3ba136affed95871e12ae8982 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 22 Jun 2018 18:56:21 +0300 Subject: [PATCH] Make index_block() a public function So it could be used by blk*.dat parsing --- src/index.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/index.rs b/src/index.rs index b77ac52..2be576d 100644 --- a/src/index.rs +++ b/src/index.rs @@ -183,7 +183,7 @@ pub fn index_transaction(txn: &Transaction, height: usize, rows: &mut Vec) rows.push(TxRow::new(&txid, height as u32).to_row()); } -fn index_block(block: &Block, height: usize) -> Vec { +pub fn index_block(block: &Block, height: usize) -> Vec { let mut rows = vec![]; for txn in &block.txdata { index_transaction(&txn, height, &mut rows); @@ -197,14 +197,17 @@ fn index_block(block: &Block, height: usize) -> Vec { }).unwrap(), value: serialize(&block.header).unwrap(), }); - // Store last indexed block (i.e. all previous blocks were indexed) - rows.push(Row { - key: b"L".to_vec(), - value: serialize(&blockhash).unwrap(), - }); rows } +fn last_indexed_block(blockhash: &Sha256dHash) -> Row { + // Store last indexed block (i.e. all previous blocks were indexed) + Row { + key: b"L".to_vec(), + value: serialize(blockhash).unwrap(), + } +} + fn read_indexed_headers(store: &ReadStore) -> HeaderList { let latest_blockhash: Sha256dHash = match store.get(b"L") { // latest blockheader persisted in the DB. @@ -359,13 +362,14 @@ impl Index { } for block in &batch { - let expected_hash = block.bitcoin_hash(); + let blockhash = block.bitcoin_hash(); let height = *height_map - .get(&expected_hash) - .expect(&format!("missing header for block {}", expected_hash)); + .get(&blockhash) + .expect(&format!("missing header for block {}", blockhash)); let timer = self.stats.start_timer("index"); - let rows = index_block(block, height); + let mut rows = index_block(block, height); + rows.push(last_indexed_block(&blockhash)); timer.observe_duration(); let timer = self.stats.start_timer("write");