Expand description
§brk_types
Domain types for Bitcoin data analysis with serialization and indexing support.
§What It Enables
Work with Bitcoin primitives (heights, satoshis, addresses, transactions) through purpose-built types that handle encoding, arithmetic, time conversions, and database storage automatically.
§Key Features
- Bitcoin primitives:
Height,Sats,Txid,BlockHash,Outpointwith full arithmetic and conversion support - Address types: All output types (P2PK33, P2PK65, P2PKH, P2MS, P2SH, P2WPKH, P2WSH, P2TR, P2A, OP_RETURN) with address index variants
- Time indexes:
DateIndex,WeekIndex,MonthIndex,QuarterIndex,SemesterIndex,YearIndex,DecadeIndexwith cross-index conversion - Protocol types:
DifficultyEpoch,HalvingEpoch,TxVersion,RawLocktime - Financial types:
Dollars,Cents,OHLC(Open/High/Low/Close) - Serialization: Serde + JSON Schema generation via schemars
- Compression: PCO (Pco) derive for columnar compression in vecdb
§Type Categories
| Category | Examples |
|---|---|
| Block metadata | Height, BlockHash, BlockTimestamp, BlkPosition |
| Transaction | Txid, TxIndex, TxIn, TxOut, Vsize, Weight |
| Address | P2PKHAddressIndex, P2TRBytes, AnyAddressIndex, AddressStats |
| Value | Sats, Dollars, Cents, Bitcoin |
| Time | Date, DateIndex, WeekIndex, MonthIndex, … |
| Metric | Metric, MetricData, MetricSelection |
| API | Pagination, Health, RecommendedFees, MempoolInfo |
§Core API
All types implement standard traits: Debug, Clone, Serialize, Deserialize, plus domain-specific operations like CheckedSub, Formattable, and PrintableIndex.
ⓘ
use brk_types::{Height, Sats, DateIndex, Date};
let height = Height::new(840_000);
let reward = Sats::FIFTY_BTC / 16; // Post-4th-halving reward
let date_idx = DateIndex::try_from(Date::new(2024, 4, 20))?;§Built On
brk_errorfor error handling
Structs§
- Address
- Bitcoin address string
- Address
Chain Stats - Address statistics on the blockchain (confirmed transactions only)
- Address
Hash - Address
Index OutPoint - Address
Index TxIndex - Address
Mempool Stats - Address statistics in the mempool (unconfirmed transactions only)
- Address
Param - Address
Stats - Address information compatible with mempool.space API format
- Address
Txids Param - Address
Validation - Address validation result
- Age
- Represents the age of a UTXO or address balance. Encapsulates all age-related calculations in one type-safe struct.
- AnyAddress
Index - Unified index for any address type (loaded or empty)
- Bitcoin
- Bitcoin amount as floating point (1 BTC = 100,000,000 satoshis)
- BlkMetadata
- BlkPosition
- Position within a .blk file, encoding file index and byte offset
- Block
- Block
Count Param - Block
FeeRates Entry - A single block fee rates data point with percentiles.
- Block
Fees Entry - A single block fees data point.
- Block
Hash - Block hash
- Block
Hash Param - Block
Hash Prefix - Block
Hash Start Index - Block
Hash TxIndex - Block
Info - Block information returned by the API
- Block
Rewards Entry - A single block rewards data point.
- Block
Size Entry - A single block size data point.
- Block
Sizes Weights - Combined block sizes and weights response.
- Block
Status - Block status indicating whether block is in the best chain
- Block
Timestamp - Block information returned for timestamp queries
- Block
Weight Entry - A single block weight data point.
- Cents
- Cents
Compact - Compact representation of USD cents as i32.
- Close
- Closing price value for a time period
- Compute
Indexes - Extended indexes with time-based granularities. Used by brk_computer for time-series aggregation.
- Data
Range - Range parameters for slicing data
- Data
Range Format - Data range with output format for API query parameters
- Date
- Date in YYYYMMDD format stored as u32
- Date
Index - Decade
Index - Detailed
Metric Count - Detailed metric count with per-database breakdown
- Difficulty
Adjustment - Difficulty adjustment information.
- Difficulty
Adjustment Entry - A single difficulty adjustment entry. Serializes as array: [timestamp, height, difficulty, change_percent]
- Difficulty
Entry - A single difficulty data point.
- Difficulty
Epoch - Disk
Usage - Disk usage of the indexed data
- Dollars
- US Dollar amount as floating point
- Empty
Address Data - Data of an empty address
- Empty
Address Index - Empty
Output Index - Exit
- Graceful shutdown coordinator for ensuring data consistency during program exit.
- FeeRate
- Fee rate in sats/vB
- FeeRate
Percentiles - Fee rate percentiles (min, 10%, 25%, 50%, 75%, 90%, max).
- Halving
Epoch - Hashrate
Entry - A single hashrate data point.
- Hashrate
Summary - Summary of network hashrate and difficulty data.
- Health
- Server health status
- Height
- Block height
- Height
Param - Hex
- Hex-encoded string
- High
- Highest price value for a time period
- Index
Info - Information about an available index and its query aliases
- Indexes
- Blockchain-level indexes tracking current positions for various entity types. Used by brk_indexer during block processing.
- JSON
Pool - Limit
- Maximum number of results to return. Defaults to 100 if not specified.
- Limit
Param - Loaded
Address Data - Data for a loaded (non-empty) address with current balance
- Loaded
Address Index - Low
- Lowest price value for a time period
- Mempool
Block - Block info in a mempool.space like format for fee estimation.
- Mempool
Entry Info - Mempool entry info from Bitcoin Core’s getrawmempool verbose
- Mempool
Info - Mempool statistics
- Metric
- Metric name
- Metric
Count - Metric count statistics - distinct metrics and total metric-index combinations
- Metric
Data - Metric data with range information.
- Metric
Leaf - Leaf node containing metric metadata
- Metric
Leaf With Schema - MetricLeaf with JSON Schema for client generation
- Metric
Param - Metric
Selection - Selection of metrics to query
- Metric
Selection Legacy - Legacy metric selection parameters (deprecated)
- Metric
With Index - Metrics
- Comma-separated list of metric names
- Month
Index - OHLC
Cents - OHLC (Open, High, Low, Close) data in cents
- OHLC
Dollars - OHLC (Open, High, Low, Close) data in dollars
- OHLC
Sats - OHLC (Open, High, Low, Close) data in satoshis
- OpReturn
Index - Open
- Opening price value for a time period
- OutPoint
- P2AAddress
Index - P2ABytes
- P2MS
Output Index - P2PK33
Address Index - P2PK33
Bytes - P2PK65
Address Index - P2PK65
Bytes - P2PKH
Address Index - P2PKH
Bytes - P2SH
Address Index - P2SH
Bytes - P2TR
Address Index - P2TR
Bytes - P2WPKH
Address Index - P2WPKH
Bytes - P2WSH
Address Index - P2WSH
Bytes - Paginated
Metrics - A paginated list of available metric names (1000 per page)
- Pagination
- Pagination parameters for paginated API endpoints
- Pagination
Index - Pagination parameters with an index filter
- Pool
- Mining pool information
- Pool
Block Counts - Block counts for different time periods
- Pool
Block Shares - Pool’s share of total blocks for different time periods
- Pool
Detail - Detailed pool information with statistics across time periods
- Pool
Detail Info - Pool information for detail view
- Pool
Info - Basic pool information for listing all pools
- Pool
Slug Param - Pool
Stats - Mining pool with block statistics for a time period
- Pools
- Pools
Summary - Mining pools response for a time period
- Quarter
Index - RawLock
Time - Transaction locktime
- Read
Block - Recommended
Fees - Recommended fee rates in sat/vB
- Reward
Stats - Block reward statistics over a range of blocks
- Sats
- Satoshis
- Semester
Index - Stored
Bool - Fixed-size boolean value optimized for on-disk storage (stored as u16)
- Stored
F32 - Stored 32-bit floating point value
- Stored
F64 - Fixed-size 64-bit floating point value optimized for on-disk storage
- Stored
I16 - Stored
String - Stored
U8 - Stored
U16 - Stored
U32 - Fixed-size 32-bit unsigned integer optimized for on-disk storage
- Stored
U64 - Fixed-size 64-bit unsigned integer optimized for on-disk storage
- Supply
State - Current supply state tracking UTXO count and total value
- Sync
Status - Sync status of the indexer
- Time
Period Param - Timestamp
- UNIX timestamp in seconds
- Timestamp
Param - Transaction
- Transaction information compatible with mempool.space API format
- TxIn
- Transaction input
- TxIn
Index - TxIndex
- TxOut
- Transaction output
- TxOut
Index - TxOutspend
- Status of an output indicating whether it has been spent
- TxStatus
- Transaction confirmation status
- TxVersion
- Transaction version number
- TxWith
Hex - A transaction with its raw hex representation
- Txid
- Transaction ID (hash)
- Txid
Param - Txid
Prefix - Txid
Vout - Transaction output reference (txid + output index)
- Type
Index - Index within its type (e.g., 0 for first P2WPKH address)
- U8x2
- U8x20
- U8x32
- U8x33
- U8x65
- Unit
- Unknown
Output Index - Utxo
- Unspent transaction output
- VSize
- Virtual size in vbytes (weight / 4, rounded up)
- Validate
Address Param - Version
- Version tracking for data schema and computed values.
- Vin
- Input index in the spending transaction
- Vout
- Index of the output being spent in the previous transaction
- Week
Index - Weight
- Transaction or block weight in weight units (WU)
- Year
- Bitcoin year (2009, 2010, …, 2025+)
- Year
Index
Enums§
- Address
Bytes - AnyAddress
Data Index Enum - Format
- Output format for API responses
- Format
Response - Response type for endpoints that support multiple formats (JSON/CSV).
- Index
- Aggregation dimension for querying metrics. Includes time-based (date, week, month, year), block-based (height, txindex), and address/output type indexes.
- Output
Type - Type (P2PKH, P2WPKH, P2SH, P2TR, etc.)
- Pool
Slug - Term
- Classification for short-term vs long-term holders. The threshold is 150 days (approximately 5 months) = 3600 hours.
- Time
Period - Time period for mining statistics.
- Tree
Node - Hierarchical tree node for organizing metrics into categories
Constants§
- BLOCKS_
PER_ DIFF_ EPOCHS - BLOCKS_
PER_ HALVING - ONE_
DAY_ IN_ SEC - ONE_
DAY_ IN_ SEC_ F64 - ONE_
HOUR_ IN_ SEC - PERCENTILES
- Standard percentile values used throughout BRK.
- PERCENTILES_
LEN - Length of the PERCENTILES array.
Traits§
- Checked
Sub - Option
Ext - Extension trait for Option to provide shorter unwrap methods
- Printable
Index - Provides string representations of index types for display and region naming.
Functions§
- de_
unquote_ i64 - de_
unquote_ limit - de_
unquote_ usize - extract_
json_ type - Extract JSON type from a schema, following $ref if needed.
- get_
percentile - Get a percentile value from a sorted slice.
- pools