Skip to content

Commit

Permalink
Decode block header only in Index::index_blockfiles (ordinals#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Feb 14, 2022
1 parent 1a5dbb2 commit 90b5f25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ impl Index {

let bytes = &blocks[start..end];

let block = Block::consensus_decode(bytes)?;
let hash = block.block_hash();
let header = BlockHeader::consensus_decode(&bytes[0..80])?;
let hash = header.block_hash();

if block.header.prev_blockhash == Default::default() {
if header.prev_blockhash == Default::default() {
if genesis {
return Err("Duplicate genesis block found".into());
}
Expand All @@ -236,7 +236,7 @@ impl Index {
genesis = true;
}

hash_to_children.insert(&block.header.prev_blockhash, &block.block_hash())?;
hash_to_children.insert(&header.prev_blockhash, &hash)?;

hash_to_block.insert(&hash, bytes)?;

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
bitcoin::{
blockdata::constants::COIN_VALUE,
consensus::{Decodable, Encodable},
Block, Network, OutPoint, Transaction,
Block, BlockHeader, Network, OutPoint, Transaction,
},
derive_more::{Display, FromStr},
integer_cbrt::IntegerCubeRoot,
Expand Down

0 comments on commit 90b5f25

Please sign in to comment.