Skip to content

Commit

Permalink
feat: add examples/run_on_mdbx.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-rise committed Aug 6, 2024
1 parent 10c5750 commit bdc0491
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions examples/run_on_mdbx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! Check mainnet blocks using [OnDiskStorage]
//! For help, run: `cargo run --example run_on_mdbx -- --help`

#![allow(missing_docs)]

use std::{
fs::File,
io::{BufReader, Error},
};

use alloy_rpc_types::Block;
use clap::Parser;
use pevm::{chain::PevmEthereum, OnDiskStorage, StorageWrapper};
use revm::db::CacheDB;

#[path = "../tests/common/mod.rs"]
pub mod common;

/// Check mainnet blocks using [OnDiskStorage]
#[derive(Parser, Debug)]
#[clap(name = "run_on_mdbx")]
struct Args {
/// Path to MDBX dir
#[clap(long, value_name = "DIR")]
mdbx: String,
/// Path to block.json file
#[clap(long, value_name = "FILE")]
block: String,
}

fn main() -> Result<(), Error> {
let args = Args::parse();

let block: Block = {
let file = File::open(args.block)?;
serde_json::from_reader(BufReader::new(file))?
};

let on_disk_storage = OnDiskStorage::open(args.mdbx).map_err(Error::other)?;
let wrapped_storage = StorageWrapper(&on_disk_storage);
let db = CacheDB::new(&wrapped_storage);

let chain = PevmEthereum::mainnet();
common::test_execute_alloy(&db, &chain, block, true);

Ok(())
}

0 comments on commit bdc0491

Please sign in to comment.