Skip to content

Commit

Permalink
Added type alias 'BlockWithReceipts'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eagle941 committed Oct 2, 2024
1 parent 7859ee6 commit 1f0a4ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion starknet-replay/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ use crate::{ReplayBlock, RunnerError};

pub mod rpc;

/// The type [`BlockWithReceipts`] bundles together all the block data: block
/// header, transaction data and receipt data.
pub type BlockWithReceipts = (BlockHeader, Vec<Transaction>, Vec<TransactionReceipt>);

pub trait Storage {
/// Returns the most recent block number available in the storage.
///
Expand Down Expand Up @@ -65,7 +69,7 @@ pub trait Storage {
fn get_transactions_and_receipts_for_block(
&self,
block_number: BlockNumber,
) -> Result<(BlockHeader, Vec<Transaction>, Vec<TransactionReceipt>), DatabaseError>;
) -> Result<BlockWithReceipts, DatabaseError>;

/// Replays the list of transactions in a block and returns the list of
/// transactions traces.
Expand Down
5 changes: 3 additions & 2 deletions starknet-replay/src/storage/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rpc_client::RpcClient;
use starknet_api::block::{BlockHeader, StarknetVersion};
use starknet_api::core::{ClassHash, ContractAddress, PatriciaKey};
use starknet_api::data_availability::L1DataAvailabilityMode;
use starknet_api::transaction::{Transaction, TransactionExecutionStatus, TransactionReceipt};
use starknet_api::transaction::{Transaction, TransactionExecutionStatus};
use starknet_api::{contract_address, felt, patricia_key};
use starknet_core::types::{
ContractClass,
Expand All @@ -41,6 +41,7 @@ use tracing::{error, info, warn};
use url::Url;

use self::visited_pcs::VisitedPcsRaw;
use super::BlockWithReceipts;
use crate::block_number::BlockNumber;
use crate::error::{DatabaseError, RunnerError};
use crate::runner::replay_block::ReplayBlock;
Expand Down Expand Up @@ -342,7 +343,7 @@ impl ReplayStorage for RpcStorage {
fn get_transactions_and_receipts_for_block(
&self,
block_number: BlockNumber,
) -> Result<(BlockHeader, Vec<Transaction>, Vec<TransactionReceipt>), DatabaseError> {
) -> Result<BlockWithReceipts, DatabaseError> {
let transactions = self
.rpc_client
.starknet_get_block_with_receipts(&block_number)?;
Expand Down
7 changes: 4 additions & 3 deletions starknet-replay/src/storage/rpc/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::error::DatabaseError;
use crate::runner::replay_class_hash::ReplayClassHash;
use crate::storage::rpc::receipt::convert_receipt;
use crate::storage::rpc::transaction::convert_transaction;
use crate::storage::BlockWithReceipts;

/// This structure partially implements a Starknet RPC client.
///
Expand Down Expand Up @@ -158,7 +159,7 @@ impl RpcClient {
let data_price_in_wei: u128 =
block.l1_data_gas_price.price_in_wei.to_string().parse()?;

let block_header: BlockHeader = BlockHeader {
let block_header = BlockHeader {
block_hash: BlockHash(Felt::from_bytes_be(&block.block_hash.to_bytes_be())),
parent_hash: BlockHash(Felt::from_bytes_be(&block.parent_hash.to_bytes_be())),
block_number: starknet_api::block::BlockNumber(block.block_number),
Expand Down Expand Up @@ -210,7 +211,7 @@ impl RpcClient {
pub async fn starknet_get_block_with_receipts(
&self,
block_number: &BlockNumber,
) -> Result<(BlockHeader, Vec<Transaction>, Vec<TransactionReceipt>), DatabaseError> {
) -> Result<BlockWithReceipts, DatabaseError> {
let block_id: BlockId = block_number.into();
let txs_with_receipts: MaybePendingBlockWithReceipts = self
.get_new_client()
Expand All @@ -228,7 +229,7 @@ impl RpcClient {
let data_price_in_wei: u128 =
block.l1_data_gas_price.price_in_wei.to_string().parse()?;

let block_header: BlockHeader = BlockHeader {
let block_header = BlockHeader {
block_hash: BlockHash(Felt::from_bytes_be(&block.block_hash.to_bytes_be())),
parent_hash: BlockHash(Felt::from_bytes_be(&block.parent_hash.to_bytes_be())),
block_number: starknet_api::block::BlockNumber(block.block_number),
Expand Down

0 comments on commit 1f0a4ae

Please sign in to comment.