rpc: init wrapper crate + global: snapshot

This commit is contained in:
nym21
2025-10-20 23:06:25 +02:00
parent 9b230d23dd
commit 4ffa2e3993
39 changed files with 1055 additions and 832 deletions
-71
View File
@@ -1,71 +0,0 @@
use std::path::Path;
use bitcoincore_rpc::{Auth, Client};
use brk_reader::Reader;
use brk_structs::{Height, OutputType};
fn main() {
let i = std::time::Instant::now();
let bitcoin_dir = Path::new("").join("");
let rpc = Box::leak(Box::new(
Client::new(
"http://localhost:8332",
Auth::CookieFile(bitcoin_dir.join(".cookie")),
)
.unwrap(),
));
// let start = None;
// let end = None;
let parser = Reader::new(bitcoin_dir.join("blocks"), rpc);
// parser
// .parse(start, end)
// .iter()
// .for_each(|(height, _block, hash)| {
// println!("{height}: {hash}");
// });
// println!(
// "{}",
// parser
// .get(Height::new(0))
// .txdata
// .first()
// .unwrap()
// .output
// .first()
// .unwrap()
// .script_pubkey
// );
let block_850_000 = parser.get(Height::new(850_000)).unwrap();
let tx = block_850_000.txdata.iter().find(|tx| {
tx.compute_txid().to_string()
== "b10c0000004da5a9d1d9b4ae32e09f0b3e62d21a5cce5428d4ad714fb444eb5d"
});
let output = tx.unwrap().tx_out(7).unwrap();
dbg!(OutputType::from(&output.script_pubkey));
dbg!(output);
// println!(
// "{}",
// .txdata
// .first()
// .unwrap()
// .output
// .first()
// .unwrap()
// .value
// );
dbg!(i.elapsed());
}
+3 -3
View File
@@ -1,13 +1,13 @@
use bitcoin::{Transaction, VarInt, block::Header, consensus::Decodable, io::Cursor};
use bitcoincore_rpc::RpcApi;
use brk_error::Result;
use brk_structs::{BlkMetadata, Block, Height, ParsedBlock};
use brk_structs::{BlkMetadata, Block, Height, ReadBlock};
use crate::{XORBytes, XORIndex};
pub enum AnyBlock {
Raw(Vec<u8>),
Decoded(ParsedBlock),
Decoded(ReadBlock),
Skipped,
}
@@ -67,7 +67,7 @@ impl AnyBlock {
let block = bitcoin::Block { header, txdata };
let block = Block::from((height, hash, block));
let block = ParsedBlock::from((block, metadata, tx_metadata));
let block = ReadBlock::from((block, metadata, tx_metadata));
Ok(Self::Decoded(block))
}
+2 -2
View File
@@ -16,7 +16,7 @@ use bitcoin::{block::Header, consensus::Decodable};
use bitcoincore_rpc::RpcApi;
use blk_index_to_blk_path::*;
use brk_error::Result;
use brk_structs::{BlkMetadata, BlkPosition, Block, Height, ParsedBlock};
use brk_structs::{BlkMetadata, BlkPosition, Block, Height, ReadBlock};
use crossbeam::channel::{Receiver, bounded};
use parking_lot::{RwLock, RwLockReadGuard};
use rayon::prelude::*;
@@ -75,7 +75,7 @@ impl Reader {
///
/// For an example checkout `./main.rs`
///
pub fn read(&self, start: Option<Height>, end: Option<Height>) -> Receiver<ParsedBlock> {
pub fn read(&self, start: Option<Height>, end: Option<Height>) -> Receiver<ReadBlock> {
let rpc = self.rpc;
let (send_bytes, recv_bytes) = bounded(BOUND_CAP / 2);