diff --git a/Cargo.lock b/Cargo.lock index de2a5a5..0566a36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1562,6 +1562,7 @@ dependencies = [ "triehash-ethereum", "wasm-bindgen", "wasm-bindgen-futures", + "web-sys", ] [[package]] @@ -2075,6 +2076,7 @@ dependencies = [ "hex", "serde", "serde-wasm-bindgen 0.4.5", + "tracing-wasm", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -4638,6 +4640,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "tracing-wasm" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4575c663a174420fa2d78f4108ff68f65bf2fbb7dd89f33749b6e826b3626e07" +dependencies = [ + "tracing", + "tracing-subscriber", + "wasm-bindgen", +] + [[package]] name = "triehash" version = "0.8.4" diff --git a/consensus/Cargo.toml b/consensus/Cargo.toml index c80bde8..d25f3d8 100644 --- a/consensus/Cargo.toml +++ b/consensus/Cargo.toml @@ -27,7 +27,7 @@ wasm-bindgen = "0.2.84" js-sys = "0.3.61" serde-wasm-bindgen = "0.5.0" wasm-bindgen-futures = "0.4.34" -web-sys = {version ="0.3.61", features=["Window","WindowClient"]} +web-sys = { version = "0.3.61" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] openssl = { version = "0.10", features = ["vendored"] } diff --git a/execution/Cargo.toml b/execution/Cargo.toml index 269bd5f..5674f8c 100644 --- a/execution/Cargo.toml +++ b/execution/Cargo.toml @@ -25,6 +25,7 @@ consensus = { path = "../consensus" } wasm-bindgen = "0.2.84" js-sys = "0.3.61" wasm-bindgen-futures = "0.4.34" +web-sys = {version="0.3.61", features=["console"]} [target.'cfg(not(target_arch = "wasm32"))'.dependencies] openssl = { version = "0.10", features = ["vendored"] } diff --git a/execution/src/rpc/http_rpc.rs b/execution/src/rpc/http_rpc.rs index 7b1aa07..8f8e90c 100644 --- a/execution/src/rpc/http_rpc.rs +++ b/execution/src/rpc/http_rpc.rs @@ -28,7 +28,7 @@ use wasm_bindgen_futures::JsFuture; #[wasm_bindgen] extern "C" { #[wasm_bindgen(js_namespace = window)] - fn consensus_rpc_handler(data: JsValue) -> Promise; + fn execution_rpc_handler(data: JsValue) -> Promise; } pub struct HttpRpc { @@ -100,11 +100,20 @@ impl JsonRpcClient for LumeProvider { T: Debug + Serialize + Send + Sync, R: DeserializeOwned, { - let js_params = to_value(¶ms).unwrap(); - let json_str = serde_json::to_string(&js_params).unwrap(); - let js_value = JsValue::from_str(&json_str); + let request = js_sys::Map::new(); + request.set(&JsValue::from_str("method"), &JsValue::from_str(method)); - let js_future = JsFuture::from(consensus_rpc_handler(js_value)); + if let Some(params) = Option::from(params) { + let js_params = to_value(¶ms).unwrap(); + let json_str = serde_json::to_string(&js_params).unwrap(); + request.set(&JsValue::from_str("params"), &JsValue::from_str(&json_str)); + } else { + request.set(&JsValue::from_str("params"), &JsValue::null()); + } + + web_sys::console::log_1(&request); + + let js_future = JsFuture::from(execution_rpc_handler(JsValue::from(request))); let result = js_future.await?; let json = result.as_string().unwrap(); diff --git a/helios-ts/Cargo.toml b/helios-ts/Cargo.toml index c0f683d..e45a6eb 100644 --- a/helios-ts/Cargo.toml +++ b/helios-ts/Cargo.toml @@ -25,6 +25,7 @@ common = { path = "../common" } consensus = { path = "../consensus" } execution = { path = "../execution" } config = { path = "../config" } +tracing-wasm = "0.2.1" [dependencies.web-sys] version = "0.3.61" diff --git a/helios-ts/src/lib.rs b/helios-ts/src/lib.rs index 0e75e9d..ff5c6af 100644 --- a/helios-ts/src/lib.rs +++ b/helios-ts/src/lib.rs @@ -10,6 +10,7 @@ use wasm_bindgen::prelude::*; use client::database::ConfigDB; use config::{networks, Config}; +use tracing_wasm; #[allow(unused_macros)] macro_rules! log { @@ -29,6 +30,7 @@ impl Client { #[wasm_bindgen(constructor)] pub fn new(checkpoint: Option) -> Self { console_error_panic_hook::set_once(); + tracing_wasm::set_as_global_default(); let base = networks::mainnet();