Trait TxPool

Source
pub trait TxPool:
    Send
    + Sync
    + 'static {
    // Required methods
    fn validate_transaction(&self, tx: Transaction) -> TxValidationResult;
    fn contains(&self, txid: &Txid) -> bool;
    fn get(&self, txid: &Txid) -> Option<Arc<Transaction>>;
    fn pending_broadcast(&self) -> Vec<(Txid, u64)>;
    fn mark_broadcast(&self, txids: &[Txid]);
    fn iter_txids(&self) -> Box<dyn Iterator<Item = (Txid, u64)> + Send>;
    fn info(&self) -> TxPoolInfo;
}
Expand description

Bitcoin transaction pool trait for network integration.

This trait abstracts mempool operations needed by the network layer, avoiding circular dependencies and enabling testing with mock implementations.

All methods are synchronous - the caller can decide whether to run them on a blocking executor (e.g., Substrate’s spawn_blocking) or inline.

Required Methods§

Source

fn validate_transaction(&self, tx: Transaction) -> TxValidationResult

Validate and potentially accept a transaction into the mempool.

This is a blocking operation that holds internal locks and performs script validation. The caller should run this on a blocking executor if needed (e.g., task_manager.spawn_blocking()).

Source

fn contains(&self, txid: &Txid) -> bool

Check if transaction is already in mempool.

Source

fn get(&self, txid: &Txid) -> Option<Arc<Transaction>>

Get transaction from mempool if present.

Source

fn pending_broadcast(&self) -> Vec<(Txid, u64)>

Get transactions pending broadcast to peers. Returns (txid, fee_rate) pairs.

Source

fn mark_broadcast(&self, txids: &[Txid])

Mark transactions as broadcast to peers.

Source

fn iter_txids(&self) -> Box<dyn Iterator<Item = (Txid, u64)> + Send>

Iterate over all transaction IDs with their fee rates. Returns (txid, fee_rate) pairs sorted by mining priority.

Source

fn info(&self) -> TxPoolInfo

Get mempool statistics.

Implementors§