Skip to main content

Query

Struct Query 

Source
pub struct Query(/* private fields */);

Implementations§

Source§

impl Query

Source

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}
Source

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}
Source

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}
Source

pub fn address_mempool_txids(&self, address: Address) -> Result<Vec<Txid>>

Source§

impl Query

Source

pub fn block(&self, hash: &BlockHash) -> Result<BlockInfo>

Source

pub fn block_by_height(&self, height: Height) -> Result<BlockInfo>

Source

pub fn blocks(&self, start_height: Option<Height>) -> Result<Vec<BlockInfo>>

Source

pub fn height_by_hash(&self, hash: &BlockHash) -> Result<Height>

Source§

impl Query

Source

pub fn block_raw(&self, hash: &BlockHash) -> Result<Vec<u8>>

Source§

impl Query

Source§

impl Query

Source§

impl Query

Source

pub fn block_txids(&self, hash: &BlockHash) -> Result<Vec<Txid>>

Source

pub fn block_txs( &self, hash: &BlockHash, start_index: TxIndex, ) -> Result<Vec<Transaction>>

Source

pub fn block_txid_at_index( &self, hash: &BlockHash, index: TxIndex, ) -> Result<Txid>

Source§

impl Query

Source

pub fn cost_basis_cohorts(&self) -> Result<Vec<String>>

List available cohorts for cost basis distribution.

Source

pub fn cost_basis_distribution( &self, cohort: &str, date: Date, ) -> Result<CostBasisDistribution>

Get the cost basis distribution for a cohort on a specific date.

Source

pub fn cost_basis_dates(&self, cohort: &str) -> Result<Vec<Date>>

List available dates for a cohort’s cost basis distribution.

Source

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

Source§

impl Query

Source

pub fn match_metric(&self, metric: &Metric, limit: Limit) -> Vec<&'static str>

Source

pub fn metric_not_found_error(&self, metric: &Metric) -> Error

Source

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.

Source

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.

Source

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.

Source

pub fn format(&self, resolved: ResolvedQuery) -> Result<MetricOutput>

Format a resolved query (expensive). Call after ETag/cache checks to avoid unnecessary work.

Source

pub fn metric_to_index_to_vec(&self) -> &BTreeMap<&str, IndexToVec<'_>>

Source

pub fn index_to_metric_to_vec(&self) -> &BTreeMap<Index, MetricToVec<'_>>

Source

pub fn metric_count(&self) -> DetailedMetricCount

Source

pub fn indexes(&self) -> &[IndexInfo]

Source

pub fn metrics(&self, pagination: Pagination) -> PaginatedMetrics

Source

pub fn metrics_catalog(&self) -> &TreeNode

Source

pub fn index_to_vecids( &self, paginated_index: PaginationIndex, ) -> Option<&[&str]>

Source

pub fn metric_to_indexes(&self, metric: Metric) -> Option<&Vec<Index>>

Source§

impl Query

Source

pub fn format_legacy( &self, resolved: ResolvedQuery, ) -> Result<MetricOutputLegacy>

Deprecated - format a resolved query as legacy output (expensive).

Source§

impl Query

Source

pub fn block_fee_rates( &self, _time_period: TimePeriod, ) -> Result<Vec<BlockFeeRatesEntry>>

Source§

impl Query

Source

pub fn block_fees(&self, time_period: TimePeriod) -> Result<Vec<BlockFeesEntry>>

Source§

impl Query

Source

pub fn block_rewards( &self, time_period: TimePeriod, ) -> Result<Vec<BlockRewardsEntry>>

Source§

impl Query

Source§

impl Query

Source§

impl Query

Source§

impl Query

Source

pub fn hashrate( &self, time_period: Option<TimePeriod>, ) -> Result<HashrateSummary>

Source§

impl Query

Source

pub fn mining_pools(&self, time_period: TimePeriod) -> Result<PoolsSummary>

Source

pub fn all_pools(&self) -> Vec<PoolInfo>

Source

pub fn pool_detail(&self, slug: PoolSlug) -> Result<PoolDetail>

Source§

impl Query

Source

pub fn reward_stats(&self, block_count: usize) -> Result<RewardStats>

Source§

impl Query

Source§

impl Query

Source

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}
Source

pub fn height(&self) -> Height

Current indexed height

Source

pub fn reader(&self) -> &Reader

Source

pub fn client(&self) -> &Client

Source

pub fn blocks_dir(&self) -> &Path

Source

pub fn indexer(&self) -> &Indexer

Source

pub fn computer(&self) -> &Computer

Source

pub fn mempool(&self) -> Option<&Mempool>

Source

pub fn vecs(&self) -> &'static Vecs<'static>

Trait Implementations§

Source§

impl Clone for Query

Source§

fn clone(&self) -> Query

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more