mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -127,9 +127,17 @@ pub fn generate_api_methods(output: &mut String, endpoints: &[Endpoint]) {
|
||||
writeln!(output, " if (format === 'csv') {{").unwrap();
|
||||
writeln!(output, " return this.getText(path, {{ signal }});").unwrap();
|
||||
writeln!(output, " }}").unwrap();
|
||||
writeln!(output, " return this.getJson(path, {{ signal, onUpdate }});").unwrap();
|
||||
writeln!(
|
||||
output,
|
||||
" return this.getJson(path, {{ signal, onUpdate }});"
|
||||
)
|
||||
.unwrap();
|
||||
} else {
|
||||
writeln!(output, " return this.getJson(path, {{ signal, onUpdate }});").unwrap();
|
||||
writeln!(
|
||||
output,
|
||||
" return this.getJson(path, {{ signal, onUpdate }});"
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -401,6 +401,4 @@ impl Stores {
|
||||
.remove(AddrIndexTxIndex::from((addr_index, tx_index)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -252,7 +252,6 @@ impl Query {
|
||||
let fa_pct90 = fad.pct90.height.collect_range_at(begin, end);
|
||||
let fa_max = fad.max.height.collect_range_at(begin, end);
|
||||
|
||||
|
||||
// Bulk read median time window
|
||||
let median_start = begin.saturating_sub(10);
|
||||
let median_timestamps = indexer
|
||||
@@ -272,20 +271,47 @@ impl Query {
|
||||
|
||||
// Single reader for header + coinbase (adjacent in blk file)
|
||||
let varint_len = Self::compact_size_len(tx_count) as usize;
|
||||
let (raw_header, coinbase_raw, coinbase_address, coinbase_addresses, coinbase_signature, coinbase_signature_ascii, scriptsig_bytes) = match reader.reader_at(positions[i]) {
|
||||
let (
|
||||
raw_header,
|
||||
coinbase_raw,
|
||||
coinbase_address,
|
||||
coinbase_addresses,
|
||||
coinbase_signature,
|
||||
coinbase_signature_ascii,
|
||||
scriptsig_bytes,
|
||||
) = match reader.reader_at(positions[i]) {
|
||||
Ok(mut blk) => {
|
||||
let mut header_buf = [0u8; HEADER_SIZE];
|
||||
if blk.read_exact(&mut header_buf).is_err() {
|
||||
([0u8; HEADER_SIZE], String::new(), None, vec![], String::new(), String::new(), vec![])
|
||||
(
|
||||
[0u8; HEADER_SIZE],
|
||||
String::new(),
|
||||
None,
|
||||
vec![],
|
||||
String::new(),
|
||||
String::new(),
|
||||
vec![],
|
||||
)
|
||||
} else {
|
||||
// Skip tx count varint
|
||||
let mut skip = [0u8; 5];
|
||||
let _ = blk.read_exact(&mut skip[..varint_len]);
|
||||
let coinbase = Self::parse_coinbase_from_read(blk);
|
||||
(header_buf, coinbase.0, coinbase.1, coinbase.2, coinbase.3, coinbase.4, coinbase.5)
|
||||
(
|
||||
header_buf, coinbase.0, coinbase.1, coinbase.2, coinbase.3, coinbase.4,
|
||||
coinbase.5,
|
||||
)
|
||||
}
|
||||
}
|
||||
Err(_) => ([0u8; HEADER_SIZE], String::new(), None, vec![], String::new(), String::new(), vec![]),
|
||||
Err(_) => (
|
||||
[0u8; HEADER_SIZE],
|
||||
String::new(),
|
||||
None,
|
||||
vec![],
|
||||
String::new(),
|
||||
String::new(),
|
||||
vec![],
|
||||
),
|
||||
};
|
||||
let header = Self::decode_header(&raw_header)?;
|
||||
|
||||
@@ -517,12 +543,20 @@ impl Query {
|
||||
fn parse_coinbase_from_read(
|
||||
reader: impl Read,
|
||||
) -> (String, Option<String>, Vec<String>, String, String, Vec<u8>) {
|
||||
let empty = (String::new(), None, vec![], String::new(), String::new(), vec![]);
|
||||
let empty = (
|
||||
String::new(),
|
||||
None,
|
||||
vec![],
|
||||
String::new(),
|
||||
String::new(),
|
||||
vec![],
|
||||
);
|
||||
|
||||
let tx = match bitcoin::Transaction::consensus_decode(&mut bitcoin::io::FromStd::new(reader)) {
|
||||
Ok(tx) => tx,
|
||||
Err(_) => return empty,
|
||||
};
|
||||
let tx =
|
||||
match bitcoin::Transaction::consensus_decode(&mut bitcoin::io::FromStd::new(reader)) {
|
||||
Ok(tx) => tx,
|
||||
Err(_) => return empty,
|
||||
};
|
||||
|
||||
let scriptsig_bytes: Vec<u8> = tx
|
||||
.input
|
||||
@@ -532,10 +566,7 @@ impl Query {
|
||||
|
||||
let coinbase_raw = scriptsig_bytes.to_lower_hex_string();
|
||||
|
||||
let coinbase_signature_ascii: String = scriptsig_bytes
|
||||
.iter()
|
||||
.map(|&b| b as char)
|
||||
.collect();
|
||||
let coinbase_signature_ascii: String = scriptsig_bytes.iter().map(|&b| b as char).collect();
|
||||
|
||||
let mut coinbase_addresses: Vec<String> = tx
|
||||
.output
|
||||
|
||||
@@ -9,7 +9,12 @@ impl Query {
|
||||
pub fn block_fee_rates(&self, time_period: TimePeriod) -> Result<Vec<BlockFeeRatesEntry>> {
|
||||
let bw = BlockWindow::new(self, time_period);
|
||||
let computer = self.computer();
|
||||
let frd = &computer.transactions.fees.effective_fee_rate.distribution.block;
|
||||
let frd = &computer
|
||||
.transactions
|
||||
.fees
|
||||
.effective_fee_rate
|
||||
.distribution
|
||||
.block;
|
||||
|
||||
let min = frd.min.height.collect_range_at(bw.start, bw.end);
|
||||
let pct10 = frd.pct10.height.collect_range_at(bw.start, bw.end);
|
||||
|
||||
@@ -62,10 +62,7 @@ impl Query {
|
||||
let mut hashrates = Vec::with_capacity(total_days / step + 1);
|
||||
let mut di = start_day1.to_usize();
|
||||
while di <= end_day1.to_usize() {
|
||||
if let (Some(Some(hr)), Some(timestamp)) = (
|
||||
hr_cursor.get(di),
|
||||
ts_cursor.get(di),
|
||||
) {
|
||||
if let (Some(Some(hr)), Some(timestamp)) = (hr_cursor.get(di), ts_cursor.get(di)) {
|
||||
hashrates.push(HashrateEntry {
|
||||
timestamp,
|
||||
avg_hashrate: *hr as u128,
|
||||
|
||||
@@ -53,8 +53,18 @@ impl Query {
|
||||
};
|
||||
|
||||
// Get block info for status
|
||||
let height = indexer.vecs.transactions.height.collect_one(tx_index).unwrap();
|
||||
let block_hash = indexer.vecs.blocks.blockhash.reader().get(height.to_usize());
|
||||
let height = indexer
|
||||
.vecs
|
||||
.transactions
|
||||
.height
|
||||
.collect_one(tx_index)
|
||||
.unwrap();
|
||||
let block_hash = indexer
|
||||
.vecs
|
||||
.blocks
|
||||
.blockhash
|
||||
.reader()
|
||||
.get(height.to_usize());
|
||||
let block_time = indexer.vecs.blocks.timestamp.collect_one(height).unwrap();
|
||||
|
||||
Ok(TxStatus {
|
||||
@@ -110,7 +120,10 @@ impl Query {
|
||||
}
|
||||
|
||||
pub fn outspend(&self, txid: &Txid, vout: Vout) -> Result<TxOutspend> {
|
||||
if self.mempool().is_some_and(|m| m.get_txs().contains_key(txid)) {
|
||||
if self
|
||||
.mempool()
|
||||
.is_some_and(|m| m.get_txs().contains_key(txid))
|
||||
{
|
||||
return Ok(TxOutspend::UNSPENT);
|
||||
}
|
||||
let (_, first_txout, output_count) = self.resolve_tx_outputs(txid)?;
|
||||
@@ -150,8 +163,7 @@ impl Query {
|
||||
}
|
||||
|
||||
let spending_tx_index = input_tx_cursor.get(usize::from(txin_index)).unwrap();
|
||||
let spending_first_txin =
|
||||
first_txin_cursor.get(spending_tx_index.to_usize()).unwrap();
|
||||
let spending_first_txin = first_txin_cursor.get(spending_tx_index.to_usize()).unwrap();
|
||||
let vin = Vin::from(usize::from(txin_index) - usize::from(spending_first_txin));
|
||||
let spending_txid = txid_reader.get(spending_tx_index.to_usize());
|
||||
let spending_height = height_cursor.get(spending_tx_index.to_usize()).unwrap();
|
||||
|
||||
@@ -4,10 +4,7 @@ use std::{
|
||||
any::Any,
|
||||
net::SocketAddr,
|
||||
path::PathBuf,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::AtomicU64,
|
||||
},
|
||||
sync::{Arc, atomic::AtomicU64},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
|
||||
@@ -377,5 +377,4 @@ where
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ pub struct CpfpInfo {
|
||||
pub adjusted_vsize: Option<VSize>,
|
||||
}
|
||||
|
||||
|
||||
/// A transaction in a CPFP relationship
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct CpfpEntry {
|
||||
|
||||
@@ -17,7 +17,13 @@ use super::{Bitcoin, CentsSigned, Close, High, Sats, StoredF32, StoredF64};
|
||||
|
||||
/// US Dollar amount
|
||||
#[derive(Debug, Default, Clone, Copy, Deref, Serialize, Deserialize, Pco, JsonSchema)]
|
||||
#[schemars(example = 0.0, example = 100.50, example = 30_000.0, example = 69_000.0, example = 84_342.12)]
|
||||
#[schemars(
|
||||
example = &0.0,
|
||||
example = &100.50,
|
||||
example = &30_000.0,
|
||||
example = &69_000.0,
|
||||
example = &84_342.12
|
||||
)]
|
||||
pub struct Dollars(f64);
|
||||
|
||||
impl Hash for Dollars {
|
||||
|
||||
@@ -11,7 +11,14 @@ use super::{Sats, VSize, Weight};
|
||||
|
||||
/// Fee rate in sat/vB
|
||||
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, Pco, JsonSchema)]
|
||||
#[schemars(example = 1.0, example = 2.5, example = 10.14, example = 25.0, example = 302.11)]
|
||||
#[schemars(
|
||||
example = &0.1,
|
||||
example = &1.0,
|
||||
example = &2.5,
|
||||
example = &10.14,
|
||||
example = &25.0,
|
||||
example = &302.11
|
||||
)]
|
||||
pub struct FeeRate(f64);
|
||||
|
||||
impl FeeRate {
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Formattable, Pco};
|
||||
|
||||
/// Transaction locktime. Values below 500,000,000 are interpreted as block heights; values at or above are Unix timestamps.
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Pco, JsonSchema)]
|
||||
#[schemars(example = 0, example = 840000, example = 840001, example = 1713571200, example = 4294967295_u32)]
|
||||
#[schemars(example = &0, example = &840000, example = &840001, example = &1713571200)]
|
||||
pub struct RawLockTime(u32);
|
||||
|
||||
impl From<LockTime> for RawLockTime {
|
||||
|
||||
@@ -31,11 +31,11 @@ use super::{Bitcoin, Cents, Dollars, Height};
|
||||
JsonSchema,
|
||||
)]
|
||||
#[schemars(
|
||||
example = 0,
|
||||
example = 546,
|
||||
example = 10000,
|
||||
example = 100_000_000,
|
||||
example = 2_100_000_000_000_000_u64
|
||||
example = &0,
|
||||
example = &546,
|
||||
example = &10000,
|
||||
example = &100_000_000,
|
||||
example = &2_100_000_000_000_000_u64
|
||||
)]
|
||||
pub struct Sats(u64);
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ use super::Date;
|
||||
JsonSchema,
|
||||
)]
|
||||
#[schemars(
|
||||
example = 1231006505,
|
||||
example = 1672531200,
|
||||
example = 1713571200,
|
||||
example = 1743631892,
|
||||
example = 1759000868
|
||||
example = &1231006505,
|
||||
example = &1672531200,
|
||||
example = &1713571200,
|
||||
example = &1743631892,
|
||||
example = &1759000868
|
||||
)]
|
||||
pub struct Timestamp(u32);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::{
|
||||
FeeRate, RawLockTime, Sats, TxIn, TxIndex, TxOut, TxStatus, TxVersionRaw, Txid, VSize,
|
||||
Weight,
|
||||
FeeRate, RawLockTime, Sats, TxIn, TxIndex, TxOut, TxStatus, TxVersionRaw, Txid, VSize, Weight,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -6,7 +6,13 @@ use serde::{Deserialize, Serialize};
|
||||
/// Unlike TxVersion (u8, indexed), this preserves non-standard values
|
||||
/// used in coinbase txs for miner signaling/branding.
|
||||
#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[schemars(example = 1, example = 2, example = 3, example = 536_870_912, example = 805_306_368)]
|
||||
#[schemars(
|
||||
example = &1,
|
||||
example = &2,
|
||||
example = &3,
|
||||
example = &536_870_912,
|
||||
example = &805_306_368
|
||||
)]
|
||||
pub struct TxVersionRaw(i32);
|
||||
|
||||
impl From<bitcoin::transaction::Version> for TxVersionRaw {
|
||||
|
||||
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(
|
||||
Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, JsonSchema,
|
||||
)]
|
||||
#[schemars(example = 0, example = 1, example = 2, example = 5, example = 10)]
|
||||
#[schemars(example = &0, example = &1, example = &2, example = &5, example = &10)]
|
||||
pub struct Vin(u16);
|
||||
|
||||
impl Vin {
|
||||
|
||||
@@ -20,7 +20,7 @@ use vecdb::{Bytes, Formattable};
|
||||
Bytes,
|
||||
Hash,
|
||||
)]
|
||||
#[schemars(example = 0, example = 1, example = 2, example = 5, example = 10)]
|
||||
#[schemars(example = &0, example = &1, example = &2, example = &5, example = &10)]
|
||||
pub struct Vout(u16);
|
||||
|
||||
impl Vout {
|
||||
|
||||
@@ -23,7 +23,13 @@ use crate::Weight;
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
#[schemars(example = 110, example = 140, example = 225, example = 500_000, example = 998_368)]
|
||||
#[schemars(
|
||||
example = &110,
|
||||
example = &140,
|
||||
example = &225,
|
||||
example = &500_000,
|
||||
example = &998_368
|
||||
)]
|
||||
pub struct VSize(u64);
|
||||
|
||||
impl VSize {
|
||||
|
||||
@@ -23,7 +23,13 @@ use crate::VSize;
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
#[schemars(example = 396, example = 561, example = 900, example = 2_000_000, example = 3_993_472)]
|
||||
#[schemars(
|
||||
example = &396,
|
||||
example = &561,
|
||||
example = &900,
|
||||
example = &2_000_000,
|
||||
example = &3_993_472
|
||||
)]
|
||||
pub struct Weight(u64);
|
||||
|
||||
impl Weight {
|
||||
|
||||
Reference in New Issue
Block a user