fuel_core_p2p/
ports.rs

1use fuel_core_services::stream::BoxStream;
2use fuel_core_storage::Result as StorageResult;
3use fuel_core_types::{
4    blockchain::{
5        SealedBlockHeader,
6        consensus::Genesis,
7    },
8    fuel_tx::{
9        Bytes64,
10        TxId,
11    },
12    fuel_types::BlockHeight,
13    services::p2p::{
14        DelegatePublicKey,
15        GossipData,
16        NetworkableTransactionPool,
17        PreConfirmationMessage,
18        ProtocolSignature,
19        Transactions,
20    },
21};
22use std::ops::Range;
23
24pub trait P2pDb: Send + Sync {
25    fn get_sealed_headers(
26        &self,
27        block_height_range: Range<u32>,
28    ) -> StorageResult<Option<Vec<SealedBlockHeader>>>;
29
30    fn get_transactions(
31        &self,
32        block_height_range: Range<u32>,
33    ) -> StorageResult<Option<Vec<Transactions>>>;
34
35    fn get_genesis(&self) -> StorageResult<Genesis>;
36}
37
38pub trait BlockHeightImporter: Send + Sync {
39    /// Creates a stream of next block heights
40    fn next_block_height(&self) -> BoxStream<BlockHeight>;
41}
42
43pub trait TxPool: Send + Sync + Clone {
44    /// Get all tx ids in the pool
45    fn get_tx_ids(
46        &self,
47        max_ids: usize,
48    ) -> impl std::future::Future<Output = anyhow::Result<Vec<TxId>>> + Send;
49
50    /// Get full txs from the pool
51    fn get_full_txs(
52        &self,
53        tx_ids: Vec<TxId>,
54    ) -> impl std::future::Future<
55        Output = anyhow::Result<Vec<Option<NetworkableTransactionPool>>>,
56    > + Send;
57}
58
59pub type P2PPreConfirmationMessage =
60    PreConfirmationMessage<DelegatePublicKey, Bytes64, ProtocolSignature>;
61
62pub type P2PPreConfirmationGossipData = GossipData<P2PPreConfirmationMessage>;