computer: add positions

This commit is contained in:
nym21
2025-09-18 19:45:16 +02:00
parent cc5701ea62
commit 43117825d7
27 changed files with 458 additions and 300 deletions
+2 -2
View File
@@ -39,7 +39,7 @@ pub fn main() -> Result<()> {
.enable_all()
.build()?
.block_on(async {
let interface = Interface::build(&indexer, &computer);
let interface = Interface::build(&parser, &indexer, &computer);
let server = Server::new(interface, None);
@@ -53,7 +53,7 @@ pub fn main() -> Result<()> {
let starting_indexes = indexer.index(&parser, rpc, &exit, true)?;
computer.compute(&indexer, starting_indexes, &exit)?;
computer.compute(&indexer, starting_indexes, &parser, &exit)?;
while block_count == rpc.get_block_count()? {
sleep(Duration::from_secs(1))
+35 -12
View File
@@ -1,4 +1,8 @@
use std::str::FromStr;
use std::{
fs::File,
io::{BufReader, Seek, SeekFrom},
str::FromStr,
};
use axum::{
Json, Router,
@@ -7,9 +11,10 @@ use axum::{
response::{IntoResponse, Redirect, Response},
routing::get,
};
use bitcoin::{Address, Network, absolute::LockTime};
use bitcoin::{Address, Network, Transaction, absolute::LockTime, consensus::Decodable};
use bitcoincore_rpc::bitcoin;
use brk_interface::{IdParam, Index, PaginatedIndexParam, PaginationParam, Params, ParamsOpt};
use brk_parser::XORIndex;
use brk_structs::{
AddressBytesHash, AnyAddressDataIndexEnum, Bitcoin, OutputType, Txid, TxidPrefix,
};
@@ -45,13 +50,6 @@ impl ApiRoutes for Router<AppState> {
let computer = interface.computer();
let stores = &indexer.stores;
let hash = AddressBytesHash::from(&address);
dbg!(&hash);
dbg!(
&address,
address.address_type(),
address.script_pubkey(),
OutputType::from(&address)
);
let Ok(Some(addri)) = stores
.addressbyteshash_to_typeindex
@@ -60,8 +58,6 @@ impl ApiRoutes for Router<AppState> {
return "Unknown address".into_response();
};
println!("Script pubkey: {}", address.script_pubkey());
println!("Address type: {:?}", address.address_type());
let output_type = OutputType::from(&address);
let stateful = &computer.stateful;
let price = computer.price.as_ref().map(|v| {
@@ -178,11 +174,38 @@ impl ApiRoutes for Router<AppState> {
.unwrap_get_inner(txindex);
let locktime = LockTime::from(rawlocktime);
let parser = interface.parser();
let computer = interface.computer();
let position = computer.positions.txindex_to_position.iter().unwrap_get_inner(txindex);
let blk_index_to_blk_path = parser.blk_index_to_blk_path();
let Some(blk_path) = blk_index_to_blk_path.get(&position.blk_index()) else {
return "Unknown blk index".into_response();
};
let mut xori = XORIndex::default();
xori.add_assign(position.offset() as usize);
let Ok(file) = File::open(blk_path) else {
return "Error opening blk file".into_response();
};
let mut reader = BufReader::new(file);
if reader.seek(SeekFrom::Start(position.offset() as u64)).is_err() {
return "Error seeking position in blk file".into_response();
}
let Ok(tx) = Transaction::consensus_decode(&mut reader) else {
return "Error decoding transaction".into_response();
};
Json(serde_json::json!({
"txid": txid,
"index": txindex,
"version": version,
"locktime": locktime
"locktime": locktime,
"tx": tx,
}))
.into_response()
},