pub struct Query(/* private fields */);Implementations§
Source§impl Query
impl Query
Sourcepub fn address(&self, address: Address) -> Result<AddressStats>
pub fn address(&self, address: Address) -> Result<AddressStats>
Examples found in repository?
examples/query.rs (lines 65-67)
22fn run() -> Result<()> {
23 let bitcoin_dir = Client::default_bitcoin_path();
24 // let bitcoin_dir = Path::new("/Volumes/WD_BLACK1/bitcoin");
25
26 let blocks_dir = bitcoin_dir.join("blocks");
27
28 let outputs_dir = Path::new(&env::var("HOME").unwrap()).join(".brk");
29 fs::create_dir_all(&outputs_dir)?;
30 // let outputs_dir = Path::new("/Volumes/WD_BLACK1/brk");
31
32 let client = Client::new(
33 Client::default_url(),
34 Auth::CookieFile(bitcoin_dir.join(".cookie")),
35 )?;
36
37 let outputs_dir = Path::new(&env::var("HOME").unwrap()).join(".brk");
38 // let outputs_dir = Path::new("../../_outputs");
39
40 let exit = Exit::new();
41 exit.set_ctrlc_handler();
42
43 let reader = Reader::new(blocks_dir, &client);
44
45 let indexer = Indexer::forced_import(&outputs_dir)?;
46
47 let computer = Computer::forced_import(&outputs_dir, &indexer, None)?;
48
49 let mempool = Mempool::new(&client);
50 let mempool_clone = mempool.clone();
51 thread::spawn(move || {
52 mempool_clone.start();
53 });
54
55 let query = Query::build(&reader, &indexer, &computer, Some(mempool));
56
57 dbg!(
58 indexer
59 .stores
60 .addresstype_to_addresshash_to_addressindex
61 .get_unwrap(OutputType::P2WSH)
62 .approximate_len()
63 );
64
65 let _ = dbg!(query.address(Address::from(
66 "bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string(),
67 )));
68
69 let _ = dbg!(query.address_txids(
70 Address::from("bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string()),
71 None,
72 25
73 ));
74
75 let _ = dbg!(query.address_utxos(Address::from(
76 "bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string()
77 )));
78
79 // dbg!(query.search_and_format(MetricSelection {
80 // index: Index::Height,
81 // metrics: vec!["date"].into(),
82 // range: DataRangeFormat::default().set_from(-1),
83 // })?);
84 // dbg!(query.search_and_format(MetricSelection {
85 // index: Index::Height,
86 // metrics: vec!["date", "timestamp"].into(),
87 // range: DataRangeFormat::default().set_from(-10).set_count(5),
88 // })?);
89
90 Ok(())
91}Sourcepub fn address_txids(
&self,
address: Address,
after_txid: Option<Txid>,
limit: usize,
) -> Result<Vec<Txid>>
pub fn address_txids( &self, address: Address, after_txid: Option<Txid>, limit: usize, ) -> Result<Vec<Txid>>
Examples found in repository?
examples/query.rs (lines 69-73)
22fn run() -> Result<()> {
23 let bitcoin_dir = Client::default_bitcoin_path();
24 // let bitcoin_dir = Path::new("/Volumes/WD_BLACK1/bitcoin");
25
26 let blocks_dir = bitcoin_dir.join("blocks");
27
28 let outputs_dir = Path::new(&env::var("HOME").unwrap()).join(".brk");
29 fs::create_dir_all(&outputs_dir)?;
30 // let outputs_dir = Path::new("/Volumes/WD_BLACK1/brk");
31
32 let client = Client::new(
33 Client::default_url(),
34 Auth::CookieFile(bitcoin_dir.join(".cookie")),
35 )?;
36
37 let outputs_dir = Path::new(&env::var("HOME").unwrap()).join(".brk");
38 // let outputs_dir = Path::new("../../_outputs");
39
40 let exit = Exit::new();
41 exit.set_ctrlc_handler();
42
43 let reader = Reader::new(blocks_dir, &client);
44
45 let indexer = Indexer::forced_import(&outputs_dir)?;
46
47 let computer = Computer::forced_import(&outputs_dir, &indexer, None)?;
48
49 let mempool = Mempool::new(&client);
50 let mempool_clone = mempool.clone();
51 thread::spawn(move || {
52 mempool_clone.start();
53 });
54
55 let query = Query::build(&reader, &indexer, &computer, Some(mempool));
56
57 dbg!(
58 indexer
59 .stores
60 .addresstype_to_addresshash_to_addressindex
61 .get_unwrap(OutputType::P2WSH)
62 .approximate_len()
63 );
64
65 let _ = dbg!(query.address(Address::from(
66 "bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string(),
67 )));
68
69 let _ = dbg!(query.address_txids(
70 Address::from("bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string()),
71 None,
72 25
73 ));
74
75 let _ = dbg!(query.address_utxos(Address::from(
76 "bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string()
77 )));
78
79 // dbg!(query.search_and_format(MetricSelection {
80 // index: Index::Height,
81 // metrics: vec!["date"].into(),
82 // range: DataRangeFormat::default().set_from(-1),
83 // })?);
84 // dbg!(query.search_and_format(MetricSelection {
85 // index: Index::Height,
86 // metrics: vec!["date", "timestamp"].into(),
87 // range: DataRangeFormat::default().set_from(-10).set_count(5),
88 // })?);
89
90 Ok(())
91}Sourcepub fn address_utxos(&self, address: Address) -> Result<Vec<Utxo>>
pub fn address_utxos(&self, address: Address) -> Result<Vec<Utxo>>
Examples found in repository?
examples/query.rs (lines 75-77)
22fn run() -> Result<()> {
23 let bitcoin_dir = Client::default_bitcoin_path();
24 // let bitcoin_dir = Path::new("/Volumes/WD_BLACK1/bitcoin");
25
26 let blocks_dir = bitcoin_dir.join("blocks");
27
28 let outputs_dir = Path::new(&env::var("HOME").unwrap()).join(".brk");
29 fs::create_dir_all(&outputs_dir)?;
30 // let outputs_dir = Path::new("/Volumes/WD_BLACK1/brk");
31
32 let client = Client::new(
33 Client::default_url(),
34 Auth::CookieFile(bitcoin_dir.join(".cookie")),
35 )?;
36
37 let outputs_dir = Path::new(&env::var("HOME").unwrap()).join(".brk");
38 // let outputs_dir = Path::new("../../_outputs");
39
40 let exit = Exit::new();
41 exit.set_ctrlc_handler();
42
43 let reader = Reader::new(blocks_dir, &client);
44
45 let indexer = Indexer::forced_import(&outputs_dir)?;
46
47 let computer = Computer::forced_import(&outputs_dir, &indexer, None)?;
48
49 let mempool = Mempool::new(&client);
50 let mempool_clone = mempool.clone();
51 thread::spawn(move || {
52 mempool_clone.start();
53 });
54
55 let query = Query::build(&reader, &indexer, &computer, Some(mempool));
56
57 dbg!(
58 indexer
59 .stores
60 .addresstype_to_addresshash_to_addressindex
61 .get_unwrap(OutputType::P2WSH)
62 .approximate_len()
63 );
64
65 let _ = dbg!(query.address(Address::from(
66 "bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string(),
67 )));
68
69 let _ = dbg!(query.address_txids(
70 Address::from("bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string()),
71 None,
72 25
73 ));
74
75 let _ = dbg!(query.address_utxos(Address::from(
76 "bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string()
77 )));
78
79 // dbg!(query.search_and_format(MetricSelection {
80 // index: Index::Height,
81 // metrics: vec!["date"].into(),
82 // range: DataRangeFormat::default().set_from(-1),
83 // })?);
84 // dbg!(query.search_and_format(MetricSelection {
85 // index: Index::Height,
86 // metrics: vec!["date", "timestamp"].into(),
87 // range: DataRangeFormat::default().set_from(-10).set_count(5),
88 // })?);
89
90 Ok(())
91}pub fn address_mempool_txids(&self, address: Address) -> Result<Vec<Txid>>
Source§impl Query
impl Query
pub fn block_status(&self, hash: &BlockHash) -> Result<BlockStatus>
Source§impl Query
impl Query
pub fn block_by_timestamp(&self, timestamp: Timestamp) -> Result<BlockTimestamp>
Source§impl Query
impl Query
Sourcepub fn cost_basis_cohorts(&self) -> Result<Vec<String>>
pub fn cost_basis_cohorts(&self) -> Result<Vec<String>>
List available cohorts for cost basis distribution.
Sourcepub fn cost_basis_distribution(
&self,
cohort: &str,
date: Date,
) -> Result<CostBasisDistribution>
pub fn cost_basis_distribution( &self, cohort: &str, date: Date, ) -> Result<CostBasisDistribution>
Get the cost basis distribution for a cohort on a specific date.
Sourcepub fn cost_basis_dates(&self, cohort: &str) -> Result<Vec<Date>>
pub fn cost_basis_dates(&self, cohort: &str) -> Result<Vec<Date>>
List available dates for a cohort’s cost basis distribution.
Sourcepub fn cost_basis_formatted(
&self,
cohort: &str,
date: Date,
bucket: CostBasisBucket,
value: CostBasisValue,
) -> Result<CostBasisFormatted>
pub fn cost_basis_formatted( &self, cohort: &str, date: Date, bucket: CostBasisBucket, value: CostBasisValue, ) -> Result<CostBasisFormatted>
Get the formatted cost basis distribution.
Source§impl Query
impl Query
pub fn mempool_info(&self) -> Result<MempoolInfo>
pub fn mempool_txids(&self) -> Result<Vec<Txid>>
pub fn recommended_fees(&self) -> Result<RecommendedFees>
pub fn mempool_blocks(&self) -> Result<Vec<MempoolBlock>>
Source§impl Query
impl Query
pub fn match_metric(&self, metric: &Metric, limit: Limit) -> Vec<&'static str>
pub fn metric_not_found_error(&self, metric: &Metric) -> Error
Sourcepub fn search(
&self,
params: &MetricSelection,
) -> Result<Vec<&'static dyn AnyExportableVec>>
pub fn search( &self, params: &MetricSelection, ) -> Result<Vec<&'static dyn AnyExportableVec>>
Search for vecs matching the given metrics and index. Returns error if no metrics requested or any requested metric is not found.
Sourcepub fn weight(
vecs: &[&dyn AnyExportableVec],
from: Option<i64>,
to: Option<i64>,
) -> usize
pub fn weight( vecs: &[&dyn AnyExportableVec], from: Option<i64>, to: Option<i64>, ) -> usize
Calculate total weight of the vecs for the given range. Applies index-specific cost multipliers for rate limiting.
Sourcepub fn resolve(
&self,
params: MetricSelection,
max_weight: usize,
) -> Result<ResolvedQuery>
pub fn resolve( &self, params: MetricSelection, max_weight: usize, ) -> Result<ResolvedQuery>
Resolve query metadata without formatting (cheap).
Use with format for lazy formatting after ETag check.
Sourcepub fn format(&self, resolved: ResolvedQuery) -> Result<MetricOutput>
pub fn format(&self, resolved: ResolvedQuery) -> Result<MetricOutput>
Format a resolved query (expensive). Call after ETag/cache checks to avoid unnecessary work.
pub fn metric_to_index_to_vec(&self) -> &BTreeMap<&str, IndexToVec<'_>>
pub fn index_to_metric_to_vec(&self) -> &BTreeMap<Index, MetricToVec<'_>>
pub fn metric_count(&self) -> DetailedMetricCount
pub fn indexes(&self) -> &[IndexInfo]
pub fn metrics(&self, pagination: Pagination) -> PaginatedMetrics
pub fn metrics_catalog(&self) -> &TreeNode
pub fn index_to_vecids( &self, paginated_index: PaginationIndex, ) -> Option<&[&str]>
pub fn metric_to_indexes(&self, metric: Metric) -> Option<&Vec<Index>>
Source§impl Query
impl Query
Sourcepub fn format_legacy(
&self,
resolved: ResolvedQuery,
) -> Result<MetricOutputLegacy>
pub fn format_legacy( &self, resolved: ResolvedQuery, ) -> Result<MetricOutputLegacy>
Deprecated - format a resolved query as legacy output (expensive).
Source§impl Query
impl Query
pub fn block_fee_rates( &self, _time_period: TimePeriod, ) -> Result<Vec<BlockFeeRatesEntry>>
Source§impl Query
impl Query
pub fn block_fees(&self, time_period: TimePeriod) -> Result<Vec<BlockFeesEntry>>
Source§impl Query
impl Query
pub fn block_rewards( &self, time_period: TimePeriod, ) -> Result<Vec<BlockRewardsEntry>>
Source§impl Query
impl Query
pub fn block_sizes_weights( &self, time_period: TimePeriod, ) -> Result<BlockSizesWeights>
Source§impl Query
impl Query
pub fn difficulty_adjustment(&self) -> Result<DifficultyAdjustment>
Source§impl Query
impl Query
pub fn difficulty_adjustments( &self, time_period: Option<TimePeriod>, ) -> Result<Vec<DifficultyAdjustmentEntry>>
Source§impl Query
impl Query
pub fn hashrate( &self, time_period: Option<TimePeriod>, ) -> Result<HashrateSummary>
Source§impl Query
impl Query
pub fn mining_pools(&self, time_period: TimePeriod) -> Result<PoolsSummary>
pub fn all_pools(&self) -> Vec<PoolInfo>
pub fn pool_detail(&self, slug: PoolSlug) -> Result<PoolDetail>
Source§impl Query
impl Query
pub fn reward_stats(&self, block_count: usize) -> Result<RewardStats>
Source§impl Query
impl Query
pub fn transaction(&self, _: TxidParam) -> Result<Transaction>
pub fn transaction_status(&self, _: TxidParam) -> Result<TxStatus>
pub fn transaction_hex(&self, _: TxidParam) -> Result<String>
pub fn outspend(&self, _: TxidParam, vout: Vout) -> Result<TxOutspend>
pub fn outspends(&self, _: TxidParam) -> Result<Vec<TxOutspend>>
pub fn transaction_by_index(&self, txindex: TxIndex) -> Result<Transaction>
Source§impl Query
impl Query
Sourcepub fn build(
reader: &Reader,
indexer: &Indexer,
computer: &Computer,
mempool: Option<Mempool>,
) -> Self
pub fn build( reader: &Reader, indexer: &Indexer, computer: &Computer, mempool: Option<Mempool>, ) -> Self
Examples found in repository?
examples/query.rs (line 55)
22fn run() -> Result<()> {
23 let bitcoin_dir = Client::default_bitcoin_path();
24 // let bitcoin_dir = Path::new("/Volumes/WD_BLACK1/bitcoin");
25
26 let blocks_dir = bitcoin_dir.join("blocks");
27
28 let outputs_dir = Path::new(&env::var("HOME").unwrap()).join(".brk");
29 fs::create_dir_all(&outputs_dir)?;
30 // let outputs_dir = Path::new("/Volumes/WD_BLACK1/brk");
31
32 let client = Client::new(
33 Client::default_url(),
34 Auth::CookieFile(bitcoin_dir.join(".cookie")),
35 )?;
36
37 let outputs_dir = Path::new(&env::var("HOME").unwrap()).join(".brk");
38 // let outputs_dir = Path::new("../../_outputs");
39
40 let exit = Exit::new();
41 exit.set_ctrlc_handler();
42
43 let reader = Reader::new(blocks_dir, &client);
44
45 let indexer = Indexer::forced_import(&outputs_dir)?;
46
47 let computer = Computer::forced_import(&outputs_dir, &indexer, None)?;
48
49 let mempool = Mempool::new(&client);
50 let mempool_clone = mempool.clone();
51 thread::spawn(move || {
52 mempool_clone.start();
53 });
54
55 let query = Query::build(&reader, &indexer, &computer, Some(mempool));
56
57 dbg!(
58 indexer
59 .stores
60 .addresstype_to_addresshash_to_addressindex
61 .get_unwrap(OutputType::P2WSH)
62 .approximate_len()
63 );
64
65 let _ = dbg!(query.address(Address::from(
66 "bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string(),
67 )));
68
69 let _ = dbg!(query.address_txids(
70 Address::from("bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string()),
71 None,
72 25
73 ));
74
75 let _ = dbg!(query.address_utxos(Address::from(
76 "bc1qwzrryqr3ja8w7hnja2spmkgfdcgvqwp5swz4af4ngsjecfz0w0pqud7k38".to_string()
77 )));
78
79 // dbg!(query.search_and_format(MetricSelection {
80 // index: Index::Height,
81 // metrics: vec!["date"].into(),
82 // range: DataRangeFormat::default().set_from(-1),
83 // })?);
84 // dbg!(query.search_and_format(MetricSelection {
85 // index: Index::Height,
86 // metrics: vec!["date", "timestamp"].into(),
87 // range: DataRangeFormat::default().set_from(-10).set_count(5),
88 // })?);
89
90 Ok(())
91}pub fn reader(&self) -> &Reader
pub fn client(&self) -> &Client
pub fn blocks_dir(&self) -> &Path
pub fn indexer(&self) -> &Indexer
pub fn computer(&self) -> &Computer
pub fn mempool(&self) -> Option<&Mempool>
pub fn vecs(&self) -> &'static Vecs<'static>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Query
impl !RefUnwindSafe for Query
impl Send for Query
impl Sync for Query
impl Unpin for Query
impl !UnwindSafe for Query
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more