mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-25 01:04:47 -07:00
global: snapshot
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
|
||||
use brk_types::RecommendedFees;
|
||||
|
||||
use super::{fees, stats::{self, BlockStats}};
|
||||
@@ -36,4 +38,14 @@ impl Snapshot {
|
||||
fees,
|
||||
}
|
||||
}
|
||||
|
||||
/// Hash of the first projected block (the one about to be mined).
|
||||
pub fn next_block_hash(&self) -> u64 {
|
||||
let Some(block) = self.blocks.first() else {
|
||||
return 0;
|
||||
};
|
||||
let mut hasher = DefaultHasher::new();
|
||||
block.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::{
|
||||
hash::{DefaultHasher, Hash, Hasher},
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicBool, AtomicU64, Ordering},
|
||||
@@ -9,7 +10,7 @@ use std::{
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_rpc::Client;
|
||||
use brk_types::{MempoolEntryInfo, MempoolInfo, TxWithHex, Txid, TxidPrefix};
|
||||
use brk_types::{AddressBytes, MempoolEntryInfo, MempoolInfo, TxWithHex, Txid, TxidPrefix};
|
||||
use derive_more::Deref;
|
||||
use parking_lot::{RwLock, RwLockReadGuard};
|
||||
use rustc_hash::FxHashMap;
|
||||
@@ -87,6 +88,20 @@ impl MempoolInner {
|
||||
self.snapshot.read().block_stats.clone()
|
||||
}
|
||||
|
||||
pub fn next_block_hash(&self) -> u64 {
|
||||
self.snapshot.read().next_block_hash()
|
||||
}
|
||||
|
||||
pub fn address_hash(&self, address: &AddressBytes) -> u64 {
|
||||
let addresses = self.addresses.read();
|
||||
let Some((stats, _)) = addresses.get(address) else {
|
||||
return 0;
|
||||
};
|
||||
let mut hasher = DefaultHasher::new();
|
||||
stats.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
|
||||
pub fn get_txs(&self) -> RwLockReadGuard<'_, TxStore> {
|
||||
self.txs.read()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user