Skip to content

Commit

Permalink
RM struct and P
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Jan 16, 2025
1 parent 50c4976 commit 4b0dab0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion crates/protocol/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum OpBlockConversionError {

/// An error encountered during batch validation provider operations.
#[derive(Debug, thiserror::Error)]
pub(crate) enum ReqwestBatchValidationProviderError {
pub enum ReqwestBatchValidationProviderError {
/// Requested block does not exist.
#[error("Block not found: {0}")]
BlockNotFound(u64),
Expand Down
41 changes: 18 additions & 23 deletions crates/protocol/src/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@
//! `Provider` generally.
use alloc::boxed::Box;
use alloy_consensus::{Block, BlockBody, Typed2718};
use alloy_consensus::{Block, BlockBody, TxEnvelope, Typed2718};
use alloy_eips::eip2718::Encodable2718;
use alloy_network::primitives::{BlockTransactions, BlockTransactionsKind};
use alloy_provider::Provider;
use alloy_network::{
primitives::{BlockTransactions, BlockTransactionsKind, HeaderResponse},
BlockResponse, Network,
};
use alloy_provider::{Provider, ReqwestProvider};
use async_trait::async_trait;
use maili_consensus::{DepositTxEnvelope, DEPOSIT_TX_TYPE_ID};

use crate::{
errors::ReqwestBatchValidationProviderError, BatchValidationProvider, BlockInfo, L2BlockInfo,
};

struct ReqwestBatchValidationProvider<T, N: Network<TxEnvelope = T>, ReqwestProvider<N>> {
provider: P,
_phantom: core::marker::PhantomData<T>,
}

#[async_trait]
impl<T, N> BatchValidationProvider for ReqwestBatchValidationProvider<T, N, ReqwestProvider<N>>
impl<N, H, T> BatchValidationProvider for ReqwestProvider<N>
where
N: Network<TxEnvelope = T, Header = H>,
H: alloy_consensus::BlockHeader,
T: DepositTxEnvelope + Encodable2718 + Typed2718 + Clone,
N: Network<TxEnvelope = T>,
{
type Error = ReqwestBatchValidationProviderError;

Expand All @@ -31,19 +30,19 @@ where
async fn l2_block_info_by_number(&mut self, number: u64) -> Result<L2BlockInfo, Self::Error> {
// Get the block from the provider.
let block = self
.provider
.get_block_by_number(number.into(), BlockTransactionsKind::Full)
.await?
.ok_or(ReqwestBatchValidationProviderError::BlockNotFound(number))?;

let header = block.header().as_ref();
// Create the L2 block info.
let block_info = BlockInfo::new(
block.header.hash,
block.header.number,
block.header.parent_hash,
block.header.timestamp,
block.header().hash(),
header.number(),
header.parent_hash(),
header.timestamp(),
);
let l1_origin = (block.header.number, block.header.hash); // TODO: We don't have valid values
let l1_origin = (header.number(), block.header().hash()); // TODO: We don't have valid values
// for this or access to genesis for
// L2BlockInfo::from_block_and_genesis().
let seq_num = 0u64; // TODO: We don't have this value either.
Expand All @@ -57,26 +56,22 @@ where
) -> Result<Block<Self::Transaction>, Self::Error> {
// Get the block from the provider.
let block = self
.provider
.get_block_by_number(number.into(), BlockTransactionsKind::Full)
.await?
.ok_or(ReqwestBatchValidationProviderError::BlockNotFound(number))?;

// Convert the transactions.
let transactions: Vec<T> = match block.transactions {
let transactions: Vec<T> = match block.transactions() {
BlockTransactions::Full(transactions) => Ok(transactions
.into_iter()
.map(|tx| if tx.is_type(DEPOSIT_TX_TYPE_ID) { todo!() } else { todo!() }) // TODO: Convert from alloy_rpc_types_eth::Transaction to T?
.collect()),
Err(err) => Err(ReqwestBatchValidationProviderError::InvalidBlock(
number,
err,
)),
Err(err) => Err(ReqwestBatchValidationProviderError::InvalidBlock(number, err)),
}?;

// Create the block.
Ok(Block {
header: block.header.into(),
header: block.header().as_ref().into(),
body: BlockBody {
transactions,
// TODO: fill
Expand Down

0 comments on commit 4b0dab0

Please sign in to comment.