From 449f9aeaa6bd85f3ac1f1a1859bae734b70ebbb8 Mon Sep 17 00:00:00 2001 From: Bohdan Ohorodnii Date: Mon, 13 Nov 2023 12:16:52 +0200 Subject: [PATCH] polish code --- api/src/handlers/compile.rs | 4 ++-- api/src/handlers/save_code.rs | 2 +- api/src/main.rs | 6 +++--- api/src/utils/hardhat_config.rs | 21 ++++++++++++------- api/src/utils/lib.rs | 2 +- .../components/BackgroundNotices/index.tsx | 2 +- plugin/src/features/CompilerVersion/index.tsx | 4 ++-- plugin/src/features/Deployment/index.tsx | 5 ----- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/api/src/handlers/compile.rs b/api/src/handlers/compile.rs index 6a948208..a1227b61 100644 --- a/api/src/handlers/compile.rs +++ b/api/src/handlers/compile.rs @@ -2,7 +2,7 @@ use crate::handlers::process::{do_process_command, fetch_process_result}; use crate::handlers::types::{ApiCommand, ApiCommandResult, CompileResponse, SolFile}; use crate::rate_limiter::RateLimited; use crate::types::{ApiError, Result}; -use crate::utils::hardhat_config::{HardhatConfig, HardhatConfigBuilder}; +use crate::utils::hardhat_config::HardhatConfigBuilder; use crate::utils::lib::{ check_file_ext, get_file_path, path_buf_to_string, status_code_to_message, to_human_error_batch, ALLOWED_VERSIONS, ARTIFACTS_ROOT, SOL_ROOT, @@ -71,7 +71,7 @@ pub async fn do_compile( version: String, remix_file_path: PathBuf, ) -> Result> { - if ALLOWED_VERSIONS.contains(&version.as_str()) == false { + if !ALLOWED_VERSIONS.contains(&version.as_str()) { return Err(ApiError::VersionNotSupported(version)); } diff --git a/api/src/handlers/save_code.rs b/api/src/handlers/save_code.rs index ab313ab7..b66ccf1b 100644 --- a/api/src/handlers/save_code.rs +++ b/api/src/handlers/save_code.rs @@ -22,7 +22,7 @@ pub async fn do_save_code( version: String, remix_file_path: PathBuf, ) -> Result { - if (ALLOWED_VERSIONS.contains(&version.as_str())) == false { + if !ALLOWED_VERSIONS.contains(&version.as_str()) { return Err(ApiError::VersionNotSupported(version)); } diff --git a/api/src/main.rs b/api/src/main.rs index 5e6af92b..442ab82c 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -22,9 +22,9 @@ use tracing::info; #[launch] async fn rocket() -> _ { - // if let Err(err) = init_logger() { - // eprintln!("Error initializing logger: {}", err); - // } + if let Err(err) = init_logger() { + eprintln!("Error initializing logger: {}", err); + } let number_of_workers = match std::env::var("WORKER_THREADS") { Ok(v) => v.parse::().unwrap_or(2u32), diff --git a/api/src/utils/hardhat_config.rs b/api/src/utils/hardhat_config.rs index 680fd412..3aea091c 100644 --- a/api/src/utils/hardhat_config.rs +++ b/api/src/utils/hardhat_config.rs @@ -11,29 +11,30 @@ pub struct HardhatConfig { pub paths: PathsConfig, } -#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Default)] pub struct ZksolcConfig { pub version: String, pub settings: serde_json::Value, } -#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Default)] pub struct SolidityConfig { pub version: String, } -#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Default)] pub struct PathsConfig { pub sources: String, pub artifacts: String, } +#[derive(Default)] pub struct HardhatConfigBuilder { config: HardhatConfig, } -impl HardhatConfig { - pub fn new() -> Self { +impl Default for HardhatConfig { + fn default() -> Self { Self { name: Self::generate_random_name(), zksolc: ZksolcConfig { @@ -49,6 +50,12 @@ impl HardhatConfig { }, } } +} + +impl HardhatConfig { + pub fn new() -> Self { + Self::default() + } pub fn to_string_config(&self) -> String { let config_prefix_js = r#" @@ -122,9 +129,7 @@ export default config; impl HardhatConfigBuilder { pub fn new() -> Self { - Self { - config: HardhatConfig::new(), - } + Self::default() } pub fn zksolc_version(&mut self, version: &str) -> &mut Self { diff --git a/api/src/utils/lib.rs b/api/src/utils/lib.rs index 469ca284..e3fe1e34 100644 --- a/api/src/utils/lib.rs +++ b/api/src/utils/lib.rs @@ -128,7 +128,7 @@ pub fn to_human_error( pub fn to_human_error_batch(diagnostics: Vec) -> String { diagnostics .into_iter() - .map(|diagnostic| to_human_error(diagnostic)) + .map(to_human_error) .collect::>() .join("\n") } diff --git a/plugin/src/components/BackgroundNotices/index.tsx b/plugin/src/components/BackgroundNotices/index.tsx index 10adffca..d039d640 100644 --- a/plugin/src/components/BackgroundNotices/index.tsx +++ b/plugin/src/components/BackgroundNotices/index.tsx @@ -1,7 +1,7 @@ import React from 'react' const Notices = [ - 'The zksync Remix Plugin is in Alpha', + 'The zkSync Remix Plugin is in Alpha', 'Solidity contracts are compiled on a server hosted by Nethermind' ] diff --git a/plugin/src/features/CompilerVersion/index.tsx b/plugin/src/features/CompilerVersion/index.tsx index 87bdf675..cab08995 100644 --- a/plugin/src/features/CompilerVersion/index.tsx +++ b/plugin/src/features/CompilerVersion/index.tsx @@ -38,8 +38,8 @@ const SolidityVersion: React.FC = () => { setVersions(allowedVersions) - if (versions.length > 0 && solidityVersion === '') { - setSolidityVersion(versions[0]) + if (allowedVersions.length > 0) { + setSolidityVersion(allowedVersions[0]) } } } catch (e) { diff --git a/plugin/src/features/Deployment/index.tsx b/plugin/src/features/Deployment/index.tsx index ef907117..7c6ff2e9 100644 --- a/plugin/src/features/Deployment/index.tsx +++ b/plugin/src/features/Deployment/index.tsx @@ -76,11 +76,6 @@ const Deployment: React.FC = ({ setActiveTab }) => { type: 'info' }) - remixClient.terminal.log({ - value: `Abi: ${JSON.stringify(selectedContract.abi, null, 2)}`, - type: 'info' - }) - const factory = new zksync.ContractFactory( selectedContract.abi, selectedContract.bytecode,