Expand description
§brk_types
Bitcoin primitives shared across BRK and Bitview.
§What it provides
Types for heights, amounts, hashes, addresses, transactions, block
templates and mempool state, including responses shared with brk_mempool such
as MempoolInfo. Bitview’s
index, value and state types (calendar indexes, protocol epochs, per-type address
indexes, unit-typed scalars) live in bitview_primitives; query-protocol types and
REST response DTOs live in bitview_types; TreeNode lives in bitview_catalog; CPFP
linearization lives in brk_cpfp.
§Features
The default build has no vecdb, rawdb or schemars dependency, so BRK
libraries such as brk_mempool and brk_rpc stay lean.
schemarsadds the JSON Schema derives (andVersion’s schema withstorage) that Bitview’s API needs;bitview_primitivesenables it.storageadds byte/compression derives, vector traits, storage versions, and storage error conversions, for crates that persist domain values; catalog and API-only consumers leave it disabled.
Index names and aliases (Height, TxIndex), arithmetic (including
CheckedSub), Serde, and JSON Schema (with schemars) remain available without
storage. bitview_types::SeriesData::version and Rust client version endpoints expose
the wire value as u32, not the storage engine’s Version type.
Verify the modes separately to avoid workspace feature unification hiding an accidental storage or schemars dependency:
cargo check -p brk_types --no-default-features
cargo check -p brk_types --features storage
cargo check -p brk_types --features schemars,storage
cargo tree -p bitview_catalog§Example
use brk_types::Height;
let height = Height::new(840_000);
let reward = height.subsidy();
let blocks_left = height.left_before_next_halving();Macros§
- impl_
float_ ord_ format - NaN-aware total order and formatting for a float newtype
$t(float): NaN equals itself and orders first, and a non-finite value is written as JSONnull/ an empty CSV cell (an undefined value:Formattable::UNDEFINED). - impl_
int_ format DisplayandFormattablefor an integer newtype$t(int): the integer’s decimal digits.- impl_
integer_ index - The impls every integer index newtype (
struct $t($inner)) shares: arithmetic with itself andusize, checked subtraction, conversions with$innerandusize(ausizeis cast to$inner, so it must fit), and formatting throughimpl_int_format. Sentinels, other conversions, capacity and aliases stay on each type. - impl_
store_ value - Implements
StoreValuefor a newtype$t(...): a byte array is stored as is, an integer as its big-endian bytes.
Structs§
- Address
- Bitcoin address, or the hex public key of a P2PK output.
- Address
Mempool Stats - Address statistics in the mempool (unconfirmed transactions only), in mempool.space’s format.
- Address
Output Type - The output type of an address: any
OutputTypebutp2ms,op_return,empty_scriptandunknown_script. Parsing another type fails, naming the address types. - Bitcoin
- An amount in bitcoin, as a decimal number (1 BTC = 100,000,000 satoshis).
- BlkPosition
- Position within a .blk file, encoding file index and byte offset
- Block
Hash - Double-SHA256 block-header hash, serialized in Bitcoin’s conventional hexadecimal byte order.
- Cents
- An amount in US cents (100 cents = 1 USD).
- Cents
Sats - Cents × Sats (u128) - price in cents multiplied by amount in sats. Uses u128 because large amounts at any price can overflow u64.
- Cents
Signed - A signed amount in US cents (100 cents = 1 USD).
- Coinbase
Tag - Up to the first 100 bytes of a coinbase transaction’s first-input
scriptSig. Bytes are preserved for storage and exposed as a string by mapping each byte to the same-valued Unicode code point. Pool attribution may search this raw value, but the value itself is not a normalized pool label. - Confirmed
Cpfp - CPFP of a confirmed transaction with relatives in its block: its package there.
- Cpfp
Cluster - CPFP cluster: the connected component the seed belongs to, plus its linearization.
- Cpfp
Cluster Chunk - One linearized chunk inside a
CpfpCluster.txsfollowsCpfpCluster.txsorder (topological);feerateis the chunk’s, shared by all its transactions. - Cpfp
Cluster Tx - Cpfp
Cluster TxIndex - Position of a transaction inside a
CpfpCluster.txsarray. Cluster-local, has no meaning outside the enclosing cluster. - Cpfp
Entry - A transaction in a CPFP relationship.
- Cpfp
Info - CPFP (Child Pays For Parent) information for a mempool transaction.
- Dollars
- An amount in US dollars.
- Empty
Cpfp - CPFP of a transaction without known relatives:
{"ancestors":[]}. - FeeRate
- Fee rate stored in milli-sat/vB and exposed as sat/vB.
- Height
- A block height: how many blocks came before it.
- Hex
- Hex-encoded data as a JSON string.
- Histogram
- Fixed-length, log-scale bin histogram generic over the per-bin counter type: raw counts
(
u32) or the smoothed EMA (f64). Serializes as a flat JSON array ofNvalues. - Mempool
Block - Block info in a mempool.space like format for fee estimation.
- Mempool
Block Content - A projected mempool block with its transactions: block 0 is Bitcoin Core’s
getblocktemplateselection. Returned byGET /api/mempool-blocks/{index}. - Mempool
Block Diff - A projected mempool block’s changes since a prior copy identified by
since. Returned byGET /api/mempool-blocks/{index}/diff/{since}. - Mempool
Block Hash - Content hash of a projected mempool block, including its statistics and complete
transaction bodies. Opaque token, distinct from HTTP ETag formatting: pass back to
GET /api/mempool-blocks/{index}/diff/{since}to follow changes. A decimal string, since JavaScript numbers can’t hold every 64-bit value. - Mempool
Block Index - A projected mempool block’s position, as
/api/v1/fees/mempool-blockslists them: 0 is the next block, Bitcoin Core’sgetblocktemplateselection. - Mempool
Entry Info - Mempool entry info from Bitcoin Core’s
getmempoolentry. - Mempool
Info - Mempool statistics with incrementally maintained fee histogram.
- Mempool
Recent Tx - Simplified mempool transaction for the
/api/mempool/recentendpoint. - OutPoint
- The output a transaction input spends: its transaction index and output position, written as
{"tx_index": N, "vout": M}(coinbase inputs:{"tx_index": 4294967295, "vout": 4294967295}). - P2ABytes
- The 2-byte witness program of a P2A (pay-to-anchor) output.
- P2PK33
Bytes - A compressed (33-byte) public key.
- P2PK65
Bytes - An uncompressed (65-byte) public key.
- P2PKH
Bytes - The 20-byte public key hash of a P2PKH output.
- P2SH
Bytes - The 20-byte script hash of a P2SH output.
- P2TR
Bytes - The 32-byte output key of a P2TR output.
- P2WPKH
Bytes - The 20-byte public key hash of a P2WPKH output.
- P2WSH
Bytes - The 32-byte script hash of a P2WSH output.
- Precise
Recommended Fees - Recommended fee rates in sat/vB, to the thousandth (
/api/v1/fees/precise) - RawLock
Time - Transaction locktime. Values below 500,000,000 are interpreted as block heights; values at or above are Unix timestamps.
- Read
Block - A block parsed from Core’s blk files, beside its raw bytes (txids hash from them without re-serializing) and where it sits in those files.
- Recommended
Fees - Recommended fee rates in whole sat/vB (
/api/v1/fees/recommended) - Retained
Run - Consecutive transactions kept from the prior block,
[start, count]: its positionsstart..start + count, in order. - Sats
- An amount in satoshis (100,000,000 to a bitcoin).
- Sats
Signed - A signed amount in satoshis.
- SigOp
Count - Bitcoin Core’s
CScript::GetSigOpCount, both modes in one walk: legacy counts every CHECKMULTISIG as 20, accurate as theOP_nright before it (20 without one). Every instruction sets that preceding opcode, signature opcodes included (rust-bitcoin’s accurate count keeps a staleOP_nacross them). A malformed push ends the walk, as in Core. - SigOps
- BIP-141 signature-operation cost: legacy and P2SH-redeem sigops count four and witness sigops one. Sums over many transactions or blocks use the full 64 bits.
- SigOps32
- A transaction’s BIP-141 signature-operation cost in 32 bits: the storage form of
SigOps. - Timestamp
- A Unix timestamp, in seconds.
- Transaction
- Transaction information compatible with mempool.space API format
- TxIn
- TxIndex
- Chain-wide transaction index (0 = the genesis coinbase). For an
in-block position, use
BlockTxIndexinstead. - TxOut
- TxOutspend
- TxStatus
- TxVersion
Raw - Raw transaction version: the protocol’s 32 bits read unsigned, as Esplora reports them. Unlike TxVersion (u8, indexed), this preserves non-standard values used in coinbase txs for miner signaling/branding.
- Txid
- A transaction ID: its hash.
- Txid
Prefix - First-8-bytes prefix of a txid, packed as a
u64. BothFrom<&Txid>(viafrom_le_bytes) andStoreValue(viafrom_be_bytes, inverse of theto_be_byteswriter) are host-independent so on-disk keys are portable across architectures. - Unit
- VSize
- Virtual size in vbytes (weight / 4, rounded up). Max block vsize is ~1,000,000 vB.
- Vin
- Input index in the spending transaction
- Vout
- Index of the output being spent in the previous transaction (coinbase inputs: 4294967295)
- Weight
- Weight in weight units (WU): non-witness bytes count four and witness bytes one. A block holds at most 4,000,000 WU; sums over many blocks use the full 64 bits.
- Weight32
- A transaction’s or block’s weight in 32 bits: the storage form of
Weight(a block holds at most 4,000,000 WU).
Enums§
- Address
Bytes - Cpfp
- A transaction’s CPFP (Child Pays For Parent) answer, in mempool.space’s shapes, told apart by
their fields (untagged on the wire): a mempool transaction’s package, a confirmed transaction’s
package among its block’s transactions, or
{"ancestors":[]}for an unknown transaction or a confirmed one without relatives in its block. - Mempool
Block Diff Entry - One stretch of the new block in a
MempoolBlockDiff. - Output
Type - An output’s script type (P2PKH, P2WPKH, P2SH, P2TR…).
- Output
Type Normalized - Output type names used by Esplora and mempool.space.
Constants§
- ADDRESS_
PAYLOAD_ LENGTHS - Each address type with its payload length in bytes.
- BLOCKS_
PER_ DIFF_ EPOCH - BLOCKS_
PER_ HALVING - CPFP_
CHAIN_ LIMIT - Bitcoin Core’s default mempool ancestor/descendant chain cap, also used by mempool.space-style truncation in CPFP walks.
- ONE_
DAY_ IN_ SEC - ONE_
DAY_ IN_ SEC_ F64 - ONE_
HOUR_ IN_ SEC - TARGET_
BLOCKS_ PER_ DAY - TARGET_
BLOCKS_ PER_ DAY_ F32 - TARGET_
BLOCKS_ PER_ DAY_ F64
Traits§
- Checked
Sub - Checked subtraction for domain values; storage builds use
vecdb’s identical trait instead. - Store
Value - Stable fixed-width encoding of a store key or value.
Functions§
- weighted_
percentiles - Vsize-weighted percentiles of a sorted (value, vsize) slice with Bitcoin Core’s
getblockstatsrank rule: for each percentp(0 to 100, nondecreasing), the first value whose cumulative vsize reachesp% of the total, in one walk.