brk_interface
Unified data query and formatting interface for Bitcoin datasets
brk_interface
provides a clean, unified API for accessing Bitcoin datasets from both indexer and computer components. It serves as the primary data access layer powering BRK's web API and MCP endpoints, offering flexible querying, pagination, and multiple output formats.
What it provides
- Unified Data Access: Single interface to query both indexed blockchain data and computed analytics
- Multiple Output Formats: JSON, CSV, TSV, and Markdown table formatting
- Flexible Pagination: Range queries with positive/negative indexing and automatic pagination
- Multi-dataset Queries: Retrieve multiple datasets with the same time index in one call
- Dynamic Search: Intelligent ID matching with automatic fallbacks and normalization
Key Features
Query Interface
- 25 Time Indices: From granular (Height, DateIndex) to aggregate (YearIndex, DecadeIndex)
- Bitcoin-Specific Indices: Address types (P2PKH, P2SH, P2TR), output types, epochs
- Multi-dataset support: Query multiple related datasets simultaneously
- Intelligent ID resolution: Flexible matching with automatic fallbacks
Pagination and Ranges
- Signed indexing: Negative indices count from end (
-1
= latest,-10
= last 10) - Range queries:
from
/to
parameters with optionalcount
limit - Efficient pagination: 1,000 items per page with proper start/end calculation
Output Formatting
- JSON: Single values, arrays, or matrices with automatic structure detection
- CSV/TSV: Delimiter-separated values with headers for spreadsheet use
- Markdown: Tables formatted for documentation and display
- Schema Support: JSON Schema generation for API documentation
Usage
Basic Query Setup
use ;
use Indexer;
use Computer;
// Load data sources
let indexer = forced_import?;
let computer = forced_import?;
// Create unified interface
let interface = build;
Single Dataset Queries
// Get latest block data
let params = Params ;
let result = interface.search_and_format?;
println!;
Range Queries
// Get price data for last 30 days
let params = Params ;
let csv_data = interface.search_and_format?;
Multiple Datasets
// Get comprehensive block statistics
let params = Params ;
let tsv_data = interface.search_and_format?;
Flexible ID Specification
// Different ways to specify dataset IDs
let params = Params ;
Advanced Queries with Pagination
// Query with custom pagination
let params = Params ;
let markdown_table = interface.search_and_format?;
API Methods
Core Query Methods
// Combined search and format
let result = interface.search_and_format?;
// Separate search and format
let vecs = interface.search?;
let formatted = interface.format?;
// Get metadata
let current_height = interface.get_height;
let available_datasets = interface.get_vecids?; // Paginated
let available_indices = interface.get_indexes;
Working with Results
use ;
// Handle different output types
match interface.search_and_format?
Available Indices
Time-based Indices
Height
- Block height (0, 1, 2, ...)DateIndex
- Days since Bitcoin genesisWeekIndex
,MonthIndex
,QuarterIndex
,YearIndex
,DecadeIndex
HalvingEpoch
,DifficultyEpoch
- Bitcoin-specific epochs
Bitcoin-specific Indices
- Address types:
P2PKHAddressIndex
,P2SHAddressIndex
,P2WPKHAddressIndex
, etc. - Output types:
OutputType
classifications - Transaction types:
TxIndex
,InputIndex
,OutputIndex
Parameter Reference
Output Formats
- JSON: Structured data (single values, arrays, matrices)
- CSV: Comma-separated values with headers
- TSV: Tab-separated values with headers
- Markdown: Formatted tables for documentation
Performance Features
- Zero-copy operations: Uses references and lifetimes to avoid cloning
- Memory mapping: Leverages vecdb's memory-mapped storage
- Lazy evaluation: Only processes data when formatting is requested
- Efficient pagination: Smart bounds calculation and range queries
Schema Support
The interface provides JSON Schema support for API documentation:
use schema_for;
let schema = schema_for!;
// Use schema for API documentation
Dependencies
brk_indexer
- Indexed blockchain data sourcebrk_computer
- Computed analytics data sourcevecdb
- Vector database with collection traitsserde
- Serialization/deserialization supportschemars
- JSON Schema generation
This README was generated by Claude Code