diff --git a/Cargo.lock b/Cargo.lock index 4bee2a0..529dfae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,15 +71,15 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anyhow" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" +checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] name = "arrayref" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] name = "arrayvec" @@ -104,13 +104,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.66" +version = "0.1.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc" +checksum = "86ea188f25f0255d8f92797797c97ebf5631fa88178beb1a46fdf5622c9a00e4" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.4", ] [[package]] @@ -153,7 +153,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -165,7 +165,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -328,9 +328,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ffdb39cb703212f3c11973452c2861b972f757b021158f3516ba10f2fa8b2c1" +checksum = "c3d4260bcc2e8fc9df1eac4919a720effeb63a3f0952f5bf4944adfa18897f09" dependencies = [ "memchr", "serde", @@ -407,7 +407,7 @@ checksum = "08a1ec454bc3eead8719cb56e15dbbfecdbc14e4b3a3ae4936cc6e31f5fc0d07" dependencies = [ "camino", "cargo-platform", - "semver 1.0.16", + "semver 1.0.17", "serde", "serde_json", "thiserror", @@ -433,9 +433,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.23" +version = "0.4.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" dependencies = [ "iana-time-zone", "js-sys", @@ -510,7 +510,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -537,6 +537,7 @@ dependencies = [ "futures", "log", "tokio", + "wasm-bindgen", ] [[package]] @@ -558,6 +559,7 @@ dependencies = [ "ssz-rs", "thiserror", "tokio", + "wasm-bindgen", "wasm-bindgen-futures", ] @@ -665,14 +667,17 @@ dependencies = [ "figment", "futures", "hex", + "js-sys", "log", "reqwest", "serde", + "serde_json", "serde_yaml", "ssz-rs", "strum", "thiserror", "tokio", + "wasm-bindgen", ] [[package]] @@ -688,17 +693,21 @@ dependencies = [ "eyre", "futures", "hex", + "js-sys", "log", "milagro_bls", "openssl", "reqwest", "serde", + "serde-wasm-bindgen 0.5.0", "serde_json", "ssz-rs", "superstruct", "thiserror", "tokio", "toml", + "wasm-bindgen", + "wasm-bindgen-futures", "wasm-timer", ] @@ -934,9 +943,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a140f260e6f3f79013b8bfc65e7ce630c9ab4388c6a89c71e07226f49487b72" +checksum = "a9c00419335c41018365ddf7e4d5f1c12ee3659ddcf3e01974650ba1de73d038" dependencies = [ "cc", "cxxbridge-flags", @@ -946,9 +955,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da6383f459341ea689374bf0a42979739dc421874f112ff26f829b8040b8e613" +checksum = "fb8307ad413a98fff033c8545ecf133e3257747b3bae935e7602aab8aa92d4ca" dependencies = [ "cc", "codespan-reporting", @@ -956,24 +965,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 2.0.4", ] [[package]] name = "cxxbridge-flags" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90201c1a650e95ccff1c8c0bb5a343213bdd317c6e600a93075bca2eff54ec97" +checksum = "edc52e2eb08915cb12596d29d55f0b5384f00d697a646dbd269b6ecb0fbd9d31" [[package]] name = "cxxbridge-macro" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" +checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.4", ] [[package]] @@ -997,7 +1006,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 1.0.109", ] [[package]] @@ -1008,7 +1017,7 @@ checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ "darling_core", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1029,7 +1038,7 @@ checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1372,7 +1381,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "syn", + "syn 1.0.109", "toml", "url", "walkdir", @@ -1390,7 +1399,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn", + "syn 1.0.109", ] [[package]] @@ -1418,7 +1427,7 @@ dependencies = [ "serde", "serde_json", "strum", - "syn", + "syn 1.0.109", "thiserror", "tiny-keccak 2.0.2", "unicode-xid", @@ -1433,7 +1442,7 @@ dependencies = [ "ethers-core", "getrandom 0.2.8", "reqwest", - "semver 1.0.16", + "semver 1.0.17", "serde", "serde-aux", "serde_json", @@ -1538,6 +1547,7 @@ dependencies = [ "eyre", "futures", "hex", + "js-sys", "log", "openssl", "reqwest", @@ -1549,6 +1559,8 @@ dependencies = [ "tokio", "toml", "triehash-ethereum", + "wasm-bindgen", + "wasm-bindgen-futures", ] [[package]] @@ -1724,9 +1736,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" +checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" dependencies = [ "futures-channel", "futures-core", @@ -1739,9 +1751,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" +checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" dependencies = [ "futures-core", "futures-sink", @@ -1749,15 +1761,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" +checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" [[package]] name = "futures-executor" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" +checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" dependencies = [ "futures-core", "futures-task", @@ -1766,9 +1778,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" +checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" [[package]] name = "futures-locks" @@ -1782,26 +1794,26 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" +checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "futures-sink" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" +checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" [[package]] name = "futures-task" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" +checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" [[package]] name = "futures-timer" @@ -1815,9 +1827,9 @@ dependencies = [ [[package]] name = "futures-util" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" dependencies = [ "futures-channel", "futures-core", @@ -2060,7 +2072,7 @@ dependencies = [ "execution", "hex", "serde", - "serde-wasm-bindgen", + "serde-wasm-bindgen 0.4.5", "serde_json", "wasm-bindgen", "wasm-bindgen-futures", @@ -2085,6 +2097,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.4.3" @@ -2145,9 +2163,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.24" +version = "0.14.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" +checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" dependencies = [ "bytes", "futures-channel", @@ -2198,16 +2216,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.53" +version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +checksum = "0c17cc76786e99f8d2f055c11159e7f0091c42474dcc3189fbab96072e873e6d" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "windows", ] [[package]] @@ -2322,7 +2340,7 @@ checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2370,10 +2388,11 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfa919a82ea574332e2de6e74b4c36e74d41982b335080fa59d4ef31be20fdf3" +checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" dependencies = [ + "hermit-abi 0.3.1", "libc", "windows-sys 0.45.0", ] @@ -2537,7 +2556,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2727,9 +2746,9 @@ dependencies = [ [[package]] name = "mime" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" @@ -2896,7 +2915,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2945,14 +2964,14 @@ dependencies = [ "bytes", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "openssl" -version = "0.10.45" +version = "0.10.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" +checksum = "d8b277f87dacc05a6b709965d1cbafac4649d6ce9f3ce9ceb88508b5666dfec9" dependencies = [ "bitflags", "cfg-if", @@ -2971,7 +2990,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2982,18 +3001,18 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "111.25.1+1.1.1t" +version = "111.25.2+1.1.1t" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ef9a9cc6ea7d9d5e7c4a913dc4b48d0e359eddf01af1dfec96ba7064b4aba10" +checksum = "320708a054ad9b3bf314688b5db87cf4d6683d64cfc835e2337924ae62bf4431" dependencies = [ "cc", ] [[package]] name = "openssl-sys" -version = "0.9.80" +version = "0.9.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" +checksum = "a95792af3c4e0153c3914df2261bedd30a98476f94dc892b67dfe1d89d433a04" dependencies = [ "autocfg", "cc", @@ -3005,9 +3024,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.4.1" +version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" [[package]] name = "overload" @@ -3050,7 +3069,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3163,7 +3182,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3209,7 +3228,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3359,7 +3378,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "version_check", ] @@ -3376,9 +3395,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" dependencies = [ "unicode-ident", ] @@ -3391,16 +3410,16 @@ checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "version_check", "yansi", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -3532,9 +3551,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c" dependencies = [ "aho-corasick", "memchr", @@ -3552,15 +3571,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "reqwest" -version = "0.11.14" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" +checksum = "0ba30cc2c0cd02af1222ed216ba659cdb2f879dfe3181852fe7c50b1d0005949" dependencies = [ "base64 0.21.0", "bytes", @@ -3697,7 +3716,7 @@ checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3727,14 +3746,14 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.16", + "semver 1.0.17", ] [[package]] name = "rustix" -version = "0.36.9" +version = "0.36.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" +checksum = "db4165c9963ab29e422d6c26fbc1d37f15bace6b2810221f9d925023480fcf0e" dependencies = [ "bitflags", "errno", @@ -3828,7 +3847,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3922,9 +3941,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" dependencies = [ "serde", ] @@ -3952,9 +3971,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.154" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cdd151213925e7f1ab45a9bbfb129316bd00799784b174b7cc7bcd16961c49e" +checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" dependencies = [ "serde_derive", ] @@ -3981,14 +4000,25 @@ dependencies = [ ] [[package]] -name = "serde_derive" -version = "1.0.154" +name = "serde-wasm-bindgen" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc80d722935453bcafdc2c9a73cd6fac4dc1938f0346035d84bf99fa9e33217" +checksum = "f3b143e2833c57ab9ad3ea280d21fd34e285a42837aeb0ee301f4f41890fa00e" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + +[[package]] +name = "serde_derive" +version = "1.0.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.4", ] [[package]] @@ -4192,7 +4222,7 @@ source = "git+https://github.com/ralexstokes/ssz-rs?rev=d09f55b4f8554491e3431e01 dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4226,7 +4256,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 1.0.109", ] [[package]] @@ -4259,7 +4289,7 @@ dependencies = [ "proc-macro2", "quote", "smallvec", - "syn", + "syn 1.0.109", ] [[package]] @@ -4273,6 +4303,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c622ae390c9302e214c31013517c2061ecb2699935882c60a9b37f82f8625ae" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tap" version = "1.0.1" @@ -4309,22 +4350,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.4", ] [[package]] @@ -4419,7 +4460,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4486,9 +4527,9 @@ checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" [[package]] name = "toml_edit" -version = "0.19.4" +version = "0.19.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1eb0622d28f4b9c90adc4ea4b2b46b47663fde9ac5fafcb14a1369d5508825" +checksum = "dc18466501acd8ac6a3f615dd29a3438f8ca6bb3b19537138b3106e575621274" dependencies = [ "indexmap", "toml_datetime", @@ -4521,7 +4562,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4593,7 +4634,7 @@ checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08" dependencies = [ "lazy_static", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4684,9 +4725,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.11" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524b68aca1d05e03fdf03fcdce2c6c94b6daf6d16861ddaa7e4f2b6638a9052c" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" @@ -4774,12 +4815,11 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "walkdir" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" dependencies = [ "same-file", - "winapi", "winapi-util", ] @@ -4832,7 +4872,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -4866,7 +4906,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4958,6 +4998,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -4984,9 +5033,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -4999,51 +5048,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "winnow" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee7b2c67f962bf5042bfd8b6a916178df33a26eec343ae064cb8e069f638fa6f" +checksum = "23d020b441f92996c80d94ae9166e8501e59c7bb56121189dc9eab3bd8216966" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 8088509..70e19d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,9 @@ exclude = [ "benches" ] +[build] +target = "wasm64-unknown-unknown" + [workspace] members = [ "cli", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4ce1262..ff0f23c 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -23,3 +23,4 @@ futures = "0.3.23" client = { path = "../client" } config = { path = "../config" } common = { path = "../common" } +wasm-bindgen = "0.2.84" diff --git a/client/Cargo.toml b/client/Cargo.toml index 4bcebfa..daaa53f 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -17,6 +17,7 @@ common = { path = "../common" } consensus = { path = "../consensus" } execution = { path = "../execution" } config = { path = "../config" } +wasm-bindgen = "0.2.84" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] jsonrpsee = { version = "0.15.1", features = ["full"] } diff --git a/client/src/client.rs b/client/src/client.rs index a2e7f6a..e7b1f37 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -37,8 +37,8 @@ use crate::rpc::Rpc; #[derive(Default)] pub struct ClientBuilder { network: Option, - consensus_rpc: Option, - execution_rpc: Option, + consensus_rpc: Option, + execution_rpc: Option, checkpoint: Option>, #[cfg(not(target_arch = "wasm32"))] rpc_port: Option, @@ -60,13 +60,13 @@ impl ClientBuilder { self } - pub fn consensus_rpc(mut self, consensus_rpc: &str) -> Self { - self.consensus_rpc = Some(consensus_rpc.to_string()); + pub fn consensus_rpc(mut self, consensus_rpc: wasm_bindgen::JsValue) -> Self { + self.consensus_rpc = Some(consensus_rpc); self } - pub fn execution_rpc(mut self, execution_rpc: &str) -> Self { - self.execution_rpc = Some(execution_rpc.to_string()); + pub fn execution_rpc(mut self, execution_rpc: wasm_bindgen::JsValue) -> Self { + self.execution_rpc = Some(execution_rpc); self } @@ -344,8 +344,11 @@ impl Client { // Try to sync again with the new checkpoint by reconstructing the consensus client // We fail fast here since the node is unrecoverable at this point let config = self.node.read().await.config.clone(); - let consensus = - ConsensusClient::new(&config.consensus_rpc, checkpoint.as_bytes(), config.clone())?; + let consensus = ConsensusClient::new( + config.consensus_rpc.clone(), + checkpoint.as_bytes(), + config.clone(), + )?; self.node.write().await.consensus = consensus; self.node.write().await.sync().await?; @@ -385,8 +388,11 @@ impl Client { // Try to sync again with the new checkpoint by reconstructing the consensus client // We fail fast here since the node is unrecoverable at this point let config = self.node.read().await.config.clone(); - let consensus = - ConsensusClient::new(&config.consensus_rpc, checkpoint.as_bytes(), config.clone())?; + let consensus = ConsensusClient::new( + config.consensus_rpc.clone(), + checkpoint.as_bytes(), + config.clone(), + )?; self.node.write().await.consensus = consensus; self.node.write().await.sync().await?; Ok(()) diff --git a/config/Cargo.toml b/config/Cargo.toml index c5a3bbb..0817810 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -19,6 +19,9 @@ strum = "0.24.1" futures = "0.3.25" common = { path = "../common" } +wasm-bindgen = "0.2.84" +serde_json = "1.0.94" +js-sys = "0.3.61" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["full"] } diff --git a/config/src/base.rs b/config/src/base.rs index 2ab2c32..a691841 100644 --- a/config/src/base.rs +++ b/config/src/base.rs @@ -1,4 +1,5 @@ use serde::Serialize; +use wasm_bindgen::JsValue; use crate::types::{ChainConfig, Forks}; use crate::utils::bytes_serialize; @@ -7,7 +8,8 @@ use crate::utils::bytes_serialize; #[derive(Serialize, Default)] pub struct BaseConfig { pub rpc_port: u16, - pub consensus_rpc: Option, + #[serde(skip_serializing, skip_deserializing)] + pub consensus_rpc: Option, #[serde( deserialize_with = "bytes_deserialize", serialize_with = "bytes_serialize" diff --git a/config/src/config.rs b/config/src/config.rs index 99e8faa..a703564 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -2,8 +2,10 @@ use figment::{ providers::{Format, Serialized, Toml}, Figment, }; -use serde::Deserialize; +use serde::de::Error; +use serde::{Deserialize, Deserializer}; use std::{path::PathBuf, process::exit}; +use wasm_bindgen::JsValue; use crate::base::BaseConfig; use crate::cli::CliConfig; @@ -13,8 +15,10 @@ use crate::utils::{bytes_deserialize, bytes_opt_deserialize}; #[derive(Deserialize, Debug, Default)] pub struct Config { - pub consensus_rpc: String, - pub execution_rpc: String, + #[serde(skip_serializing, skip_deserializing)] + pub consensus_rpc: wasm_bindgen::JsValue, + #[serde(skip_serializing, skip_deserializing)] + pub execution_rpc: wasm_bindgen::JsValue, pub rpc_port: Option, #[serde(deserialize_with = "bytes_deserialize")] pub default_checkpoint: Vec, @@ -30,6 +34,20 @@ pub struct Config { pub strict_checkpoint_age: bool, } +struct JsonString(String); + +impl<'de> Deserialize<'de> for JsonString { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let json_string = String::deserialize(deserializer)?; + Ok(JsonString(json_string)) + } +} + +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 9f2f7f8..953a0b1 100644 --- a/config/src/networks.rs +++ b/config/src/networks.rs @@ -1,6 +1,7 @@ use common::utils::hex_str_to_bytes; use serde::{Deserialize, Serialize}; use strum::{Display, EnumIter}; +use wasm_bindgen::JsValue; use crate::base::BaseConfig; use crate::types::{ChainConfig, Fork, Forks}; @@ -40,7 +41,7 @@ pub fn mainnet() -> BaseConfig { ) .unwrap(), rpc_port: 8545, - consensus_rpc: Some("https://www.lightclientdata.org".to_string()), + consensus_rpc: Some(JsValue::null()), chain: ChainConfig { chain_id: 1, genesis_time: 1606824023, diff --git a/consensus/Cargo.toml b/consensus/Cargo.toml index 57b12cf..5d6c365 100644 --- a/consensus/Cargo.toml +++ b/consensus/Cargo.toml @@ -23,6 +23,10 @@ superstruct = "0.7.0" common = { path = "../common" } config = { path = "../config" } +wasm-bindgen = "0.2.84" +js-sys = "0.3.61" +serde-wasm-bindgen = "0.5.0" +wasm-bindgen-futures = "0.4.34" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] openssl = { version = "0.10", features = ["vendored"] } @@ -30,4 +34,3 @@ tokio = { version = "1", features = ["full"] } [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-timer = "0.2.5" - diff --git a/consensus/src/consensus.rs b/consensus/src/consensus.rs index 7a8e45f..e5c0e27 100644 --- a/consensus/src/consensus.rs +++ b/consensus/src/consensus.rs @@ -55,11 +55,11 @@ struct LightClientStore { impl ConsensusClient { pub fn new( - rpc: &str, + rpc_handler: wasm_bindgen::JsValue, checkpoint_block_root: &[u8], config: Arc, ) -> Result> { - let rpc = R::new(rpc); + let rpc = R::new(rpc_handler); Ok(ConsensusClient { rpc, @@ -660,8 +660,8 @@ mod tests { async fn get_client(strict_checkpoint_age: bool) -> ConsensusClient { let base_config = networks::goerli(); let config = Config { - consensus_rpc: String::new(), - execution_rpc: String::new(), + consensus_rpc: wasm_bindgen::JsValue::null(), + execution_rpc: wasm_bindgen::JsValue::null(), chain: base_config.chain, forks: base_config.forks, strict_checkpoint_age, @@ -672,7 +672,9 @@ mod tests { hex::decode("1e591af1e90f2db918b2a132991c7c2ee9a4ab26da496bd6e71e4f0bd65ea870") .unwrap(); - let mut client = ConsensusClient::new("testdata/", &checkpoint, Arc::new(config)).unwrap(); + let mut client = + ConsensusClient::new(wasm_bindgen::JsValue::null(), &checkpoint, Arc::new(config)) + .unwrap(); client.bootstrap().await.unwrap(); client } diff --git a/consensus/src/rpc/mock_rpc.rs b/consensus/src/rpc/mock_rpc.rs deleted file mode 100644 index a887410..0000000 --- a/consensus/src/rpc/mock_rpc.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::{fs::read_to_string, path::PathBuf}; - -use super::ConsensusRpc; -use crate::types::{BeaconBlock, Bootstrap, FinalityUpdate, OptimisticUpdate, Update}; -use async_trait::async_trait; -use eyre::Result; -pub struct MockRpc { - testdata: PathBuf, -} - -#[cfg_attr(not(target_arch = "wasm32"), async_trait)] -#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] -impl ConsensusRpc for MockRpc { - fn new(path: &str) -> Self { - MockRpc { - testdata: PathBuf::from(path), - } - } - - async fn get_bootstrap(&self, _block_root: &'_ [u8]) -> Result { - let bootstrap = read_to_string(self.testdata.join("bootstrap.json"))?; - Ok(serde_json::from_str(&bootstrap)?) - } - - async fn get_updates(&self, _period: u64, _count: u8) -> Result> { - let updates = read_to_string(self.testdata.join("updates.json"))?; - Ok(serde_json::from_str(&updates)?) - } - - async fn get_finality_update(&self) -> Result { - let finality = read_to_string(self.testdata.join("finality.json"))?; - Ok(serde_json::from_str(&finality)?) - } - - async fn get_optimistic_update(&self) -> Result { - let optimistic = read_to_string(self.testdata.join("optimistic.json"))?; - Ok(serde_json::from_str(&optimistic)?) - } - - async fn get_block(&self, _slot: u64) -> Result { - let block = read_to_string(self.testdata.join("blocks.json"))?; - Ok(serde_json::from_str(&block)?) - } - - async fn chain_id(&self) -> Result { - eyre::bail!("not implemented") - } -} diff --git a/consensus/src/rpc/mod.rs b/consensus/src/rpc/mod.rs index 03f46dd..1061cec 100644 --- a/consensus/src/rpc/mod.rs +++ b/consensus/src/rpc/mod.rs @@ -1,4 +1,3 @@ -pub mod mock_rpc; pub mod nimbus_rpc; use async_trait::async_trait; @@ -10,7 +9,7 @@ use crate::types::{BeaconBlock, Bootstrap, FinalityUpdate, OptimisticUpdate, Upd #[cfg_attr(not(target_arch = "wasm32"), async_trait)] #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] pub trait ConsensusRpc { - fn new(path: &str) -> Self; + fn new(rpc_handler: wasm_bindgen::JsValue) -> Self; async fn get_bootstrap(&self, block_root: &'_ [u8]) -> Result; async fn get_updates(&self, period: u64, count: u8) -> Result>; async fn get_finality_update(&self) -> Result; diff --git a/consensus/src/rpc/nimbus_rpc.rs b/consensus/src/rpc/nimbus_rpc.rs index e0548fb..f06b646 100644 --- a/consensus/src/rpc/nimbus_rpc.rs +++ b/consensus/src/rpc/nimbus_rpc.rs @@ -1,110 +1,98 @@ -use async_trait::async_trait; -use eyre::Result; use std::cmp; +use std::fmt::{Display, Formatter, Result as FmtResult}; + +use async_trait::async_trait; +use eyre::{Result, WrapErr}; +use js_sys::then; +use serde::Deserialize; +use serde_wasm_bindgen::from_value as from_js_value; +use wasm_bindgen::{JsCast, JsValue}; + +use wasm_bindgen_futures::JsFuture; -use super::ConsensusRpc; use crate::constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES; use crate::types::*; -use common::errors::RpcError; + +use super::ConsensusRpc; + +#[derive(Debug)] +pub struct RpcError { + message: String, +} + +impl Display for RpcError { + fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { + write!(f, "{}", self.message) + } +} + +impl std::error::Error for RpcError {} #[derive(Debug)] pub struct NimbusRpc { - rpc: String, + rpc_handler: wasm_bindgen::JsValue, } #[cfg_attr(not(target_arch = "wasm32"), async_trait)] #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] impl ConsensusRpc for NimbusRpc { - fn new(rpc: &str) -> Self { - NimbusRpc { - rpc: rpc.to_string(), - } + fn new(rpc_handler: JsValue) -> Self { + NimbusRpc { rpc_handler } } async fn get_bootstrap(&self, block_root: &'_ [u8]) -> Result { let root_hex = hex::encode(block_root); - let req = format!( - "{}/eth/v1/beacon/light_client/bootstrap/0x{}", - self.rpc, root_hex - ); + let path = format!("/eth/v1/beacon/light_client/bootstrap/0x{}", root_hex); - let client = reqwest::Client::new(); - let res = client - .get(req) - .send() - .await - .map_err(|e| RpcError::new("bootstrap", e))? - .json::() - .await - .map_err(|e| RpcError::new("bootstrap", e))?; + let res = self.request::(path, "bootstrap").await?; - Ok(res.data) + Ok(res) } async fn get_updates(&self, period: u64, count: u8) -> Result> { let count = cmp::min(count, MAX_REQUEST_LIGHT_CLIENT_UPDATES); - let req = format!( - "{}/eth/v1/beacon/light_client/updates?start_period={}&count={}", - self.rpc, period, count + let path = format!( + "/eth/v1/beacon/light_client/updates?start_period={}&count={}", + period, count ); - let client = reqwest::Client::new(); - let res = client - .get(req) - .send() - .await - .map_err(|e| RpcError::new("updates", e))? - .json::() - .await - .map_err(|e| RpcError::new("updates", e))?; + let res = self.request::(path, "updates").await?; Ok(res.iter().map(|d| d.data.clone()).collect()) } async fn get_finality_update(&self) -> Result { - let req = format!("{}/eth/v1/beacon/light_client/finality_update", self.rpc); - let res = reqwest::get(req) - .await - .map_err(|e| RpcError::new("finality_update", e))? - .json::() - .await - .map_err(|e| RpcError::new("finality_update", e))?; + let path = format!("/eth/v1/beacon/light_client/finality_update"); + + let res = self + .request::(path, "finality_update") + .await?; Ok(res.data) } async fn get_optimistic_update(&self) -> Result { - let req = format!("{}/eth/v1/beacon/light_client/optimistic_update", self.rpc); - let res = reqwest::get(req) - .await - .map_err(|e| RpcError::new("optimistic_update", e))? - .json::() - .await - .map_err(|e| RpcError::new("optimistic_update", e))?; + let path = format!("/eth/v1/beacon/light_client/optimistic_update"); + + let res = self + .request::(path, "optimistic_update") + .await?; Ok(res.data) } async fn get_block(&self, slot: u64) -> Result { - let req = format!("{}/eth/v2/beacon/blocks/{}", self.rpc, slot); - let res = reqwest::get(req) - .await - .map_err(|e| RpcError::new("blocks", e))? - .json::() - .await - .map_err(|e| RpcError::new("blocks", e))?; + let path = format!("/eth/v2/beacon/blocks/{}", slot); + + let res = self.request::(path, "blocks").await?; Ok(res.data.message) } async fn chain_id(&self) -> Result { - let req = format!("{}/eth/v1/config/spec", self.rpc); - let res = reqwest::get(req) - .await - .map_err(|e| RpcError::new("spec", e))? - .json::() - .await - .map_err(|e| RpcError::new("spec", e))?; + let path = format!("/eth/v1/config/spec"); + + let res = self.request::(path, "blocks").await?; Ok(res.data.chain_id) } @@ -152,3 +140,28 @@ struct Spec { #[serde(rename = "DEPOSIT_NETWORK_ID", deserialize_with = "u64_deserialize")] chain_id: u64, } + +impl NimbusRpc { + async fn request(&self, path: String, error_type: &str) -> Result + where + for<'a> T: Deserialize<'a>, + { + let js_params = js_sys::Map::new(); + js_params.set(&JsValue::from_str("method"), &JsValue::from_str("GET")); + js_params.set(&JsValue::from_str("path"), &JsValue::from_str(&path)); + + let promise = self + .rpc_handler + .dyn_into::() + .unwrap() + .call1(&JsValue::null(), &js_params) + .expect("Failed to make JSON-RPC request"); + + let result = match promise.dyn_into::() { + Ok(promise) => JsFuture::from(promise).await.unwrap(), + Err(_) => panic!("Unable to convert JS value to Promise"), + }; + + Ok(result) + } +} diff --git a/execution/Cargo.toml b/execution/Cargo.toml index b2f72e1..269bd5f 100644 --- a/execution/Cargo.toml +++ b/execution/Cargo.toml @@ -22,6 +22,9 @@ thiserror = "1.0.37" common = { path = "../common" } consensus = { path = "../consensus" } +wasm-bindgen = "0.2.84" +js-sys = "0.3.61" +wasm-bindgen-futures = "0.4.34" [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 9c0f9b2..9f8ad42 100644 --- a/execution/src/rpc/http_rpc.rs +++ b/execution/src/rpc/http_rpc.rs @@ -1,8 +1,12 @@ +use std::error::Error; +use std::fmt::{Debug, Display, Formatter}; use std::str::FromStr; use async_trait::async_trait; use ethers::prelude::{Address, Http}; -use ethers::providers::{HttpRateLimitRetryPolicy, Middleware, Provider, RetryClient}; +use ethers::providers::{ + HttpRateLimitRetryPolicy, JsonRpcClient, Middleware, Provider, ProviderError, RetryClient, +}; use ethers::types::transaction::eip2718::TypedTransaction; use ethers::types::transaction::eip2930::AccessList; use ethers::types::{ @@ -10,36 +14,101 @@ use ethers::types::{ Filter, Log, Transaction, TransactionReceipt, H256, U256, }; 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 crate::types::CallOpts; use common::errors::RpcError; use super::ExecutionRpc; +use js_sys::{Function, Promise}; +use wasm_bindgen_futures::JsFuture; + pub struct HttpRpc { - url: String, - provider: Provider>, + provider: Provider, + rpc_handler: JsValue, } impl Clone for HttpRpc { fn clone(&self) -> Self { - Self::new(&self.url).unwrap() + Self::new(self.rpc_handler.clone()).unwrap() + } +} + +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 for ProviderError { + fn from(err: LumeError) -> Self { + ProviderError::CustomError(err.to_string()) + } +} + +#[derive(Clone, Debug)] +pub struct LumeProvider { + pub rpc_handler: JsValue, +} + +impl LumeProvider { + pub fn new(rpc_handler: JsValue) -> Self { + LumeProvider { rpc_handler } + } +} + +impl JsonRpcClient for LumeProvider { + type Error = LumeError; + + async fn request(&self, method: &str, params: T) -> Result + where + T: Debug + Serialize + Send + Sync, + R: DeserializeOwned, + { + let js_method = JsValue::from(method); + let js_params = to_value(¶ms).unwrap(); + + let promise = self + .rpc_handler + .dyn_into::() + .unwrap() + .call2(&js_method, &js_params) + .unwrap(); + let result = match promise.dyn_into::() { + Ok(promise) => JsFuture::from(promise).await.unwrap(), + Err(_) => panic!("Unable to convert JS value to Promise"), + }; } } #[cfg_attr(not(target_arch = "wasm32"), async_trait)] #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] impl ExecutionRpc for HttpRpc { - fn new(rpc: &str) -> Result { + fn new(rpc_handler: wasm_bindgen::JsValue) -> Result { let http = Http::from_str(rpc)?; - let mut client = RetryClient::new(http, Box::new(HttpRateLimitRetryPolicy), 100, 50); - client.set_compute_units(300); - + let mut client = LumeProvider::new(rpc_handler.clone()); let provider = Provider::new(client); Ok(HttpRpc { - url: rpc.to_string(), provider, + rpc_handler, }) } diff --git a/helios-ts/src/lib.rs b/helios-ts/src/lib.rs index b9cb5a5..df8f436 100644 --- a/helios-ts/src/lib.rs +++ b/helios-ts/src/lib.rs @@ -28,18 +28,14 @@ pub struct Client { impl Client { #[wasm_bindgen(constructor)] pub fn new( - execution_rpc: String, - consensus_rpc: Option, + execution_rpc: JsValue, + consensus_rpc: JsValue, network: String, checkpoint: Option, ) -> Self { console_error_panic_hook::set_once(); - let base = match network.as_str() { - "mainnet" => networks::mainnet(), - "goerli" => networks::goerli(), - _ => panic!("invalid network"), - }; + let base = networks::mainnet(); let chain_id = base.chain.chain_id; @@ -51,8 +47,6 @@ impl Client { .unwrap_or(base.default_checkpoint), ); - let consensus_rpc = consensus_rpc.unwrap_or(base.consensus_rpc.unwrap()); - let config = Config { execution_rpc, consensus_rpc,