2021-08-26 18:34:33 -07:00
|
|
|
//! Chain tip interfaces.
|
|
|
|
|
2021-08-30 11:42:07 -07:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2021-08-29 19:38:41 -07:00
|
|
|
use crate::{block, transaction};
|
2021-08-26 18:34:33 -07:00
|
|
|
|
|
|
|
/// An interface for querying the chain tip.
|
|
|
|
///
|
|
|
|
/// This trait helps avoid dependencies between:
|
|
|
|
/// * zebra-chain and tokio
|
|
|
|
/// * zebra-network and zebra-state
|
|
|
|
pub trait ChainTip {
|
|
|
|
/// Return the height of the best chain tip.
|
|
|
|
fn best_tip_height(&self) -> Option<block::Height>;
|
2021-08-27 12:18:47 -07:00
|
|
|
|
|
|
|
/// Return the block hash of the best chain tip.
|
|
|
|
fn best_tip_hash(&self) -> Option<block::Hash>;
|
2021-08-29 19:38:41 -07:00
|
|
|
|
|
|
|
/// Return the mined transaction IDs of the transactions in the best chain tip block.
|
|
|
|
///
|
|
|
|
/// All transactions with these mined IDs should be rejected from the mempool,
|
|
|
|
/// even if their authorizing data is different.
|
2021-08-30 11:42:07 -07:00
|
|
|
fn best_tip_mined_transaction_ids(&self) -> Arc<[transaction::Hash]>;
|
2021-08-26 18:34:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A chain tip that is always empty.
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub struct NoChainTip;
|
|
|
|
|
|
|
|
impl ChainTip for NoChainTip {
|
|
|
|
fn best_tip_height(&self) -> Option<block::Height> {
|
|
|
|
None
|
|
|
|
}
|
2021-08-27 12:18:47 -07:00
|
|
|
|
|
|
|
fn best_tip_hash(&self) -> Option<block::Hash> {
|
|
|
|
None
|
|
|
|
}
|
2021-08-29 19:38:41 -07:00
|
|
|
|
2021-08-30 11:42:07 -07:00
|
|
|
fn best_tip_mined_transaction_ids(&self) -> Arc<[transaction::Hash]> {
|
|
|
|
Arc::new([])
|
2021-08-29 19:38:41 -07:00
|
|
|
}
|
2021-08-26 18:34:33 -07:00
|
|
|
}
|