This commit is contained in:
Derrick Hammer 2023-03-24 12:51:57 -04:00
parent 2e116d3e2f
commit 086884b617
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
6 changed files with 32 additions and 6 deletions

13
Cargo.lock generated
View File

@ -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"

View File

@ -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"] }

View File

@ -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"] }

View File

@ -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(&params).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(&params).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();

View File

@ -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"

View File

@ -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<String>) -> Self {
console_error_panic_hook::set_once();
tracing_wasm::set_as_global_default();
let base = networks::mainnet();