diff --git a/.github/CI.yml b/.github/CI.yml new file mode 100644 index 00000000..233c1df9 --- /dev/null +++ b/.github/CI.yml @@ -0,0 +1,25 @@ +on: [push] + +name: CI + +jobs: + build_and_test: + name: Rust project + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt, clippy + - name: Setup + run: | + make fetch-thirdparty + - name: Lint + run: | + make lint + - name: Test + run: | + make cargo-test + + diff --git a/.gitignore b/.gitignore index dac30f6d..cf782bca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # Rust -/target \ No newline at end of file +/target +.local \ No newline at end of file diff --git a/Makefile b/Makefile index 32621f4a..f7c43050 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,10 @@ run-create-wallet: cargo-fmt: cargo fmt --all +lint: + cargo fmt --all -- --check + cargo clippy -- -D warnings -A clippy::derive_partial_eq_without_eq + cargo-test: cargo test diff --git a/bin/bundler-rpc.rs b/bin/bundler-rpc.rs index 32a96215..9847cbb1 100644 --- a/bin/bundler-rpc.rs +++ b/bin/bundler-rpc.rs @@ -2,7 +2,6 @@ use anyhow::Result; use clap::Parser; use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder, tracing::info}; use std::future::pending; -use tracing_subscriber; use aa_bundler::rpc::{eth::EthApiServerImpl, eth_api::EthApiServer}; diff --git a/bin/bundler.rs b/bin/bundler.rs index 00862aef..acead157 100644 --- a/bin/bundler.rs +++ b/bin/bundler.rs @@ -1,5 +1,5 @@ use aa_bundler::{ - bundler::bundler::Bundler, + bundler::Bundler, models::wallet::Wallet, rpc::{eth::EthApiServerImpl, eth_api::EthApiServer}, }; diff --git a/build.rs b/build.rs index f1cb87e2..80322675 100644 --- a/build.rs +++ b/build.rs @@ -4,7 +4,7 @@ use ethers::solc::{Project, ProjectPathsConfig}; fn config() -> prost_build::Config { let mut config = prost_build::Config::new(); - config.bytes(&["."]); + config.bytes(["."]); config } diff --git a/src/bundler/bundler.rs b/src/bundler/bundler.rs deleted file mode 100644 index b1e967a3..00000000 --- a/src/bundler/bundler.rs +++ /dev/null @@ -1,11 +0,0 @@ -use crate::models::wallet::Wallet; - -pub struct Bundler { - pub wallet: Wallet, -} - -impl Bundler { - pub fn new(wallet: Wallet) -> Self { - Self { wallet } - } -} diff --git a/src/bundler/mod.rs b/src/bundler/mod.rs index 26ba97a7..e67cb73a 100644 --- a/src/bundler/mod.rs +++ b/src/bundler/mod.rs @@ -1,10 +1,10 @@ -pub mod bundler; - use std::str::FromStr; use clap::Parser; use ethers::types::{Address, U256}; +use crate::models::wallet::Wallet; + #[derive(Debug, Parser, PartialEq)] pub struct BundlerOpts { #[clap(long, value_parser=parse_address)] @@ -34,6 +34,16 @@ fn parse_u256(s: &str) -> Result { U256::from_str_radix(s, 10).map_err(|_| format!("{} is not a valid U256", s)) } +pub struct Bundler { + pub wallet: Wallet, +} + +impl Bundler { + pub fn new(wallet: Wallet) -> Self { + Self { wallet } + } +} + #[cfg(test)] mod test { use super::*; diff --git a/src/contracts/entrypoint.rs b/src/contracts/entrypoint.rs index e6b1c4b3..c2729597 100644 --- a/src/contracts/entrypoint.rs +++ b/src/contracts/entrypoint.rs @@ -3,7 +3,6 @@ use std::sync::Arc; use anyhow; use ethers::abi::AbiDecode; -use ethers::prelude::ContractError; use ethers::providers::Middleware; use ethers::types::{Address, Bytes}; use regex::Regex; @@ -23,7 +22,7 @@ impl EntryPoint { let api = EntryPointAPI::new(entry_point_address, provider.clone()); Self { provider, - entry_point_address: entry_point_address, + entry_point_address, api, } } @@ -39,7 +38,7 @@ impl EntryPoint { fn deserialize_error_msg( err_msg: &str, ) -> Result { - JsonRpcError::from_str(&err_msg) + JsonRpcError::from_str(err_msg) .map_err(|_| { EntryPointErr::DecodeErr(format!( "{:?} is not a valid JsonRpcError message", @@ -115,7 +114,7 @@ impl EntryPoint { }) } - async fn get_sender_address>( + pub async fn get_sender_address>( &self, initcode: Bytes, ) -> Result { @@ -141,10 +140,10 @@ impl EntryPoint { } } - async fn handle_aggregated_ops>( + pub async fn handle_aggregated_ops>( &self, - ops_per_aggregator: Vec, - beneficiary: Address, + _ops_per_aggregator: Vec, + _beneficiary: Address, ) -> Result<(), EntryPointErr> { todo!() } diff --git a/src/models/wallet.rs b/src/models/wallet.rs index 1dec1df1..4d6c216b 100644 --- a/src/models/wallet.rs +++ b/src/models/wallet.rs @@ -13,7 +13,7 @@ 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(); + fs::create_dir_all(&output_path).unwrap(); Self { signer: MnemonicBuilder::::default() diff --git a/src/types/user_operation.rs b/src/types/user_operation.rs index 57f2e658..918e3302 100644 --- a/src/types/user_operation.rs +++ b/src/types/user_operation.rs @@ -1,6 +1,6 @@ use ethers::abi::AbiEncode; use ethers::prelude::{EthAbiCodec, EthAbiType}; -use ethers::types::{Address, Bytes, H256, U256, TransactionReceipt}; +use ethers::types::{Address, Bytes, TransactionReceipt, H256, U256}; use ethers::utils::keccak256; use serde::{Deserialize, Serialize}; use std::str::FromStr; diff --git a/src/uopool/mod.rs b/src/uopool/mod.rs index 50aa8a45..c8e6d113 100644 --- a/src/uopool/mod.rs +++ b/src/uopool/mod.rs @@ -1,6 +1,6 @@ use crate::{ types::user_operation::{UserOperation, UserOperationHash}, - uopool::{server::server::uo_pool_server::UoPoolServer, services::UoPoolService}, + uopool::{server::uopool_server::uo_pool_server::UoPoolServer, services::UoPoolService}, }; use anyhow::Result; use clap::Parser; @@ -26,6 +26,12 @@ impl UserOperationPool { } } +impl Default for UserOperationPool { + fn default() -> Self { + Self::new() + } +} + #[derive(Educe, Parser)] #[educe(Debug)] pub struct UoPoolOpts { diff --git a/src/uopool/server.rs b/src/uopool/server.rs index cd913698..823dd49a 100644 --- a/src/uopool/server.rs +++ b/src/uopool/server.rs @@ -2,6 +2,6 @@ mod types { tonic::include_proto!("types"); } -pub mod server { +pub mod uopool_server { tonic::include_proto!("uopool"); } diff --git a/src/uopool/services/uopool.rs b/src/uopool/services/uopool.rs index 30bfb219..a530be10 100644 --- a/src/uopool/services/uopool.rs +++ b/src/uopool/services/uopool.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use crate::uopool::{ - server::server::{ + server::uopool_server::{ uo_pool_server::UoPool, AddRequest, AddResponse, AllRequest, AllResponse, RemoveRequest, RemoveResponse, },