Skip to content

Commit 323e5b4

Browse files
authored
Merge pull request #29 from rustaceanrob/8-12-kernel-hints
Initial program for building a hintfile with `bitcoinkernel`
2 parents 9e87c7e + db393eb commit 323e5b4

8 files changed

Lines changed: 50 additions & 127 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
Cargo.lock
33
!justfile
44
*.db
5+
*.hints

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[workspace]
22
members = ["accumulator", "hintfile", "network"]
33
default-members = ["accumulator", "hintfile", "network"]
4-
resolver = "3"
4+
resolver = "2"
55

66
[workspace.dependencies]
77
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin", default-features = false, rev = "16cc257c3695dea0e7301a5fa9cab44b8ed60598" }

accumulator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "accumulator"
33
version = "0.1.0"
4-
edition = "2024"
4+
edition = "2021"
55

66
[dependencies]
77
bitcoin = { workspace = true }

flake.lock

Lines changed: 0 additions & 96 deletions
This file was deleted.

flake.nix

Lines changed: 0 additions & 27 deletions
This file was deleted.

hintfile/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
[package]
22
name = "hintfile"
33
version = "0.1.0"
4-
edition = "2024"
4+
edition = "2021"
55

66
[dependencies]
7+
bitcoin = { workspace = true }
8+
kernel = { package = "bitcoinkernel", git = "https://github.com/alexanderwiederin/rust-bitcoinkernel.git" }
9+
10+
[[bin]]
11+
name = "construct"

hintfile/src/bin/construct.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use std::{fs::File, sync::Arc};
2+
3+
use bitcoin::consensus;
4+
use kernel::{ChainType, ChainstateManager, ChainstateManagerOptions, ContextBuilder, KernelError};
5+
6+
fn main() {
7+
let mut file = File::create("./signet.hints").unwrap();
8+
9+
let mut args = std::env::args();
10+
let _ = args.next();
11+
let data_dir = args.next().expect("Usage: <path_to_bitcoin_dir>");
12+
let mut blocks_dir = data_dir.clone();
13+
blocks_dir.push_str("/blocks");
14+
println!("Initializing");
15+
let ctx = ContextBuilder::new()
16+
.chain_type(ChainType::SIGNET)
17+
.build()
18+
.unwrap();
19+
let options = ChainstateManagerOptions::new(&ctx, &data_dir, &blocks_dir).unwrap();
20+
let context = Arc::new(ctx);
21+
let chainman = ChainstateManager::new(options, context).unwrap();
22+
println!("Chain state initialized");
23+
let genesis = chainman.get_block_index_genesis();
24+
let mut current = chainman.get_next_block_index(genesis).unwrap();
25+
loop {
26+
let block = chainman.read_block_data(&current).unwrap();
27+
let bytes: Vec<u8> = block.into();
28+
let block = consensus::deserialize::<bitcoin::Block>(&bytes).unwrap();
29+
let (_, transactions) = block.into_parts();
30+
println!("On block {}", current.height());
31+
let mut delta: u64 = 0;
32+
let mut block_offsets: Vec<u64> = Vec::new();
33+
for tx in transactions {}
34+
match chainman.get_next_block_index(current) {
35+
Ok(next) => current = next,
36+
Err(KernelError::OutOfBounds) => break,
37+
Err(e) => panic!("{e}"),
38+
}
39+
}
40+
}

network/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "peers"
33
version = "0.1.0"
4-
edition = "2024"
4+
edition = "2021"
55

66
[dependencies]
77
tokio = { version = "1", default-features = false, optional = true, features = [

0 commit comments

Comments
 (0)