Crates.io | brk_store |
lib.rs | brk_store |
version | 0.0.95 |
created_at | 2025-06-07 08:34:23.609886+00 |
updated_at | 2025-08-28 10:45:52.546566+00 |
description | A thin wrapper around fjall |
homepage | https://bitcoinresearchkit.org |
repository | https://github.com/bitcoinresearchkit/brk |
max_upload_size | |
id | 1703824 |
size | 51,617 |
Blockchain-aware key-value storage wrapper for Bitcoin data
brk_store
is a thin, typed wrapper around the Fjall embedded key-value store, specifically designed for Bitcoin blockchain data storage. It provides height-based versioning, batch operations, and optimized configurations for Bitcoin data patterns.
use brk_store::{Store, open_keyspace};
use brk_structs::{Height, Version};
// Open keyspace
let keyspace = open_keyspace(Path::new("./data"))?;
// Create typed store
let mut store: Store<String, u64> = Store::import(
&keyspace,
Path::new("./data"),
"store_name",
Version::ZERO,
Some(true), // Enable bloom filters
)?;
// Conditional insertion based on height
store.insert_if_needed("key1".to_string(), 42u64, Height::new(800_000));
// Batch commit changes
store.commit(Height::new(800_000))?;
// Persist to disk
store.persist()?;
// Get value (checks pending puts first, then disk)
if let Some(value) = store.get(&"key1".to_string())? {
println!("Value: {}", value);
}
// Check if store needs processing at height
if store.needs(Height::new(800_000)) {
// Process this height
}
use brk_store::AnyStore;
fn process_stores(stores: &mut [Box<dyn AnyStore>]) -> brk_error::Result<()> {
let height = Height::new(800_000);
for store in stores {
if store.needs(height) {
// Process data for this store
store.commit(height)?;
}
}
// Persist all stores
for store in stores {
store.persist()?;
}
Ok(())
}
// Reset store for complete reindexing
store.reset()?;
// Store automatically recreated on next import
let mut fresh_store: Store<String, u64> = Store::import(
&keyspace,
path,
"store_name",
Version::ZERO,
Some(true)
)?;
Keys and values must implement:
Debug + Clone + From<ByteView> + Ord
for keysDebug + Clone + From<ByteView>
for valuesThis enables automatic serialization and type-safe storage operations.
fjall
- Embedded key-value store enginebyteview
- Zero-copy byte view operationsbrk_structs
- Bitcoin-aware type systembrk_error
- Unified error handlingThis README was generated by Claude Code