mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-26 07:39:59 -07:00
query + server: more endpoints/methods/helpers
This commit is contained in:
@@ -82,7 +82,6 @@ pub struct Vecs {
|
||||
pub txindex_to_input_count: EagerVec<PcoVec<TxIndex, StoredU64>>,
|
||||
pub txindex_to_output_count: EagerVec<PcoVec<TxIndex, StoredU64>>,
|
||||
pub txindex_to_txindex: LazyVecFrom1<TxIndex, TxIndex, TxIndex, Txid>,
|
||||
pub txinindex_to_txindex: EagerVec<PcoVec<TxInIndex, TxIndex>>,
|
||||
pub txinindex_to_txinindex: LazyVecFrom1<TxInIndex, TxInIndex, TxInIndex, OutPoint>,
|
||||
pub txinindex_to_txoutindex: EagerVec<PcoVec<TxInIndex, TxOutIndex>>,
|
||||
pub txoutindex_to_txoutindex: LazyVecFrom1<TxOutIndex, TxOutIndex, TxOutIndex, Sats>,
|
||||
@@ -122,7 +121,6 @@ impl Vecs {
|
||||
}
|
||||
|
||||
let this = Self {
|
||||
txinindex_to_txindex: eager!("txindex"),
|
||||
txinindex_to_txoutindex: eager!("txoutindex"),
|
||||
txoutindex_to_txoutindex: lazy!("txoutindex", indexer.vecs.txout.txoutindex_to_value),
|
||||
txinindex_to_txinindex: lazy!("txinindex", indexer.vecs.txin.txinindex_to_outpoint),
|
||||
@@ -253,13 +251,6 @@ impl Vecs {
|
||||
// TxInIndex
|
||||
// ---
|
||||
|
||||
self.txinindex_to_txindex.compute_finer(
|
||||
starting_indexes.txinindex,
|
||||
&indexer.vecs.tx.txindex_to_first_txinindex,
|
||||
&indexer.vecs.txin.txinindex_to_outpoint,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let txindex_to_first_txoutindex = &indexer.vecs.tx.txindex_to_first_txoutindex;
|
||||
let txindex_to_first_txoutindex_reader = txindex_to_first_txoutindex.create_reader();
|
||||
self.txinindex_to_txoutindex.compute_transform(
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_store::AnyStore;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Address, AddressBytes, Height, OutputType, PoolId, Pools, TxOutIndex, pools};
|
||||
use brk_types::{Address, AddressBytes, Height, OutputType, PoolSlug, Pools, TxOutIndex, pools};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{
|
||||
AnyStoredVec, AnyVec, BytesVec, Database, Exit, GenericStoredVec, ImportableVec, IterableVec,
|
||||
@@ -24,8 +24,8 @@ pub struct Vecs {
|
||||
db: Database,
|
||||
pools: &'static Pools,
|
||||
|
||||
pub height_to_pool: BytesVec<Height, PoolId>,
|
||||
pub vecs: BTreeMap<PoolId, vecs::Vecs>,
|
||||
pub height_to_pool: BytesVec<Height, PoolSlug>,
|
||||
pub vecs: BTreeMap<PoolSlug, vecs::Vecs>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
@@ -48,13 +48,13 @@ impl Vecs {
|
||||
.map(|pool| {
|
||||
vecs::Vecs::forced_import(
|
||||
&db,
|
||||
pool.id,
|
||||
pool.slug,
|
||||
pools,
|
||||
version + Version::ZERO,
|
||||
indexes,
|
||||
price,
|
||||
)
|
||||
.map(|vecs| (pool.id, vecs))
|
||||
.map(|vecs| (pool.slug, vecs))
|
||||
})
|
||||
.collect::<Result<BTreeMap<_, _>>>()?,
|
||||
pools,
|
||||
@@ -126,20 +126,36 @@ impl Vecs {
|
||||
let mut txindex_to_first_txoutindex_iter =
|
||||
indexer.vecs.tx.txindex_to_first_txoutindex.iter()?;
|
||||
let mut txindex_to_output_count_iter = indexes.txindex_to_output_count.iter();
|
||||
let mut txoutindex_to_outputtype_iter = indexer.vecs.txout.txoutindex_to_outputtype.iter()?;
|
||||
let mut txoutindex_to_outputtype_iter =
|
||||
indexer.vecs.txout.txoutindex_to_outputtype.iter()?;
|
||||
let mut txoutindex_to_typeindex_iter = indexer.vecs.txout.txoutindex_to_typeindex.iter()?;
|
||||
let mut p2pk65addressindex_to_p2pk65bytes_iter =
|
||||
indexer.vecs.address.p2pk65addressindex_to_p2pk65bytes.iter()?;
|
||||
let mut p2pk33addressindex_to_p2pk33bytes_iter =
|
||||
indexer.vecs.address.p2pk33addressindex_to_p2pk33bytes.iter()?;
|
||||
let mut p2pkhaddressindex_to_p2pkhbytes_iter =
|
||||
indexer.vecs.address.p2pkhaddressindex_to_p2pkhbytes.iter()?;
|
||||
let mut p2pk65addressindex_to_p2pk65bytes_iter = indexer
|
||||
.vecs
|
||||
.address
|
||||
.p2pk65addressindex_to_p2pk65bytes
|
||||
.iter()?;
|
||||
let mut p2pk33addressindex_to_p2pk33bytes_iter = indexer
|
||||
.vecs
|
||||
.address
|
||||
.p2pk33addressindex_to_p2pk33bytes
|
||||
.iter()?;
|
||||
let mut p2pkhaddressindex_to_p2pkhbytes_iter = indexer
|
||||
.vecs
|
||||
.address
|
||||
.p2pkhaddressindex_to_p2pkhbytes
|
||||
.iter()?;
|
||||
let mut p2shaddressindex_to_p2shbytes_iter =
|
||||
indexer.vecs.address.p2shaddressindex_to_p2shbytes.iter()?;
|
||||
let mut p2wpkhaddressindex_to_p2wpkhbytes_iter =
|
||||
indexer.vecs.address.p2wpkhaddressindex_to_p2wpkhbytes.iter()?;
|
||||
let mut p2wshaddressindex_to_p2wshbytes_iter =
|
||||
indexer.vecs.address.p2wshaddressindex_to_p2wshbytes.iter()?;
|
||||
let mut p2wpkhaddressindex_to_p2wpkhbytes_iter = indexer
|
||||
.vecs
|
||||
.address
|
||||
.p2wpkhaddressindex_to_p2wpkhbytes
|
||||
.iter()?;
|
||||
let mut p2wshaddressindex_to_p2wshbytes_iter = indexer
|
||||
.vecs
|
||||
.address
|
||||
.p2wshaddressindex_to_p2wshbytes
|
||||
.iter()?;
|
||||
let mut p2traddressindex_to_p2trbytes_iter =
|
||||
indexer.vecs.address.p2traddressindex_to_p2trbytes.iter()?;
|
||||
let mut p2aaddressindex_to_p2abytes_iter =
|
||||
@@ -201,7 +217,7 @@ impl Vecs {
|
||||
.or_else(|| self.pools.find_from_coinbase_tag(&coinbase_tag))
|
||||
.unwrap_or(unknown);
|
||||
|
||||
self.height_to_pool.push_if_needed(height, pool.id)?;
|
||||
self.height_to_pool.push_if_needed(height, pool.slug)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, PoolId, Pools, Sats, StoredF32, StoredU16, StoredU32};
|
||||
use brk_types::{Height, PoolSlug, Pools, Sats, StoredF32, StoredU16, StoredU32};
|
||||
use vecdb::{Database, Exit, GenericStoredVec, IterableVec, VecIndex, Version};
|
||||
|
||||
use crate::{
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
id: PoolId,
|
||||
slug: PoolSlug,
|
||||
|
||||
pub indexes_to_blocks_mined: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_1w_blocks_mined: ComputedVecsFromDateIndex<StoredU32>,
|
||||
@@ -36,15 +36,13 @@ pub struct Vecs {
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
id: PoolId,
|
||||
pools: &Pools,
|
||||
slug: PoolSlug,
|
||||
_pools: &Pools,
|
||||
parent_version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
let pool = pools.get(id);
|
||||
let name = pool.serialized_id();
|
||||
let suffix = |s: &str| format!("{name}_{s}");
|
||||
let suffix = |s: &str| format!("{}_{s}", slug.to_string());
|
||||
let compute_dollars = price.is_some();
|
||||
let version = parent_version + Version::ZERO;
|
||||
|
||||
@@ -65,7 +63,7 @@ impl Vecs {
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
id,
|
||||
slug,
|
||||
indexes_to_blocks_mined: ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
&suffix("blocks_mined"),
|
||||
@@ -118,7 +116,7 @@ impl Vecs {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
height_to_pool: &impl IterableVec<Height, PoolId>,
|
||||
height_to_pool: &impl IterableVec<Height, PoolSlug>,
|
||||
chain: &chain::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
@@ -131,7 +129,7 @@ impl Vecs {
|
||||
|(h, id, ..)| {
|
||||
(
|
||||
h,
|
||||
if id == self.id {
|
||||
if id == self.slug {
|
||||
StoredU32::ONE
|
||||
} else {
|
||||
StoredU32::ZERO
|
||||
|
||||
Reference in New Issue
Block a user