*WIP
This commit is contained in:
parent
15fd1b8f88
commit
7adc38ae1a
File diff suppressed because it is too large
Load Diff
|
@ -29,12 +29,12 @@ common = { path = "./common" }
|
|||
consensus = { path = "./consensus" }
|
||||
execution = { path = "./execution" }
|
||||
serde = { version = "1.0.154", features = ["derive"] }
|
||||
ethers = "1.0.2"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
eyre = "0.6.8"
|
||||
dirs = "4.0.0"
|
||||
ethers = { version = "1.0.2", features = [ "abigen" ] }
|
||||
env_logger = "0.9.0"
|
||||
log = "0.4.17"
|
||||
tracing-test = "0.2.4"
|
||||
|
@ -93,3 +93,6 @@ harness = false
|
|||
[[bench]]
|
||||
name = "sync"
|
||||
harness = false
|
||||
|
||||
[replace]
|
||||
"ethers:1.0.2" = { git = "https://git.lumeweb.com/LumeWeb/ethers-rs.git", branch= "lume" }
|
||||
|
|
|
@ -8,7 +8,7 @@ eyre = "0.6.8"
|
|||
serde = { version = "1.0.143", features = ["derive"] }
|
||||
hex = "0.4.3"
|
||||
ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "d09f55b4f8554491e3431e01af1c32347a8781cd" }
|
||||
ethers = "1.0.0"
|
||||
ethers = { version = "1.0.2", path = "../../helios-workspace/ethers-rs"}
|
||||
futures = "0.3.23"
|
||||
log = "0.4.17"
|
||||
thiserror = "1.0.37"
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
use ethers::providers::HttpClientError;
|
||||
use ethers::providers::JsonRpcError;
|
||||
use ethers::providers::Provider;
|
||||
use ethers::types::H256;
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ eyre = "0.6.8"
|
|||
serde = { version = "1.0.143", features = ["derive"] }
|
||||
hex = "0.4.3"
|
||||
ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "d09f55b4f8554491e3431e01af1c32347a8781cd" }
|
||||
ethers = "1.0.0"
|
||||
ethers = { version = "1.0.2", path = "../../helios-workspace/ethers-rs"}
|
||||
figment = { version = "0.10.7", features = ["toml", "env"] }
|
||||
thiserror = "1.0.37"
|
||||
log = "0.4.17"
|
||||
|
|
|
@ -11,7 +11,7 @@ serde_json = "1.0.85"
|
|||
hex = "0.4.3"
|
||||
ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "d09f55b4f8554491e3431e01af1c32347a8781cd" }
|
||||
milagro_bls = { git = "https://github.com/Snowfork/milagro_bls" }
|
||||
ethers = "1.0.0"
|
||||
ethers = { version = "1.0.2", path = "../../helios-workspace/ethers-rs"}
|
||||
bytes = "1.2.1"
|
||||
toml = "0.5.9"
|
||||
async-trait = "0.1.57"
|
||||
|
|
|
@ -11,7 +11,7 @@ serde_json = "1.0.85"
|
|||
hex = "0.4.3"
|
||||
ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "d09f55b4f8554491e3431e01af1c32347a8781cd" }
|
||||
revm = { version = "2.3", default-features = false, features = ["std", "k256", "with-serde"] }
|
||||
ethers = "1.0.0"
|
||||
ethers = { version = "1.0.2", path = "../../helios-workspace/ethers-rs"}
|
||||
bytes = "1.2.1"
|
||||
futures = "0.3.23"
|
||||
toml = "0.5.9"
|
||||
|
|
|
@ -3,7 +3,9 @@ use std::fmt::{Debug, Display, Formatter};
|
|||
|
||||
use async_trait::async_trait;
|
||||
use ethers::prelude::Address;
|
||||
use ethers::providers::{JsonRpcClient, Middleware, Provider, ProviderError};
|
||||
use ethers::providers::{
|
||||
HttpClientError, JsonRpcClient, Middleware, Provider, ProviderError, Response,
|
||||
};
|
||||
use ethers::types::transaction::eip2718::TypedTransaction;
|
||||
use ethers::types::transaction::eip2930::AccessList;
|
||||
use ethers::types::{
|
||||
|
@ -41,47 +43,6 @@ impl Clone for HttpRpc {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct LumeError {
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl Display for LumeError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Error: {}", self.message)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for LumeError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Debug: {}", self.message)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for LumeError {}
|
||||
|
||||
impl From<LumeError> for ProviderError {
|
||||
fn from(err: LumeError) -> Self {
|
||||
ProviderError::CustomError(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsValue> for LumeError {
|
||||
fn from(error: JsValue) -> Self {
|
||||
LumeError {
|
||||
message: error
|
||||
.as_string()
|
||||
.unwrap_or_else(|| "Unknown error".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<RpcError<String>> for LumeError {
|
||||
fn from(error: RpcError<String>) -> Self {
|
||||
LumeError {
|
||||
message: error.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LumeProvider {}
|
||||
|
||||
|
@ -90,10 +51,9 @@ impl LumeProvider {
|
|||
LumeProvider {}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
|
||||
impl JsonRpcClient for LumeProvider {
|
||||
type Error = LumeError;
|
||||
type Error = HttpClientError;
|
||||
|
||||
async fn request<T, R>(&self, method: &str, params: T) -> Result<R, Self::Error>
|
||||
where
|
||||
|
@ -113,40 +73,35 @@ impl JsonRpcClient for LumeProvider {
|
|||
|
||||
let js_future = JsFuture::from(execution_rpc_handler(JsValue::from(request)));
|
||||
let result = js_future.await?;
|
||||
let json = result.as_string().ok_or_else(|| {
|
||||
let err_msg = "response is not a string".to_string();
|
||||
panic!("{}", err_msg);
|
||||
// web_sys::console::log_1(&JsValue::from_str(&err_msg));
|
||||
RpcError::new(method, err_msg)
|
||||
})?;
|
||||
let json = result.as_string().expect("response is not a string");
|
||||
|
||||
web_sys::console::log_1(&JsValue::from_str(&json));
|
||||
let body = json.as_bytes();
|
||||
|
||||
let json_value: serde_json::Value = serde_json::from_str(&json).map_err(|e| {
|
||||
let err_msg = e.to_string();
|
||||
panic!("{}", err_msg);
|
||||
// web_sys::console::log_1(&JsValue::from_str(&err_msg));
|
||||
RpcError::new(method, err_msg)
|
||||
})?;
|
||||
|
||||
if let serde_json::Value::Object(obj) = json_value {
|
||||
web_sys::console::log_1(&JsValue::from_str("serde_json::Value matches"));
|
||||
if obj.contains_key("error") {
|
||||
let error_message = obj.get("error").unwrap().clone();
|
||||
let err_msg = serde_json::to_string(&error_message).unwrap();
|
||||
panic!("{}", err_msg);
|
||||
// web_sys::console::log_1(&JsValue::from_str(&err_msg));
|
||||
let raw = match serde_json::from_slice(&body) {
|
||||
Ok(Response::Success { result, .. }) => result.to_owned(),
|
||||
Ok(Response::Error { error, .. }) => return Err(error.into()),
|
||||
Ok(_) => {
|
||||
panic!(
|
||||
"{} {}",
|
||||
"unexpected notification over HTTP transport",
|
||||
String::from_utf8_lossy(&body).to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
panic!(
|
||||
"{} {}",
|
||||
err.to_string(),
|
||||
String::from_utf8_lossy(&body).to_string()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
let response: R = serde_json::from_str(&json).map_err(|e| {
|
||||
let err_msg = e.to_string();
|
||||
panic!("{}", err_msg);
|
||||
// web_sys::console::log_1(&JsValue::from_str(&err_msg));
|
||||
RpcError::new(method, err_msg)
|
||||
let res = serde_json::from_str(raw.get()).map_err(|err| HttpClientError::SerdeJson {
|
||||
err,
|
||||
text: raw.to_string(),
|
||||
})?;
|
||||
|
||||
Ok(response)
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ console_error_panic_hook = "0.1.7"
|
|||
futures = "0.3"
|
||||
serde = { version = "1.0.85", features = ["derive"] }
|
||||
|
||||
ethers = "1.0.0"
|
||||
ethers = { version = "1.0.2", features = [ "abigen" ], path = "../../helios-workspace/ethers-rs" }
|
||||
hex = "0.4.3"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue