Skip to content

Commit

Permalink
feat: dump command
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Jan 18, 2024
1 parent c231383 commit 55e6498
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/silius/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ dirs = "5.0.1"
expanded-pathbuf = { workspace = true }
eyre = { workspace = true }
log = "0.4.20"
serde_json = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
23 changes: 22 additions & 1 deletion bin/silius/src/cli/commands.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use super::args::{BundlerAndUoPoolArgs, BundlerArgs, CreateWalletArgs, RpcArgs, UoPoolArgs};
use crate::bundler::{create_wallet, launch_bundler, launch_bundling, launch_rpc, launch_uopool};
use clap::Parser;
use silius_mempool::{init_env, DatabaseTable, UserOperationOp, UserOperations, WriteMap};
use silius_primitives::provider::{
create_http_block_streams, create_http_provider, create_ws_block_streams, create_ws_provider,
};
use std::{future::pending, sync::Arc};
use std::{future::pending, path::PathBuf, sync::Arc};

/// Start the bundler with all components (bundling component, user operation mempool, RPC server)
#[derive(Debug, Parser)]
Expand Down Expand Up @@ -199,3 +200,23 @@ impl CreateWalletCommand {
create_wallet(self.create_wallet)
}
}

/// Dump the database
#[derive(Debug, Parser)]
/// Represents the `Dump` command.
pub struct Dump {
/// The directory where the data will be dumped.
#[clap(long)]
data_dir: PathBuf,
}

impl Dump {
/// Execute the command
pub fn execute(self) -> eyre::Result<()> {
let env = Arc::new(init_env::<WriteMap>(self.data_dir).expect("Init mdbx failed"));
let table = DatabaseTable::<WriteMap, UserOperations>::new(env.clone());
let uo = table.get_all()?;
serde_json::to_writer(std::io::stdout(), &uo)?;
Ok(())
}
}
4 changes: 4 additions & 0 deletions bin/silius/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ pub enum Commands {
/// Create wallet for bundling component
#[command(name = "create-wallet")]
CreateWallet(commands::CreateWalletCommand),

/// Dump the database
#[command(name = "dump")]
Dump(commands::Dump),
}

pub fn run() -> eyre::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/user_operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use ssz_rs::List;
use std::{cmp::Ord, ops::Deref, slice::Windows};

/// User operation with hash
#[derive(AsRef, Deref, Debug, Clone)]
#[derive(AsRef, Deref, Debug, Clone, Serialize, Deserialize)]
pub struct UserOperation {
/// Hash of the user operation
pub hash: UserOperationHash,
Expand Down

0 comments on commit 55e6498

Please sign in to comment.