Skip to content

Commit

Permalink
refactor(starknet_batcher): add result type (#2652)
Browse files Browse the repository at this point in the history
Co-Authored-By: Gilad Chase <gilad@starkware.com>
  • Loading branch information
giladchase and Gilad Chase authored Dec 12, 2024
1 parent b3c6b00 commit 2b0f9e2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/starknet_batcher/src/transaction_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use starknet_mempool_types::communication::{MempoolClientError, SharedMempoolCli
use thiserror::Error;
use tracing::warn;

type TransactionProviderResult<T> = Result<T, TransactionProviderError>;

#[derive(Clone, Debug, Error)]
pub enum TransactionProviderError {
#[error(transparent)]
Expand All @@ -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<NextTxs, TransactionProviderError>;
async fn get_txs(&mut self, n_txs: usize) -> TransactionProviderResult<NextTxs>;
}

#[derive(Clone)]
Expand Down Expand Up @@ -69,7 +71,7 @@ impl ProposeTransactionProvider {
async fn get_mempool_txs(
&mut self,
n_txs: usize,
) -> Result<Vec<Transaction>, TransactionProviderError> {
) -> TransactionProviderResult<Vec<Transaction>> {
Ok(self
.mempool_client
.get_txs(n_txs)
Expand All @@ -82,7 +84,7 @@ impl ProposeTransactionProvider {

#[async_trait]
impl TransactionProvider for ProposeTransactionProvider {
async fn get_txs(&mut self, n_txs: usize) -> Result<NextTxs, TransactionProviderError> {
async fn get_txs(&mut self, n_txs: usize) -> TransactionProviderResult<NextTxs> {
assert!(n_txs > 0, "The number of transactions requested must be greater than zero.");
let mut txs = vec![];
if self.phase == TxProviderPhase::L1 {
Expand Down Expand Up @@ -118,7 +120,7 @@ pub struct ValidateTransactionProvider {

#[async_trait]
impl TransactionProvider for ValidateTransactionProvider {
async fn get_txs(&mut self, n_txs: usize) -> Result<NextTxs, TransactionProviderError> {
async fn get_txs(&mut self, n_txs: usize) -> TransactionProviderResult<NextTxs> {
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;
Expand Down

0 comments on commit 2b0f9e2

Please sign in to comment.