Crates.io | brk_structs |
lib.rs | brk_structs |
version | 0.0.95 |
created_at | 2025-08-07 19:24:44.372935+00 |
updated_at | 2025-08-28 10:44:57.973821+00 |
description | Structs used throughout BRK |
homepage | https://bitcoinresearchkit.org |
repository | https://github.com/bitcoinresearchkit/brk |
max_upload_size | |
id | 1785676 |
size | 254,006 |
Bitcoin-aware type system and data structures for blockchain analysis
brk_structs
provides the foundational type system for the Bitcoin Research Kit (BRK). It offers strongly-typed, storage-optimized data structures that encode Bitcoin protocol knowledge and enable efficient blockchain data analysis.
Height
- Block heights with Bitcoin-specific arithmeticTxid
/BlockHash
- Transaction and block identifiers with prefix optimizationTxIndex
/InputIndex
/OutputIndex
- Component indices with type safetyDate
/Timestamp
- Time representations anchored to Bitcoin genesis blockSats
- Satoshi amounts with comprehensive arithmetic operationsBitcoin
- BTC amounts with precision handlingDollars
/Cents
- Fiat currency for price analysisOpen<T>
, High<T>
, Low<T>
, Close<T>
) for market dataOutputType
- All Bitcoin script types (P2PKH, P2SH, P2WPKH, P2WSH, P2TR, etc.)AddressBytes
- Type-safe address data extractionAnyAddressIndex
- Unified address indexingDateIndex
- Days since Bitcoin genesisWeekIndex
, MonthIndex
, QuarterIndex
, YearIndex
, DecadeIndex
HalvingEpoch
- Bitcoin halving periods (every 210,000 blocks)DifficultyEpoch
- Difficulty adjustment periodsuse brk_structs::*;
// Type-safe blockchain data
let height = Height::new(800_000);
let epoch = HalvingEpoch::from(height);
let amount = Sats::_1BTC * 2;
// Time-based indexing
let date = Date::new(2024, 1, 15);
let month_idx = MonthIndex::from(date);
// Extract address information from Bitcoin scripts
let output_type = OutputType::from(&script);
if output_type.is_address() {
let address_bytes = AddressBytes::try_from((&script, output_type))?;
}
// Efficient serialization without copying
let height_bytes = height.as_bytes();
let recovered_height = Height::read_from_bytes(height_bytes)?;
// Flexible filtering for analytics
let utxo_groups = UTXOGroups {
all: total_utxos,
age_range: ByAgeRange::new(age_filtered_utxos),
epoch: ByEpoch::new(epoch_filtered_utxos),
// ... more groupings
};
All types implement zero-copy serialization traits:
bitcoin
- Bitcoin protocol types and script parsingvecdb
- Vector database storage traitszerocopy
- Zero-copy serialization frameworkserde
- JSON serialization supportjiff
- Modern date/time handlingThis README was generated by Claude Code