From 8b4794de68f83f653cfc249706c1b8eceac84fc2 Mon Sep 17 00:00:00 2001 From: Vid Kersic Date: Fri, 25 Nov 2022 11:15:10 +0100 Subject: [PATCH] changed all println! to info!, different default output path --- .gitignore | 5 +---- Cargo.lock | 1 + Cargo.toml | 1 + Makefile | 4 ++-- README.md | 4 ++-- bin/bundler.rs | 2 +- bin/create-wallet.rs | 18 ++++++++++++++---- src/models/wallet.rs | 3 +++ src/res/bundler/.gitkeep | 0 src/rpc/eth.rs | 6 +++--- 10 files changed, 28 insertions(+), 16 deletions(-) delete mode 100644 src/res/bundler/.gitkeep diff --git a/.gitignore b/.gitignore index 3de95e19..dac30f6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ # Rust -/target - -# bundler wallets -/src/res/bundler/0x* \ No newline at end of file +/target \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 005b6ef3..02d5e3e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,7 @@ dependencies = [ "async-trait", "bytes", "clap", + "dirs", "educe", "ethereum-interfaces", "ethereum-types 0.14.0", diff --git a/Cargo.toml b/Cargo.toml index 52970d9d..98a03e73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ anyhow = "1" async-trait = "0.1" bytes = { version = "1", features = ["serde"] } clap = { version = "4", features = ["derive"] } +dirs = "4.0" educe = { version = "0.4", features = ["Debug", "Default"] } ethereum-interfaces = { git = "https://github.com/ledgerwatch/interfaces" } ethereum-types = { version = "0.14", features = ["codec"] } diff --git a/Makefile b/Makefile index 872ff4a6..1d589dac 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ run-bundler: - cargo run -- --mnemonic-file ./src/res/bundler/0xF78bB01dFd478608F5738fB0560642b2806D295E + cargo run -- --mnemonic-file ${HOME}/.aa-bundler/0x129D197b2a989C6798601A49D89a4AEC822A17a3 run-bundler-uopool: cargo run --bin bundler-uopool @@ -8,7 +8,7 @@ run-bundler-rpc: cargo run --bin bundler-rpc run-create-wallet: - cargo run --bin create-wallet -- --output-folder ./src/res/bundler + cargo run --bin create-wallet -- --output-path ${HOME}/.aa-bundler cargo-fmt: cargo fmt --all diff --git a/README.md b/README.md index e3671f64..00be94d3 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ For more information: https://hackmd.io/@Vid201/aa-bundler-rust Create wallet for bundler: ```bash -cargo run --bin create-wallet -- --output-folder ./src/res/bundler +cargo run --bin create-wallet -- --output-path ${HOME}/.aa-bundler ``` Run bundler (with user operation pool and JSON-RPC API): ```bash -cargo run -- --mnemonic-file ./src/res/bundler/0xF78bB01dFd478608F5738fB0560642b2806D295E +cargo run -- --mnemonic-file ${HOME}/.aa-bundler/0x129D197b2a989C6798601A49D89a4AEC822A17a3 ``` Run only user operation pool: diff --git a/bin/bundler.rs b/bin/bundler.rs index 3bf9cb0d..4c3664b5 100644 --- a/bin/bundler.rs +++ b/bin/bundler.rs @@ -50,7 +50,7 @@ fn main() -> Result<()> { info!("Starting AA - Bundler"); let wallet = Wallet::from_file(opt.mnemonic_file); - println!("{:?}", wallet.signer); + info!("{:?}", wallet.signer); let bundler = Bundler::new(wallet); diff --git a/bin/create-wallet.rs b/bin/create-wallet.rs index 0563e4f0..fd846ac5 100644 --- a/bin/create-wallet.rs +++ b/bin/create-wallet.rs @@ -1,7 +1,10 @@ use aa_bundler::models::wallet::Wallet; use anyhow::Result; use clap::Parser; +use dirs::home_dir; use expanded_pathbuf::ExpandedPathBuf; +use jsonrpsee::tracing::info; +use std::str::FromStr; #[derive(Parser)] #[clap( @@ -9,8 +12,8 @@ use expanded_pathbuf::ExpandedPathBuf; about = "Bundler's wallet creation for EIP-4337 Account Abstraction" )] pub struct Opt { - #[clap(long, default_value = "./src/res/bundler")] - pub output_folder: ExpandedPathBuf, + #[clap(long)] + pub output_path: Option, } fn main() -> Result<()> { @@ -18,8 +21,15 @@ fn main() -> Result<()> { tracing_subscriber::fmt::init(); - let wallet = Wallet::new(opt.output_folder); - println!("{:?}", wallet.signer); + let path = if let Some(output_path) = opt.output_path { + output_path + } else { + ExpandedPathBuf::from_str(home_dir().unwrap().join(".aa-bundler").to_str().unwrap()) + .unwrap() + }; + + let wallet = Wallet::new(path); + info!("{:?}", wallet.signer); Ok(()) } diff --git a/src/models/wallet.rs b/src/models/wallet.rs index c116da67..1dec1df1 100644 --- a/src/models/wallet.rs +++ b/src/models/wallet.rs @@ -3,6 +3,7 @@ use ethers::{ signers::{coins_bip39::English, MnemonicBuilder}, }; use expanded_pathbuf::ExpandedPathBuf; +use std::fs; pub struct Wallet { pub signer: ethers::signers::Wallet, @@ -12,6 +13,8 @@ impl Wallet { pub fn new(output_path: ExpandedPathBuf) -> Self { let mut rng = rand::thread_rng(); + fs::create_dir_all(output_path.to_path_buf()).unwrap(); + Self { signer: MnemonicBuilder::::default() .write_to(output_path.to_path_buf()) diff --git a/src/res/bundler/.gitkeep b/src/res/bundler/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/rpc/eth.rs b/src/rpc/eth.rs index c0871f1d..9106216e 100644 --- a/src/rpc/eth.rs +++ b/src/rpc/eth.rs @@ -1,7 +1,7 @@ use crate::{rpc::eth_api::EthApiServer, types::user_operation::UserOperation}; use async_trait::async_trait; use ethereum_types::{Address, U64}; -use jsonrpsee::core::RpcResult; +use jsonrpsee::{core::RpcResult, tracing::info}; pub struct EthApiServerImpl { pub call_gas_limit: u64, @@ -22,8 +22,8 @@ impl EthApiServer for EthApiServerImpl { user_operation: UserOperation, entry_point: Address, ) -> RpcResult { - println!("{:?}", user_operation); - println!("{:?}", entry_point); + info!("{:?}", user_operation); + info!("{:?}", entry_point); Ok(true) } }