From 89d410bffcc2a40306a757b15afbdeaba1b955ef Mon Sep 17 00:00:00 2001 From: Hamza Khalid Date: Fri, 29 Nov 2024 12:02:24 +0500 Subject: [PATCH] fix formating --- packages/ciphernode/config/src/app_config.rs | 18 +++++----- .../ciphernode/enclave_node/src/aggregator.rs | 6 ++-- .../ciphernode/enclave_node/src/ciphernode.rs | 2 +- .../evm/src/ciphernode_registry_sol.rs | 3 +- packages/ciphernode/evm/src/enclave_sol.rs | 2 +- .../ciphernode/evm/src/enclave_sol_writer.rs | 2 +- packages/ciphernode/evm/src/helpers.rs | 34 ++++++++----------- .../ciphernode/evm/src/registry_filter_sol.rs | 2 +- 8 files changed, 31 insertions(+), 38 deletions(-) diff --git a/packages/ciphernode/config/src/app_config.rs b/packages/ciphernode/config/src/app_config.rs index de225b04..d7790879 100644 --- a/packages/ciphernode/config/src/app_config.rs +++ b/packages/ciphernode/config/src/app_config.rs @@ -49,11 +49,8 @@ pub struct ContractAddresses { #[serde(tag = "type", content = "credentials")] pub enum RpcAuth { None, - Basic { - username: String, - password: String, - }, - Bearer(String) + Basic { username: String, password: String }, + Bearer(String), } impl Default for RpcAuth { @@ -377,10 +374,13 @@ chains: chain.contracts.ciphernode_registry.address(), "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" ); - assert_eq!(chain.rpc_auth, RpcAuth::Basic { - username: "testUser".to_string(), - password: "testPassword".to_string(), - }); + assert_eq!( + chain.rpc_auth, + RpcAuth::Basic { + username: "testUser".to_string(), + password: "testPassword".to_string(), + } + ); assert_eq!(chain.contracts.enclave.deploy_block(), None); assert_eq!( chain.contracts.ciphernode_registry.deploy_block(), diff --git a/packages/ciphernode/enclave_node/src/aggregator.rs b/packages/ciphernode/enclave_node/src/aggregator.rs index a90ce4f5..04bcb9d8 100644 --- a/packages/ciphernode/enclave_node/src/aggregator.rs +++ b/packages/ciphernode/enclave_node/src/aggregator.rs @@ -4,9 +4,7 @@ use cipher::Cipher; use config::AppConfig; use enclave_core::EventBus; use evm::{ - helpers::{ - get_signer_from_repository, RPC, ProviderConfig - }, + helpers::{get_signer_from_repository, ProviderConfig, RPC}, CiphernodeRegistrySol, EnclaveSol, RegistryFilterSol, }; use logger::SimpleLogger; @@ -46,7 +44,7 @@ pub async fn setup_aggregator( { let rpc_url = RPC::from_url(&chain.rpc_url).map_err(|e| { anyhow::anyhow!("Failed to parse RPC URL for chain {}: {}", chain.name, e) - })?; + })?; let provider_config = ProviderConfig::new(rpc_url, chain.rpc_auth.clone().into()); let read_provider = provider_config.create_readonly_provider().await?; let write_provider = provider_config.create_ws_signer_provider(&signer).await?; diff --git a/packages/ciphernode/enclave_node/src/ciphernode.rs b/packages/ciphernode/enclave_node/src/ciphernode.rs index 3edece4c..ecb20e09 100644 --- a/packages/ciphernode/enclave_node/src/ciphernode.rs +++ b/packages/ciphernode/enclave_node/src/ciphernode.rs @@ -5,7 +5,7 @@ use cipher::Cipher; use config::AppConfig; use enclave_core::{get_tag, EventBus}; use evm::{ - helpers::{RPC, ProviderConfig}, + helpers::{ProviderConfig, RPC}, CiphernodeRegistrySol, EnclaveSolReader, }; use logger::SimpleLogger; diff --git a/packages/ciphernode/evm/src/ciphernode_registry_sol.rs b/packages/ciphernode/evm/src/ciphernode_registry_sol.rs index 5367487e..a616411b 100644 --- a/packages/ciphernode/evm/src/ciphernode_registry_sol.rs +++ b/packages/ciphernode/evm/src/ciphernode_registry_sol.rs @@ -7,7 +7,8 @@ use actix::{Actor, Addr}; use alloy::{ primitives::{LogData, B256}, sol, - sol_types::SolEvent, transports::BoxTransport, + sol_types::SolEvent, + transports::BoxTransport, }; use anyhow::Result; use data::Repository; diff --git a/packages/ciphernode/evm/src/enclave_sol.rs b/packages/ciphernode/evm/src/enclave_sol.rs index a766bcde..bcdcab98 100644 --- a/packages/ciphernode/evm/src/enclave_sol.rs +++ b/packages/ciphernode/evm/src/enclave_sol.rs @@ -2,7 +2,7 @@ use crate::{ enclave_sol_reader::EnclaveSolReader, enclave_sol_writer::EnclaveSolWriter, event_reader::EvmEventReaderState, - helpers::{ReadonlyProvider, SignerProvider, WithChainId, RpcWSClient}, + helpers::{ReadonlyProvider, RpcWSClient, SignerProvider, WithChainId}, }; use actix::Addr; use alloy::transports::BoxTransport; diff --git a/packages/ciphernode/evm/src/enclave_sol_writer.rs b/packages/ciphernode/evm/src/enclave_sol_writer.rs index 9e595198..36b519b0 100644 --- a/packages/ciphernode/evm/src/enclave_sol_writer.rs +++ b/packages/ciphernode/evm/src/enclave_sol_writer.rs @@ -1,4 +1,4 @@ -use crate::helpers::{SignerProvider, WithChainId, RpcWSClient}; +use crate::helpers::{RpcWSClient, SignerProvider, WithChainId}; use actix::prelude::*; use actix::Addr; use alloy::{primitives::Address, sol}; diff --git a/packages/ciphernode/evm/src/helpers.rs b/packages/ciphernode/evm/src/helpers.rs index 3f104b4e..851eefe5 100644 --- a/packages/ciphernode/evm/src/helpers.rs +++ b/packages/ciphernode/evm/src/helpers.rs @@ -25,11 +25,11 @@ use alloy::{ use anyhow::{bail, Context, Result}; use base64::{engine::general_purpose::STANDARD, Engine}; use cipher::Cipher; +use config::RpcAuth as ConfigRpcAuth; use data::Repository; use std::{env, marker::PhantomData, sync::Arc}; use url::Url; use zeroize::Zeroizing; -use config::RpcAuth as ConfigRpcAuth; #[derive(Clone)] pub enum RPC { @@ -89,11 +89,8 @@ impl RPC { #[derive(Clone)] pub enum RpcAuth { None, - Basic { - username: String, - password: String, - }, - Bearer(String) + Basic { username: String, password: String }, + Bearer(String), } impl RpcAuth { @@ -114,15 +111,12 @@ impl RpcAuth { fn to_ws_auth(&self) -> Option { match self { RpcAuth::None => None, - RpcAuth::Basic { username, password } => { - Some(Authorization::basic(username, password)) - } + RpcAuth::Basic { username, password } => Some(Authorization::basic(username, password)), RpcAuth::Bearer(token) => Some(Authorization::bearer(token)), } } } - impl From for RpcAuth { fn from(value: ConfigRpcAuth) -> Self { match value { @@ -143,7 +137,6 @@ impl From for ConfigRpcAuth { } } - /// We need to cache the chainId so we can easily use it in a non-async situation /// This wrapper just stores the chain_id with the Provider #[derive(Clone)] @@ -199,7 +192,6 @@ pub type SignerProvider = FillProvider< pub type ReadonlyProvider = RootProvider; - #[derive(Clone)] pub struct ProviderConfig { rpc: RPC, @@ -223,9 +215,10 @@ impl ProviderConfig { .on_client(self.create_http_client()?) .boxed()) } - - pub async fn create_readonly_provider(&self) -> Result> { + pub async fn create_readonly_provider( + &self, + ) -> Result> { let provider = if self.rpc.is_websocket() { self.create_ws_provider().await? } else { @@ -243,8 +236,9 @@ impl ProviderConfig { .with_recommended_fillers() .wallet(wallet) .on_ws(self.create_ws_connect()) - .await.context("Failed to create WS signer provider")?; - + .await + .context("Failed to create WS signer provider")?; + WithChainId::new(provider).await } @@ -273,9 +267,7 @@ impl ProviderConfig { if let Some(auth_header) = self.auth.to_header_value() { headers.insert(AUTHORIZATION, auth_header); } - let client = Client::builder() - .default_headers(headers) - .build()?; + let client = Client::builder().default_headers(headers).build()?; let http = Http::with_client(client, self.rpc.as_http_url().parse()?); Ok(RpcClient::new(http, false)) } @@ -343,7 +335,9 @@ mod test { assert!(RPC::from_url("wss://example.com/").unwrap().is_secure()); assert!(!RPC::from_url("http://example.com/").unwrap().is_websocket()); - assert!(!RPC::from_url("https://example.com/").unwrap().is_websocket()); + assert!(!RPC::from_url("https://example.com/") + .unwrap() + .is_websocket()); assert!(RPC::from_url("ws://example.com/").unwrap().is_websocket()); assert!(RPC::from_url("wss://example.com/").unwrap().is_websocket()); } diff --git a/packages/ciphernode/evm/src/registry_filter_sol.rs b/packages/ciphernode/evm/src/registry_filter_sol.rs index 7360e05e..b4b8f770 100644 --- a/packages/ciphernode/evm/src/registry_filter_sol.rs +++ b/packages/ciphernode/evm/src/registry_filter_sol.rs @@ -1,4 +1,4 @@ -use crate::helpers::{SignerProvider, WithChainId, RpcWSClient}; +use crate::helpers::{RpcWSClient, SignerProvider, WithChainId}; use actix::prelude::*; use alloy::{ primitives::{Address, Bytes, U256},