pub struct CompactBlock {
pub header: BlockHeader,
pub nonce: u64,
pub short_ids: Vec<ShortTxId>,
pub prefilled_txs: Vec<PrefilledTransaction>,
}Expand description
A compact block (BIP152 cmpctblock).
Contains the header, a nonce, short transaction IDs for most transactions, and a few prefilled transactions (always at least the coinbase).
Fields§
§header: BlockHeaderThe block header.
nonce: u64Random nonce used for short ID computation.
short_ids: Vec<ShortTxId>Short transaction IDs for non-prefilled transactions.
prefilled_txs: Vec<PrefilledTransaction>Prefilled transactions (coinbase + any extras).
Implementations§
Source§impl CompactBlock
impl CompactBlock
Sourcepub fn from_block(block: &Block, nonce: u64) -> Self
pub fn from_block(block: &Block, nonce: u64) -> Self
Build a compact block from a full block.
The coinbase transaction is always prefilled. Additional transactions may be prefilled if the sender thinks the receiver won’t have them.
Sourcepub fn reconstruct(
&self,
mempool_lookup: &HashMap<ShortTxId, Transaction>,
) -> ReconstructResult
pub fn reconstruct( &self, mempool_lookup: &HashMap<ShortTxId, Transaction>, ) -> ReconstructResult
Attempt to reconstruct the full block using a mempool lookup.
mempool_lookup maps short IDs → transactions. If all transactions
can be resolved, returns the full block. Otherwise, returns a request
for the missing transactions.
Sourcepub fn transaction_count(&self) -> usize
pub fn transaction_count(&self) -> usize
The number of transactions represented (prefilled + short IDs).
Sourcepub fn build_mempool_lookup<'a, I>(
&self,
mempool_txs: I,
) -> HashMap<ShortTxId, Transaction>where
I: IntoIterator<Item = &'a Transaction>,
pub fn build_mempool_lookup<'a, I>(
&self,
mempool_txs: I,
) -> HashMap<ShortTxId, Transaction>where
I: IntoIterator<Item = &'a Transaction>,
Build a mempool lookup table for compact block reconstruction.
Takes an iterator of mempool transactions and returns a map from short ID → transaction, keyed using this compact block’s header and nonce.
Trait Implementations§
Source§impl Clone for CompactBlock
impl Clone for CompactBlock
Source§fn clone(&self) -> CompactBlock
fn clone(&self) -> CompactBlock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more