Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions hintfile/src/bin/construct.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{fs::File, sync::Arc};
use std::{fs::File, io::Write, sync::Arc};

use bitcoin::consensus;
use bitcoin::{consensus, OutPoint};
use hintfile::write_compact_size;
use kernel::{ChainType, ChainstateManager, ChainstateManagerOptions, ContextBuilder, KernelError};

fn main() {
Expand All @@ -21,6 +22,8 @@ fn main() {
let chainman = ChainstateManager::new(options, context).unwrap();
println!("Chain state initialized");
let genesis = chainman.get_block_index_genesis();
let tip = chainman.get_block_index_tip().block_hash().hash;
file.write_all(&tip).unwrap();
let mut current = chainman.get_next_block_index(genesis).unwrap();
loop {
let block = chainman.read_block_data(&current).unwrap();
Expand All @@ -30,7 +33,25 @@ fn main() {
println!("On block {}", current.height());
let mut delta: u64 = 0;
let mut block_offsets: Vec<u64> = Vec::new();
for tx in transactions {}
for tx in transactions {
let txid = tx.compute_txid();
for (index, _txout) in tx.outputs.iter().enumerate() {
let _outpoint = OutPoint {
txid,
vout: index as u32,
};
// if true
block_offsets.push(delta);
delta = 0;
}
}
// Overflows 32 bit machines
let len_encode = block_offsets.len() as u64;
println!("Writing block offsets");
write_compact_size(len_encode, &mut file).expect("unexpected EOF");
for offset in block_offsets {
write_compact_size(offset, &mut file).expect("unexpected EOF");
}
match chainman.get_next_block_index(current) {
Ok(next) => current = next,
Err(KernelError::OutOfBounds) => break,
Expand Down
7 changes: 5 additions & 2 deletions hintfile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ impl Hints {
///
/// If there are no offset present at that height, aka an overflow, or the entry has already
/// been fetched.
pub fn take_block_offsets(&mut self, height: BlockHeight) -> Vec<u64> {
self.map.remove(&height).expect("block height overflow")
pub fn get_block_offsets(&self, height: BlockHeight) -> Vec<u64> {
self.map
.get(&height)
.cloned()
.expect("block height overflow")
}
}

Expand Down
Loading