From 18742dcd1ced547f13154f203ca75aca22b2bbd0 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 24 Mar 2023 10:59:16 -0400 Subject: [PATCH] *WIP --- config/src/base.rs | 2 -- config/src/config.rs | 4 ---- config/src/networks.rs | 2 -- consensus/src/rpc/mod.rs | 1 - consensus/src/rpc/nimbus_rpc.rs | 21 ++++++--------------- execution/src/rpc/http_rpc.rs | 22 +++++++--------------- helios-ts/src/lib.rs | 1 - 7 files changed, 13 insertions(+), 40 deletions(-) diff --git a/config/src/base.rs b/config/src/base.rs index 196ba8b..a82fb01 100644 --- a/config/src/base.rs +++ b/config/src/base.rs @@ -1,6 +1,4 @@ use serde::Serialize; -use std::sync::Arc; -use wasm_bindgen::JsValue; use crate::types::{ChainConfig, Forks}; use crate::utils::bytes_serialize; diff --git a/config/src/config.rs b/config/src/config.rs index 0b8cc3f..d40947c 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -2,9 +2,7 @@ use figment::{ providers::{Format, Serialized, Toml}, Figment, }; -use serde::de::Error; use serde::{Deserialize, Deserializer}; -use std::sync::Arc; use std::{path::PathBuf, process::exit}; use wasm_bindgen::JsValue; @@ -44,8 +42,6 @@ impl<'de> Deserialize<'de> for JsonString { } } -struct JsValueWrapper(JsValue); - impl Config { pub fn from_file(config_path: &PathBuf, network: &str, cli_config: &CliConfig) -> Self { let base_config = match network { diff --git a/config/src/networks.rs b/config/src/networks.rs index 12f67c1..b901be6 100644 --- a/config/src/networks.rs +++ b/config/src/networks.rs @@ -1,8 +1,6 @@ use common::utils::hex_str_to_bytes; use serde::{Deserialize, Serialize}; -use std::sync::Arc; use strum::{Display, EnumIter}; -use wasm_bindgen::JsValue; use crate::base::BaseConfig; use crate::types::{ChainConfig, Fork, Forks}; diff --git a/consensus/src/rpc/mod.rs b/consensus/src/rpc/mod.rs index 5543345..e71182f 100644 --- a/consensus/src/rpc/mod.rs +++ b/consensus/src/rpc/mod.rs @@ -2,7 +2,6 @@ pub mod nimbus_rpc; use async_trait::async_trait; use eyre::Result; -use std::sync::Arc; use crate::types::{BeaconBlock, Bootstrap, FinalityUpdate, OptimisticUpdate, Update}; diff --git a/consensus/src/rpc/nimbus_rpc.rs b/consensus/src/rpc/nimbus_rpc.rs index 8c9fede..6db281c 100644 --- a/consensus/src/rpc/nimbus_rpc.rs +++ b/consensus/src/rpc/nimbus_rpc.rs @@ -1,24 +1,17 @@ use std::cmp; -use std::collections::HashMap; use std::fmt::{Display, Formatter, Result as FmtResult}; -use std::sync::Arc; use async_trait::async_trait; -use eyre::{Result, WrapErr}; -use js_sys::{Function, Map, Promise}; -use serde::de::DeserializeOwned; +use eyre::Result; +use js_sys::Promise; use serde::Deserialize; -use serde_json::from_str as from_json_str; -use serde_wasm_bindgen::to_value; -use wasm_bindgen::closure::Closure; -use wasm_bindgen::{JsCast, JsValue}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen_futures::JsFuture; use crate::constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES; use crate::types::*; -use web_sys; use super::ConsensusRpc; @@ -179,11 +172,9 @@ impl NimbusRpc { js_params.set(&JsValue::from_str("method"), &JsValue::from_str("GET")); js_params.set(&JsValue::from_str("path"), &JsValue::from_str(&path)); - let result = unsafe { - let js_future = JsFuture::from(consensus_rpc_handler(JsValue::from(js_params))); - let result = js_future.await?; - result - }; + let js_future = JsFuture::from(consensus_rpc_handler(JsValue::from(js_params))); + let result = js_future.await?; + let json = result.as_string().unwrap(); let response: T = serde_json::from_str(&json).map_err(|e| RpcError::new(e.to_string()))?; diff --git a/execution/src/rpc/http_rpc.rs b/execution/src/rpc/http_rpc.rs index d465cb0..7b1aa07 100644 --- a/execution/src/rpc/http_rpc.rs +++ b/execution/src/rpc/http_rpc.rs @@ -1,13 +1,9 @@ use std::error::Error; use std::fmt::{Debug, Display, Formatter}; -use std::str::FromStr; -use std::sync::Arc; use async_trait::async_trait; -use ethers::prelude::{Address, Http}; -use ethers::providers::{ - HttpRateLimitRetryPolicy, JsonRpcClient, Middleware, Provider, ProviderError, RetryClient, -}; +use ethers::prelude::Address; +use ethers::providers::{JsonRpcClient, Middleware, Provider, ProviderError}; use ethers::types::transaction::eip2718::TypedTransaction; use ethers::types::transaction::eip2930::AccessList; use ethers::types::{ @@ -18,15 +14,14 @@ use eyre::Result; use serde::de::DeserializeOwned; use serde::Serialize; use serde_json::to_value; -use wasm_bindgen::closure::Closure; -use wasm_bindgen::{JsCast, JsValue}; +use wasm_bindgen::JsValue; use crate::types::CallOpts; use common::errors::RpcError; use super::ExecutionRpc; -use js_sys::{Function, Promise}; +use js_sys::Promise; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen_futures::JsFuture; @@ -109,11 +104,8 @@ impl JsonRpcClient for LumeProvider { let json_str = serde_json::to_string(&js_params).unwrap(); let js_value = JsValue::from_str(&json_str); - let result = unsafe { - let js_future = JsFuture::from(consensus_rpc_handler(js_value)); - let result = js_future.await?; - result - }; + let js_future = JsFuture::from(consensus_rpc_handler(js_value)); + let result = js_future.await?; let json = result.as_string().unwrap(); let response: R = @@ -126,7 +118,7 @@ impl JsonRpcClient for LumeProvider { #[async_trait(?Send)] impl ExecutionRpc for HttpRpc { fn new() -> Result { - let mut client = LumeProvider::new(); + let client = LumeProvider::new(); let provider = Provider::new(client); Ok(HttpRpc { provider }) diff --git a/helios-ts/src/lib.rs b/helios-ts/src/lib.rs index f0218ae..bd46c77 100644 --- a/helios-ts/src/lib.rs +++ b/helios-ts/src/lib.rs @@ -2,7 +2,6 @@ extern crate console_error_panic_hook; extern crate web_sys; use std::str::FromStr; -use std::sync::Arc; use common::types::BlockTag; use ethers::types::{Address, Filter, H256};