Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion crates/l2/networking/rpc/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use ethrex_rpc::{
EthClientError,
eth::{
RpcResponse,
errors::{GetBaseFeeVaultAddressError, GetBatchByNumberError, GetMessageProofError},
errors::{
GetBaseFeeVaultAddressError, GetBatchByNumberError, GetBatchNumberError,
GetMessageProofError,
},
},
},
utils::RpcRequest,
Expand Down Expand Up @@ -55,6 +58,27 @@ pub async fn get_batch_by_number(
}
}

pub async fn get_batch_number(client: &EthClient) -> Result<u64, EthClientError> {
let request = RpcRequest::new("ethrex_batchNumber", None);

match client.send_request(request).await? {
RpcResponse::Success(result) => {
let batch_number_hex: String = serde_json::from_value(result.result)
.map_err(GetBatchNumberError::SerdeJSONError)
.map_err(EthClientError::from)?;
let hex_str = batch_number_hex
.strip_prefix("0x")
.unwrap_or(&batch_number_hex);
u64::from_str_radix(hex_str, 16)
.map_err(GetBatchNumberError::ParseIntError)
.map_err(EthClientError::from)
}
RpcResponse::Error(error_response) => {
Err(GetBatchNumberError::RPCError(error_response.error.message).into())
}
}
}

pub async fn get_base_fee_vault_address(
client: &EthClient,
block: BlockIdentifier,
Expand Down
12 changes: 12 additions & 0 deletions crates/networking/rpc/clients/eth/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub enum EthClientError {
FailedToGetTxPool(#[from] TxPoolContentError),
#[error("ethrex_getBatchByNumber request error: {0}")]
GetBatchByNumberError(#[from] GetBatchByNumberError),
#[error("ethrex_batchNumber request error: {0}")]
GetBatchNumberError(#[from] GetBatchNumberError),
#[error("ethrex_getBlobBaseFee request error: {0}")]
GetBlobBaseFeeError(#[from] GetBlobBaseFeeRequestError),
#[error("All RPC calls failed")]
Expand Down Expand Up @@ -327,6 +329,16 @@ pub enum GetBatchByNumberError {
RPCError(String),
}

#[derive(Debug, thiserror::Error)]
pub enum GetBatchNumberError {
#[error("{0}")]
SerdeJSONError(#[from] serde_json::Error),
#[error("{0}")]
RPCError(String),
#[error("{0}")]
ParseIntError(#[from] std::num::ParseIntError),
}

Comment on lines +334 to +343
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the enum above this has a TODO that says Move to L2, do you know if there's an issue created for that? Would it be easy to achieve?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find any. The closes was this

#[derive(Debug, thiserror::Error)]
pub enum GetEthConfigError {
#[error("{0}")]
Expand Down