From 9fa54a1ec495d6a795d3dd7fd7e214105e69691d Mon Sep 17 00:00:00 2001 From: Lev Roitman Date: Thu, 20 Jun 2024 12:59:08 +0300 Subject: [PATCH] feat: add function to create all channels commit-id:4cc36c62 --- crates/mempool_node/src/communication.rs | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 crates/mempool_node/src/communication.rs 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) }, + } +}