pub trait Listen {
// Required methods
fn filtered_block_connected(
&self,
header: &Header,
txdata: &TransactionData<'_>,
height: u32,
);
fn blocks_disconnected(&self, fork_point_block: BestBlock);
// Provided method
fn block_connected(&self, block: &Block, height: u32) { ... }
}Expand description
The Listen trait is used to notify when blocks have been connected or disconnected from the
chain.
Useful when needing to replay chain data upon startup or as new chain events occur. Clients
sourcing chain data using a block-oriented API should prefer this interface over Confirm.
Such clients fetch the entire header chain whereas clients using Confirm only fetch headers
when needed.
By using Listen::filtered_block_connected this interface supports clients fetching the
entire header chain and only blocks with matching transaction data using BIP 157 filters or
other similar filtering.
§Requirements
Each block must be connected in chain order with one call to either
Listen::block_connected or Listen::filtered_block_connected. If a call to the
Filter interface was made during block processing and further transaction(s) from the same
block now match the filter, a second call to Listen::filtered_block_connected should be
made immediately for the same block (prior to any other calls to the Listen interface).
In case of a reorg, you must call Listen::blocks_disconnected once with information on the
“fork point” block, i.e. the highest block that is in both forks. You may call
Listen::blocks_disconnected multiple times as you walk the chain backwards, but each must
include a fork point block that is before the last.
§Object Birthday
Note that most implementations take a BestBlock on construction and blocks only need to be
applied starting from that point.
Required Methods§
Sourcefn filtered_block_connected(
&self,
header: &Header,
txdata: &TransactionData<'_>,
height: u32,
)
fn filtered_block_connected( &self, header: &Header, txdata: &TransactionData<'_>, height: u32, )
Notifies the listener that a block was added at the given height, with the transaction data possibly filtered.
Sourcefn blocks_disconnected(&self, fork_point_block: BestBlock)
fn blocks_disconnected(&self, fork_point_block: BestBlock)
Notifies the listener that one or more blocks were removed in anticipation of a reorg.
The provided BestBlock is the new best block after disconnecting blocks in the reorg
but before connecting new ones (i.e. the “fork point” block). For backwards compatibility,
you may instead walk the chain backwards, calling blocks_disconnected for each block
that is disconnected in a reorg.
Provided Methods§
Sourcefn block_connected(&self, block: &Block, height: u32)
fn block_connected(&self, block: &Block, height: u32)
Notifies the listener that a block was added at the given height.