diff --git a/crates/mempool_node/src/communication.rs b/crates/mempool_node/src/communication.rs new file mode 100644 index 000000000..6dc3fffe2 --- /dev/null +++ b/crates/mempool_node/src/communication.rs @@ -0,0 +1,38 @@ +use starknet_mempool_types::communication::MempoolRequestAndResponseSender; +use tokio::sync::mpsc::{channel, Receiver, Sender}; + +pub struct ComponentCommunication { + tx: Sender, + rx: Option>, +} + +impl ComponentCommunication { + fn get_tx(&self) -> Sender { + self.tx.clone() + } + fn get_rx(&mut self) -> Receiver { + self.rx.take().expect("Receiver already taken") + } +} + +pub struct MempoolNodeCommunication { + mempool_channel: ComponentCommunication, +} + +impl MempoolNodeCommunication { + pub fn get_mempool_tx(&self) -> Sender { + self.mempool_channel.get_tx() + } + pub fn get_mempool_rx(&mut self) -> Receiver { + self.mempool_channel.get_rx() + } +} + +pub fn create_node_channels() -> MempoolNodeCommunication { + const MEMPOOL_INVOCATIONS_QUEUE_SIZE: usize = 32; + let (tx_mempool, rx_mempool) = + channel::(MEMPOOL_INVOCATIONS_QUEUE_SIZE); + MempoolNodeCommunication { + mempool_channel: ComponentCommunication { tx: tx_mempool, rx: Some(rx_mempool) }, + } +}