mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
global: snapshot
This commit is contained in:
@@ -175,12 +175,20 @@ impl Query {
|
||||
.into_iter()
|
||||
.map(|(txindex, vout)| {
|
||||
let txid: Txid = txid_reader.get(txindex.to_usize());
|
||||
let height = vecs.transactions.height.collect_one_at(txindex.to_usize()).unwrap();
|
||||
let height = vecs
|
||||
.transactions
|
||||
.height
|
||||
.collect_one_at(txindex.to_usize())
|
||||
.unwrap();
|
||||
let first_txoutindex = first_txoutindex_reader.get(txindex.to_usize());
|
||||
let txoutindex = first_txoutindex + vout;
|
||||
let value: Sats = value_reader.get(usize::from(txoutindex));
|
||||
let block_hash = blockhash_reader.get(usize::from(height));
|
||||
let block_time = vecs.blocks.timestamp.collect_one_at(usize::from(height)).unwrap();
|
||||
let block_time = vecs
|
||||
.blocks
|
||||
.timestamp
|
||||
.collect_one_at(usize::from(height))
|
||||
.unwrap();
|
||||
|
||||
Utxo {
|
||||
txid,
|
||||
|
||||
@@ -20,7 +20,11 @@ impl Query {
|
||||
return Err(Error::OutOfRange("Block height out of range".into()));
|
||||
}
|
||||
|
||||
let position = computer.positions.block_position.collect_one(height).unwrap();
|
||||
let position = computer
|
||||
.positions
|
||||
.block_position
|
||||
.collect_one(height)
|
||||
.unwrap();
|
||||
let size = indexer.vecs.blocks.total_size.collect_one(height).unwrap();
|
||||
|
||||
reader.read_raw_bytes(position, *size as usize)
|
||||
|
||||
@@ -13,14 +13,7 @@ impl Query {
|
||||
fn block_status_by_height(&self, height: Height) -> Result<BlockStatus> {
|
||||
let indexer = self.indexer();
|
||||
|
||||
let max_height = Height::from(
|
||||
indexer
|
||||
.vecs
|
||||
.blocks
|
||||
.blockhash
|
||||
.len()
|
||||
.saturating_sub(1),
|
||||
);
|
||||
let max_height = Height::from(indexer.vecs.blocks.blockhash.len().saturating_sub(1));
|
||||
|
||||
if height > max_height {
|
||||
return Ok(BlockStatus::not_in_best_chain());
|
||||
|
||||
@@ -57,7 +57,12 @@ impl Query {
|
||||
}
|
||||
|
||||
let height = Height::from(best_height);
|
||||
let blockhash = indexer.vecs.blocks.blockhash.reader().get(usize::from(height));
|
||||
let blockhash = indexer
|
||||
.vecs
|
||||
.blocks
|
||||
.blockhash
|
||||
.reader()
|
||||
.get(usize::from(height));
|
||||
|
||||
// Convert timestamp to ISO 8601 format
|
||||
let ts_secs: i64 = (*best_ts).into();
|
||||
|
||||
@@ -31,7 +31,12 @@ impl Query {
|
||||
return Err(Error::OutOfRange("Block height out of range".into()));
|
||||
}
|
||||
|
||||
let first_txindex = indexer.vecs.transactions.first_txindex.collect_one(height).unwrap();
|
||||
let first_txindex = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.first_txindex
|
||||
.collect_one(height)
|
||||
.unwrap();
|
||||
let next_first_txindex = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
@@ -42,20 +47,12 @@ impl Query {
|
||||
let first: usize = first_txindex.into();
|
||||
let next: usize = next_first_txindex.into();
|
||||
|
||||
let txids: Vec<Txid> = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.txid
|
||||
.collect_range_at(first, next);
|
||||
let txids: Vec<Txid> = indexer.vecs.transactions.txid.collect_range_at(first, next);
|
||||
|
||||
Ok(txids)
|
||||
}
|
||||
|
||||
fn block_txs_by_height(
|
||||
&self,
|
||||
height: Height,
|
||||
start_index: usize,
|
||||
) -> Result<Vec<Transaction>> {
|
||||
fn block_txs_by_height(&self, height: Height, start_index: usize) -> Result<Vec<Transaction>> {
|
||||
let indexer = self.indexer();
|
||||
|
||||
let max_height = self.height();
|
||||
@@ -63,7 +60,12 @@ impl Query {
|
||||
return Err(Error::OutOfRange("Block height out of range".into()));
|
||||
}
|
||||
|
||||
let first_txindex = indexer.vecs.transactions.first_txindex.collect_one(height).unwrap();
|
||||
let first_txindex = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.first_txindex
|
||||
.collect_one(height)
|
||||
.unwrap();
|
||||
let next_first_txindex = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
@@ -100,7 +102,12 @@ impl Query {
|
||||
return Err(Error::OutOfRange("Block height out of range".into()));
|
||||
}
|
||||
|
||||
let first_txindex = indexer.vecs.transactions.first_txindex.collect_one(height).unwrap();
|
||||
let first_txindex = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.first_txindex
|
||||
.collect_one(height)
|
||||
.unwrap();
|
||||
let next_first_txindex = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
|
||||
@@ -29,7 +29,12 @@ impl Query {
|
||||
let blocks = block_stats
|
||||
.into_iter()
|
||||
.map(|stats| {
|
||||
MempoolBlock::new(stats.tx_count, stats.total_vsize, stats.total_fee, stats.fee_range)
|
||||
MempoolBlock::new(
|
||||
stats.tx_count,
|
||||
stats.total_vsize,
|
||||
stats.total_fee,
|
||||
stats.fee_range,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
@@ -27,11 +27,13 @@ impl Query {
|
||||
.day1;
|
||||
|
||||
Ok(iter.collect(|di, ts, h| {
|
||||
rewards_vec.collect_one_flat(di).map(|reward| BlockRewardsEntry {
|
||||
avg_height: h.into(),
|
||||
timestamp: *ts,
|
||||
avg_rewards: *reward,
|
||||
})
|
||||
rewards_vec
|
||||
.collect_one_flat(di)
|
||||
.map(|reward| BlockRewardsEntry {
|
||||
avg_height: h.into(),
|
||||
timestamp: *ts,
|
||||
avg_rewards: *reward,
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,12 @@ impl Query {
|
||||
let current_height = self.height();
|
||||
|
||||
// Get current difficulty
|
||||
let current_difficulty = *indexer.vecs.blocks.difficulty.collect_one(current_height).unwrap();
|
||||
let current_difficulty = *indexer
|
||||
.vecs
|
||||
.blocks
|
||||
.difficulty
|
||||
.collect_one(current_height)
|
||||
.unwrap();
|
||||
|
||||
// Get current hashrate
|
||||
let current_day1 = computer
|
||||
@@ -47,10 +52,7 @@ impl Query {
|
||||
let end_day1 = current_day1;
|
||||
|
||||
// Sample at regular intervals to avoid too many data points
|
||||
let total_days = end_day1
|
||||
.to_usize()
|
||||
.saturating_sub(start_day1.to_usize())
|
||||
+ 1;
|
||||
let total_days = end_day1.to_usize().saturating_sub(start_day1.to_usize()) + 1;
|
||||
let step = (total_days / 200).max(1); // Max ~200 data points
|
||||
|
||||
let hashrate_vec = &computer.mining.hashrate.hash_rate.day1;
|
||||
@@ -60,9 +62,10 @@ impl Query {
|
||||
let mut di = start_day1.to_usize();
|
||||
while di <= end_day1.to_usize() {
|
||||
let day1 = Day1::from(di);
|
||||
if let (Some(hr), Some(timestamp)) =
|
||||
(hashrate_vec.collect_one_flat(day1), timestamp_vec.collect_one(day1))
|
||||
{
|
||||
if let (Some(hr), Some(timestamp)) = (
|
||||
hashrate_vec.collect_one_flat(day1),
|
||||
timestamp_vec.collect_one(day1),
|
||||
) {
|
||||
hashrates.push(HashrateEntry {
|
||||
timestamp,
|
||||
avg_hashrate: *hr as u128,
|
||||
|
||||
@@ -30,16 +30,16 @@ impl Query {
|
||||
|
||||
// For each pool, get cumulative count at end and start, subtract to get range count
|
||||
for (pool_id, pool_vecs) in &computer.pools.vecs {
|
||||
let cumulative = &pool_vecs
|
||||
.blocks_mined
|
||||
.cumulative.height;
|
||||
let cumulative = &pool_vecs.blocks_mined.cumulative.height;
|
||||
|
||||
let count_at_end: u32 = *cumulative.collect_one(current_height).unwrap_or_default();
|
||||
|
||||
let count_at_start: u32 = if start == 0 {
|
||||
0
|
||||
} else {
|
||||
*cumulative.collect_one(Height::from(start - 1)).unwrap_or_default()
|
||||
*cumulative
|
||||
.collect_one(Height::from(start - 1))
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
let block_count = count_at_end.saturating_sub(count_at_start);
|
||||
@@ -98,9 +98,7 @@ impl Query {
|
||||
.get(&slug)
|
||||
.ok_or_else(|| Error::NotFound("Pool data not found".into()))?;
|
||||
|
||||
let cumulative = &pool_vecs
|
||||
.blocks_mined
|
||||
.cumulative.height;
|
||||
let cumulative = &pool_vecs.blocks_mined.cumulative.height;
|
||||
|
||||
// Get total blocks (all time)
|
||||
let total_all: u32 = *cumulative.collect_one(current_height).unwrap_or_default();
|
||||
|
||||
@@ -55,7 +55,12 @@ impl Query {
|
||||
};
|
||||
|
||||
// Get block info for status
|
||||
let height = indexer.vecs.transactions.height.collect_one(txindex).unwrap();
|
||||
let height = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.height
|
||||
.collect_one(txindex)
|
||||
.unwrap();
|
||||
let block_hash = indexer.vecs.blocks.blockhash.read_once(height)?;
|
||||
let block_time = indexer.vecs.blocks.timestamp.collect_one(height).unwrap();
|
||||
|
||||
@@ -191,10 +196,30 @@ impl Query {
|
||||
|
||||
// Get tx metadata using collect_one for PcoVec, read_once for BytesVec
|
||||
let txid = indexer.vecs.transactions.txid.read_once(txindex)?;
|
||||
let height = indexer.vecs.transactions.height.collect_one(txindex).unwrap();
|
||||
let version = indexer.vecs.transactions.txversion.collect_one(txindex).unwrap();
|
||||
let lock_time = indexer.vecs.transactions.rawlocktime.collect_one(txindex).unwrap();
|
||||
let total_size = indexer.vecs.transactions.total_size.collect_one(txindex).unwrap();
|
||||
let height = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.height
|
||||
.collect_one(txindex)
|
||||
.unwrap();
|
||||
let version = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.txversion
|
||||
.collect_one(txindex)
|
||||
.unwrap();
|
||||
let lock_time = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.rawlocktime
|
||||
.collect_one(txindex)
|
||||
.unwrap();
|
||||
let total_size = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.total_size
|
||||
.collect_one(txindex)
|
||||
.unwrap();
|
||||
let first_txinindex = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
@@ -243,7 +268,8 @@ impl Query {
|
||||
let prev_txid = txid_reader.get(prev_txindex.to_usize());
|
||||
|
||||
// Calculate the txoutindex for the prevout
|
||||
let prev_first_txoutindex = first_txoutindex_reader.get(prev_txindex.to_usize());
|
||||
let prev_first_txoutindex =
|
||||
first_txoutindex_reader.get(prev_txindex.to_usize());
|
||||
let prev_txoutindex = prev_first_txoutindex + prev_vout;
|
||||
|
||||
// Get the value of the prevout
|
||||
@@ -312,7 +338,12 @@ impl Query {
|
||||
let reader = self.reader();
|
||||
let computer = self.computer();
|
||||
|
||||
let total_size = indexer.vecs.transactions.total_size.collect_one(txindex).unwrap();
|
||||
let total_size = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.total_size
|
||||
.collect_one(txindex)
|
||||
.unwrap();
|
||||
let position = computer.positions.tx_position.collect_one(txindex).unwrap();
|
||||
|
||||
let buffer = reader.read_raw_bytes(position, *total_size as usize)?;
|
||||
@@ -344,7 +375,12 @@ impl Query {
|
||||
.collect_one(spending_txindex)
|
||||
.unwrap();
|
||||
let block_hash = indexer.vecs.blocks.blockhash.read_once(spending_height)?;
|
||||
let block_time = indexer.vecs.blocks.timestamp.collect_one(spending_height).unwrap();
|
||||
let block_time = indexer
|
||||
.vecs
|
||||
.blocks
|
||||
.timestamp
|
||||
.collect_one(spending_height)
|
||||
.unwrap();
|
||||
|
||||
Ok(TxOutspend {
|
||||
spent: true,
|
||||
|
||||
Reference in New Issue
Block a user