Skip to main content

Crate bitview_query

Crate bitview_query 

Source
Expand description

§bitview_query

Query interface for Bitcoin indexed and computed data.

§What It Enables

Query blocks, transactions, addresses, and on-chain series through a unified API. Supports pagination, range queries, and multiple output formats.

§Key Features

  • Unified access: Single entry point to plugin and mempool data
  • Series discovery: Browse the catalog, inspect supported indexes, and fuzzy search
  • Range queries: By height, date, or relative offsets (from=-100)
  • Bulk queries: Fetch multiple series in one call
  • Async support: Tokio-compatible with AsyncQuery wrapper
  • Format flexibility: JSON, CSV, or raw values

§Core API

ⓘ
let query = Query::build(&plugins, Some(mempool));

// Current height
let height = query.height();

// Series queries use a cheap resolve phase before formatting.
let selection = SeriesSelection::from((
    Index::Height,
    SeriesName::from("supply"),
    DataRangeFormat::default(),
));
let resolved = query.resolve(selection, usize::MAX)?;
let data = query.format(resolved)?;

// Block queries
let info = query.block_by_height(Height::new(840_000))?;

// Transaction queries
let tx = query.transaction(txid.into())?;

// Address queries
let stats = query.addr(address)?;

§Query Types

DomainMethods
Seriessearch_series, resolve, format, series_count, series_list, series_catalog, series_info
Blocksblock, block_by_height, blocks, block_txs, block_status, block_by_timestamp
Transactionstransaction, transaction_status, transaction_hex, outspend, outspends
Addressesaddr, addr_txids, addr_utxos
Miningdifficulty_adjustments, hashrate, mining_pools, reward_stats
Mempoolmempool_info, recommended_fees, mempool_blocks

§Async Usage

ⓘ
let async_query = AsyncQuery::build(&plugins, mempool);

// Run blocking queries in thread pool
let result = async_query.run(|q| q.block_by_height(height)).await;

// Access inner Query
let height = async_query.inner().height();

§Built On

  • bitview_runtime::PluginSet for generic plugin discovery
  • brk_mempool for mempool queries
  • brk_reader for raw block access

§Features

Plugin features (indexer, blocks, distribution, mappings, price, and the other built-in plugin IDs) are the source of truth. Enabling one adds its typed HasX requirement to QueryPluginSet and exposes its typed accessor. The tokio feature adds AsyncQuery and also enables the indexer capability.

chain, series, urpd, and full-api are convenience aggregators. full-api is the default for standalone users; composition and adapter crates should disable default features and select only what they expose. Generic Vecs discovery works with any Traversable plugin without a feature or dependency on that plugin crate. Query construction validates the enabled capabilities once and then keeps direct typed references, so hot paths perform no dynamic lookup.

Structs§

Query
ResolvedQuery
A resolved series query ready for formatting. Carries the vecs plus the metadata callers need to derive an etag or cache policy. stable_count is None when any selected series can mutate existing entries.
SeriesOutput
Series output with metadata for caching.
SeriesOutputLegacy
Deprecated: Legacy series output with metadata for caching.
Vecs

Enums§

LegacyValue
Deprecated: Raw JSON without metadata wrapper.
Output
Series data output format
OutputLegacy
Deprecated: Raw JSON without metadata wrapper

Traits§

QueryPluginSet
Composition contract for the individually enabled query plugins.
SupportsBedrock
SupportsBlocks
SupportsChainQueries
Capabilities required by the complete chain-query API.
SupportsCoinflow
SupportsCointime
SupportsDistribution
SupportsInputs
SupportsMappings
SupportsMining
SupportsOutputs
SupportsPools
SupportsPrice
SupportsSeriesQueries
Capabilities required by the series-query API.
SupportsTransactions
SupportsUrpdQueries
Capabilities required by the complete URPD-query API.