Skip to content

Commit 4c5d8c6

Browse files
authored
Merge pull request #31 from rustaceanrob/8-14-ref-hints
`hintfile` crate updates
2 parents 95c55bd + 3aa7eff commit 4c5d8c6

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

hintfile/src/bin/construct.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use std::{fs::File, sync::Arc};
1+
use std::{fs::File, io::Write, sync::Arc};
22

3-
use bitcoin::consensus;
3+
use bitcoin::{consensus, OutPoint};
4+
use hintfile::write_compact_size;
45
use kernel::{ChainType, ChainstateManager, ChainstateManagerOptions, ContextBuilder, KernelError};
56

67
fn main() {
@@ -21,6 +22,8 @@ fn main() {
2122
let chainman = ChainstateManager::new(options, context).unwrap();
2223
println!("Chain state initialized");
2324
let genesis = chainman.get_block_index_genesis();
25+
let tip = chainman.get_block_index_tip().block_hash().hash;
26+
file.write_all(&tip).unwrap();
2427
let mut current = chainman.get_next_block_index(genesis).unwrap();
2528
loop {
2629
let block = chainman.read_block_data(&current).unwrap();
@@ -30,7 +33,25 @@ fn main() {
3033
println!("On block {}", current.height());
3134
let mut delta: u64 = 0;
3235
let mut block_offsets: Vec<u64> = Vec::new();
33-
for tx in transactions {}
36+
for tx in transactions {
37+
let txid = tx.compute_txid();
38+
for (index, _txout) in tx.outputs.iter().enumerate() {
39+
let _outpoint = OutPoint {
40+
txid,
41+
vout: index as u32,
42+
};
43+
// if true
44+
block_offsets.push(delta);
45+
delta = 0;
46+
}
47+
}
48+
// Overflows 32 bit machines
49+
let len_encode = block_offsets.len() as u64;
50+
println!("Writing block offsets");
51+
write_compact_size(len_encode, &mut file).expect("unexpected EOF");
52+
for offset in block_offsets {
53+
write_compact_size(offset, &mut file).expect("unexpected EOF");
54+
}
3455
match chainman.get_next_block_index(current) {
3556
Ok(next) => current = next,
3657
Err(KernelError::OutOfBounds) => break,

hintfile/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ impl Hints {
7272
///
7373
/// If there are no offset present at that height, aka an overflow, or the entry has already
7474
/// been fetched.
75-
pub fn take_block_offsets(&mut self, height: BlockHeight) -> Vec<u64> {
76-
self.map.remove(&height).expect("block height overflow")
75+
pub fn get_block_offsets(&self, height: BlockHeight) -> Vec<u64> {
76+
self.map
77+
.get(&height)
78+
.cloned()
79+
.expect("block height overflow")
7780
}
7881
}
7982

0 commit comments

Comments
 (0)