| Crates.io | brk_interface |
| lib.rs | brk_interface |
| version | 0.0.109 |
| created_at | 2025-06-24 10:01:34.553157+00 |
| updated_at | 2025-09-20 17:22:08.06129+00 |
| description | An interface to find and format data from BRK |
| homepage | https://bitcoinresearchkit.org |
| repository | https://github.com/bitcoinresearchkit/brk |
| max_upload_size | |
| id | 1724102 |
| size | 107,819 |
Unified data query and formatting interface for Bitcoin datasets with intelligent search and multi-format output.
This crate provides a high-level interface for querying and formatting data from BRK's indexer and computer components. It offers intelligent vector search with fuzzy matching, parameter validation, range queries, and multi-format output (JSON, CSV) with efficient caching and pagination support.
Key Features:
Target Use Cases:
cargo add brk_interface
use brk_interface::{Interface, Params, Index};
use brk_indexer::Indexer;
use brk_computer::Computer;
// Initialize with indexer and computer
let indexer = Indexer::build(/* config */)?;
let computer = Computer::build(/* config */)?;
let interface = Interface::build(&indexer, &computer);
// Query data with parameters
let params = Params {
index: Index::Height,
ids: vec!["height-to-blockhash".to_string()].into(),
from: Some(800000),
to: Some(800100),
format: Some(Format::JSON),
..Default::default()
};
// Search and format results
let output = interface.search_and_format(params)?;
println!("{}", output);
Interface<'a>: Main query interface coordinating indexer and computer accessParams: Query parameters including index, IDs, range, and formatting optionsIndex: Enumeration of available data indexes (Height, Date, Address, etc.)Format: Output format specification (JSON, CSV)Output: Formatted query results with multiple value typesInterface::build(indexer: &Indexer, computer: &Computer) -> Self
Creates interface instance with references to data sources.
search(&self, params: &Params) -> Result<Vec<(String, &&dyn AnyCollectableVec)>>
Searches for vectors matching the query parameters with intelligent error handling.
format(&self, vecs: Vec<...>, params: &ParamsOpt) -> Result<Output>
Formats search results according to specified output format and range parameters.
search_and_format(&self, params: Params) -> Result<Output>
Combined search and formatting operation for single-call data retrieval.
Core Parameters:
index: Data index to query (height, date, address, etc.)ids: Vector IDs to retrieve from the specified indexfrom/to: Optional range filtering (inclusive start, exclusive end)format: Output format (defaults to JSON)Pagination Parameters:
offset: Number of entries to skiplimit: Maximum entries to returnuse brk_interface::{Interface, Params, Index, Format};
let interface = Interface::build(&indexer, &computer);
// Query block heights to hashes
let params = Params {
index: Index::Height,
ids: vec!["height-to-blockhash".to_string()].into(),
from: Some(750000),
to: Some(750010),
format: Some(Format::JSON),
..Default::default()
};
match interface.search_and_format(params)? {
Output::Json(value) => println!("{}", serde_json::to_string_pretty(&value)?),
_ => unreachable!(),
}
use brk_interface::{Interface, Params, Index, Format};
// Export price data as CSV
let params = Params {
index: Index::Date,
ids: vec!["dateindex-to-price-close".to_string()].into(),
from: Some(0), // From genesis
to: Some(5000), // First ~13 years
format: Some(Format::CSV),
..Default::default()
};
match interface.search_and_format(params)? {
Output::CSV(csv_text) => {
std::fs::write("bitcoin_prices.csv", csv_text)?;
println!("Price data exported to bitcoin_prices.csv");
},
_ => unreachable!(),
}
use brk_interface::{Interface, Params, Index};
// Query with typo in vector ID
let params = Params {
index: Index::Height,
ids: vec!["height-to-blockhas".to_string()].into(), // Typo: "blockhas"
..Default::default()
};
// Interface provides helpful error with suggestions
match interface.search(¶ms) {
Err(error) => {
println!("{}", error);
// Output: No vec named "height-to-blockhas" indexed by "height" found.
// Maybe you meant one of the following: ["height-to-blockhash"] ?
},
Ok(_) => unreachable!(),
}
The interface acts as a bridge between:
JSON Output:
CSV Output:
Available indexes include:
Height: Block height-based indexingDate: Calendar date indexingAddress: Bitcoin address indexingTransaction: Transaction hash indexingMain Structure: Interface struct coordinating between Indexer and Computer data sources
Query System: Parameter-driven search with Params struct supporting range queries and formatting options
Error Handling: Intelligent fuzzy matching with cached error messages and helpful suggestions
Output Formats: Multi-format support (JSON, CSV) with proper data serialization
Caching: quick_cache integration for error messages and expensive operations
Search Logic: nucleo-matcher fuzzy search for user-friendly vector name resolution
Architecture: Abstraction layer providing unified access to heterogeneous Bitcoin data sources
This README was generated by Claude Code