From 2b0f9e2c57ef92f16aaf95afc41f831a94498304 Mon Sep 17 00:00:00 2001 From: giladchase Date: Thu, 12 Dec 2024 13:33:42 +0200 Subject: [PATCH] refactor(starknet_batcher): add result type (#2652) Co-Authored-By: Gilad Chase --- crates/starknet_batcher/src/transaction_provider.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/starknet_batcher/src/transaction_provider.rs b/crates/starknet_batcher/src/transaction_provider.rs index fba810cb07..402cd51317 100644 --- a/crates/starknet_batcher/src/transaction_provider.rs +++ b/crates/starknet_batcher/src/transaction_provider.rs @@ -11,6 +11,8 @@ use starknet_mempool_types::communication::{MempoolClientError, SharedMempoolCli use thiserror::Error; use tracing::warn; +type TransactionProviderResult = Result; + #[derive(Clone, Debug, Error)] pub enum TransactionProviderError { #[error(transparent)] @@ -28,7 +30,7 @@ pub enum NextTxs { #[cfg_attr(test, automock)] #[async_trait] pub trait TransactionProvider: Send { - async fn get_txs(&mut self, n_txs: usize) -> Result; + async fn get_txs(&mut self, n_txs: usize) -> TransactionProviderResult; } #[derive(Clone)] @@ -69,7 +71,7 @@ impl ProposeTransactionProvider { async fn get_mempool_txs( &mut self, n_txs: usize, - ) -> Result, TransactionProviderError> { + ) -> TransactionProviderResult> { Ok(self .mempool_client .get_txs(n_txs) @@ -82,7 +84,7 @@ impl ProposeTransactionProvider { #[async_trait] impl TransactionProvider for ProposeTransactionProvider { - async fn get_txs(&mut self, n_txs: usize) -> Result { + async fn get_txs(&mut self, n_txs: usize) -> TransactionProviderResult { assert!(n_txs > 0, "The number of transactions requested must be greater than zero."); let mut txs = vec![]; if self.phase == TxProviderPhase::L1 { @@ -118,7 +120,7 @@ pub struct ValidateTransactionProvider { #[async_trait] impl TransactionProvider for ValidateTransactionProvider { - async fn get_txs(&mut self, n_txs: usize) -> Result { + async fn get_txs(&mut self, n_txs: usize) -> TransactionProviderResult { assert!(n_txs > 0, "The number of transactions requested must be greater than zero."); let mut buffer = Vec::with_capacity(n_txs); self.tx_receiver.recv_many(&mut buffer, n_txs).await;