diff --git a/Cargo.lock b/Cargo.lock
index 69f168eba2057..c5a097ff79255 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -358,6 +358,28 @@ dependencies = [
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "browser-utils"
+version = "2.0.0"
+dependencies = [
+ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "console_log 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
+ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "js-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvdb-web 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libp2p 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "sc-chain-spec 2.0.0",
+ "sc-network 0.8.0",
+ "sc-service 2.0.0",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen-futures 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "bs58"
version = "0.2.5"
@@ -389,7 +411,7 @@ dependencies = [
[[package]]
name = "bumpalo"
-version = "2.6.0"
+version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -558,7 +580,7 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -567,7 +589,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "web-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "web-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1621,7 +1643,7 @@ dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -2084,10 +2106,10 @@ dependencies = [
[[package]]
name = "js-sys"
-version = "0.3.32"
+version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -2260,6 +2282,21 @@ dependencies = [
"smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "kvdb-web"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "js-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvdb 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvdb-memorydb 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "send_wrapper 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
+ "web-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "language-tags"
version = "0.2.2"
@@ -2559,7 +2596,7 @@ dependencies = [
"ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "js-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libp2p-core 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2573,9 +2610,9 @@ dependencies = [
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)",
- "web-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "web-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -2624,11 +2661,11 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
- "js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "js-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
"libp2p-core 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -2979,19 +3016,14 @@ dependencies = [
name = "node-cli"
version = "2.0.0"
dependencies = [
- "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "console_log 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "browser-utils 2.0.0",
"ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"frame-support 2.0.0",
"frame-system 2.0.0",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonrpc-core 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "kvdb-memorydb 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "libp2p 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"node-executor 2.0.0",
"node-primitives 2.0.0",
@@ -3006,7 +3038,6 @@ dependencies = [
"pallet-timestamp 2.0.0",
"pallet-transaction-payment 2.0.0",
"parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"sc-authority-discovery 2.0.0",
"sc-basic-authority 2.0.0",
@@ -3043,8 +3074,8 @@ dependencies = [
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen-futures 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4633,7 +4664,7 @@ dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -4789,7 +4820,7 @@ dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "web-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "web-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -5888,6 +5919,11 @@ name = "send_wrapper"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "send_wrapper"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "serde"
version = "1.0.103"
@@ -7666,25 +7702,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wasm-bindgen"
-version = "0.2.55"
+version = "0.2.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen-macro 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen-macro 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-backend"
-version = "0.2.55"
+version = "0.2.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bumpalo 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen-shared 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen-shared 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -7694,40 +7730,51 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
- "js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
- "web-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "js-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
+ "web-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "wasm-bindgen-futures"
+version = "0.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "js-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
+ "web-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-macro"
-version = "0.2.55"
+version = "0.2.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen-macro-support 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen-macro-support 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-macro-support"
-version = "0.2.55"
+version = "0.2.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen-backend 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen-shared 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen-backend 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen-shared 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-shared"
-version = "0.2.55"
+version = "0.2.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wasm-bindgen-webidl"
-version = "0.2.55"
+version = "0.2.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -7736,7 +7783,7 @@ dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen-backend 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen-backend 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
"weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -7756,11 +7803,11 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
- "js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "js-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
"send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
- "web-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
+ "web-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -7880,14 +7927,14 @@ dependencies = [
[[package]]
name = "web-sys"
-version = "0.3.32"
+version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
- "js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "js-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
"sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
- "wasm-bindgen-webidl 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-bindgen-webidl 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -8171,7 +8218,7 @@ dependencies = [
"checksum bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b170cd256a3f9fa6b9edae3e44a7dfdfc77e8124dbc3e2612d75f9c3e2396dae"
"checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245"
"checksum build-helper 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdce191bf3fa4995ce948c8c83b4640a1745457a149e73c6db75b4ffe36aad5f"
-"checksum bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708"
+"checksum bumpalo 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fe2567a8d8a3aedb4e39aa39e186d5673acfd56393c6ac83b2bc5bd82f4369c"
"checksum byte-slice-cast 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f6209f3b2c1edea170002e016d5ead6903d3bb0a846477f53bbeb614967a52a9"
"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
@@ -8338,7 +8385,7 @@ dependencies = [
"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484"
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
"checksum jobserver 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b1d42ef453b30b7387e113da1c83ab1605d90c5b4e0eb8e96d016ed3b8c160"
-"checksum js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)" = "1c840fdb2167497b0bd0db43d6dfe61e91637fa72f9d061f8bd17ddc44ba6414"
+"checksum js-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)" = "c40e7a4fafb6cf0be06d25662fc99aacb25f526eb6e1bc0c24100bde5d6a834e"
"checksum jsonrpc-client-transports 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0a9ae166c4d1f702d297cd76d4b55758ace80272ffc6dbb139fdc1bf810de40b"
"checksum jsonrpc-core 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fe3b688648f1ef5d5072229e2d672ecb92cbff7d1c79bcf3fd5898f3f3df0970"
"checksum jsonrpc-core-client 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "080dc110be17701097df238fad3c816d4a478a1899dfbcf8ec8957dd40ec7304"
@@ -8354,6 +8401,7 @@ dependencies = [
"checksum kvdb 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cecee8d85a74f6b8284710d52a7d1196f09e31f8217e1f184a475b509d360554"
"checksum kvdb-memorydb 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0a5d70712b1fe0f02ce7ee36a962fcb0b15d0fe11262ba21a4aa839ef22cf60d"
"checksum kvdb-rocksdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "54cc6b52f7e511de9f07fd77cda70247adfc6b8192e4b5a1b6dbca416dc425b5"
+"checksum kvdb-web 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "90cff04dc606356c88e3fbbf8033040b072cb57d03d6fed8b6d6372587d5931c"
"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
@@ -8540,6 +8588,7 @@ dependencies = [
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0eddf2e8f50ced781f288c19f18621fa72a3779e3cb58dbf23b07469b0abeb4"
+"checksum send_wrapper 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "686ef91cf020ad8d4aca9a7047641fd6add626b7b89e14546c2b6a76781cf822"
"checksum serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "1217f97ab8e8904b57dd22eb61cde455fa7446a9c1cf43966066da047c1f3702"
"checksum serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "a8c6faef9a2e64b0064f48570289b4bf8823b7581f1d6157c1b52152306651d0"
"checksum serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)" = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7"
@@ -8656,13 +8705,14 @@ dependencies = [
"checksum want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230"
"checksum want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0"
"checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
-"checksum wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "29ae32af33bacd663a9a28241abecf01f2be64e6a185c6139b04f18b6385c5f2"
-"checksum wasm-bindgen-backend 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "1845584bd3593442dc0de6e6d9f84454a59a057722f36f005e44665d6ab19d85"
+"checksum wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)" = "701bc20794a7f9e8dcd85984a848f951ef6c5083322b6dd17fe880c99390f7cd"
+"checksum wasm-bindgen-backend 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)" = "426315280d373e1a828e1c322507d51aa82e03c2fb1d654720b9e2f2368d291d"
"checksum wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
-"checksum wasm-bindgen-macro 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "87fcc747e6b73c93d22c947a6334644d22cfec5abd8b66238484dc2b0aeb9fe4"
-"checksum wasm-bindgen-macro-support 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "3dc4b3f2c4078c8c4a5f363b92fcf62604c5913cbd16c6ff5aaf0f74ec03f570"
-"checksum wasm-bindgen-shared 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "ca0b78d6d3be8589b95d1d49cdc0794728ca734adf36d7c9f07e6459508bb53d"
-"checksum wasm-bindgen-webidl 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "3126356474ceb717c8fb5549ae387c9fbf4872818454f4d87708bee997214bb5"
+"checksum wasm-bindgen-futures 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1de54efe80cb87a8fa1f715d60ab47a5eac6b1447dd68665300773f498c229b1"
+"checksum wasm-bindgen-macro 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)" = "d9a8a46373db32c892de910ccca302ecdaf8262abab746324a8a4dac352fc11f"
+"checksum wasm-bindgen-macro-support 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)" = "45d1c6c2259c0f4ef3d61ea0976ea075b6f8185497c4a5457793740c2cda6430"
+"checksum wasm-bindgen-shared 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)" = "dd8e108ae395aae8017b091c4766101f08c635a5074e6631e0085e8a839e5810"
+"checksum wasm-bindgen-webidl 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)" = "7a38859ace1c29c8ed75cd74940d4c96b980837179355de542a2eab3b435bb5c"
"checksum wasm-gc-api 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c32691b6c7e6c14e7f8fd55361a9088b507aa49620fcd06c09b3a1082186b9"
"checksum wasm-timer 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "aa3e01d234bb71760e685cfafa5e2c96f8ad877c161a721646356651069e26ac"
"checksum wasmi 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bf617d864d25af3587aa745529f7aaa541066c876d57e050c0d0c85c61c92aff"
@@ -8672,7 +8722,7 @@ dependencies = [
"checksum wasmtime-environ 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a3947662a0b8e05b1418465e64f16de9114f9fec18cc3f56e0ed5aa7737b89d0"
"checksum wasmtime-jit 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6ed7922689461a7b5bd0d9c7350cac526c8a520a23b3ffd7f5b446ac51dfc51f"
"checksum wasmtime-runtime 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "781d6bb8b346efaa3dc39746386957cd79b8d841e8652ed9b02d77bcf64fb514"
-"checksum web-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)" = "98405c0a2e722ed3db341b4c5b70eb9fe0021621f7350bab76df93b09b649bbf"
+"checksum web-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ba09295448c0b93bc87d2769614d371a924749e5e6c87e4c1df8b2416b49b775"
"checksum webpki 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d7e664e770ac0110e2384769bcc59ed19e329d81f555916a6e072714957b81b4"
"checksum webpki-roots 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a262ae37dd9d60f60dd473d1158f9fbebf110ba7b6a5051c8160460f6043718b"
"checksum webpki-roots 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4"
diff --git a/Cargo.toml b/Cargo.toml
index 505cd299d9c71..7404744a41276 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -143,6 +143,7 @@ members = [
"test-utils/client",
"test-utils/runtime",
"test-utils/runtime/client",
+ "utils/browser",
"utils/build-script-utils",
"utils/fork-tree",
"utils/frame/rpc/support",
diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml
index c4cb3108dedd9..a2b2195404508 100644
--- a/bin/node/cli/Cargo.toml
+++ b/bin/node/cli/Cargo.toml
@@ -87,15 +87,9 @@ ctrlc = { version = "3.1.3", features = ["termination"], optional = true }
node-transaction-factory = { version = "2.0.0", optional = true, path = "../transaction-factory" }
# WASM-specific dependencies
-libp2p = { version = "0.13.2", default-features = false, optional = true }
-clear_on_drop = { version = "0.2.3", features = ["no_cc"], optional = true } # Imported just for the `no_cc` feature
-console_error_panic_hook = { version = "0.1.1", optional = true }
-console_log = { version = "0.1.2", optional = true }
-js-sys = { version = "0.3.22", optional = true }
-wasm-bindgen = { version = "0.2.45", optional = true }
-wasm-bindgen-futures = { version = "0.3.22", optional = true }
-kvdb-memorydb = { version = "0.2.0", optional = true }
-rand6 = { package = "rand", version = "0.6", features = ["wasm-bindgen"], optional = true } # Imported just for the `wasm-bindgen` feature
+wasm-bindgen = { version = "0.2.57", optional = true }
+wasm-bindgen-futures = { version = "0.4.7", optional = true }
+browser-utils = { path = "../../../utils/browser", optional = true }
[dev-dependencies]
sc-keystore = { version = "2.0.0", path = "../../../client/keystore" }
@@ -113,16 +107,9 @@ vergen = "3.0.4"
[features]
default = ["cli"]
browser = [
- "clear_on_drop",
- "console_error_panic_hook",
- "console_log",
- "js-sys",
- "libp2p",
+ "browser-utils",
"wasm-bindgen",
"wasm-bindgen-futures",
- "kvdb-memorydb",
- "rand/wasm-bindgen",
- "rand6"
]
cli = [
"sc-cli",
diff --git a/bin/node/cli/browser-demo/build.sh b/bin/node/cli/browser-demo/build.sh
index c16100794ad2e..059ed9fe423b0 100755
--- a/bin/node/cli/browser-demo/build.sh
+++ b/bin/node/cli/browser-demo/build.sh
@@ -1,3 +1,3 @@
#!/usr/bin/env sh
wasm-pack build --target web --out-dir ./browser-demo/pkg --no-typescript --release ./.. -- --no-default-features --features "browser"
-python -m SimpleHTTPServer 8000
+python -m http.server 8000
diff --git a/bin/node/cli/browser-demo/index.html b/bin/node/cli/browser-demo/index.html
index cf107e64568f2..0b66b612f10f7 100644
--- a/bin/node/cli/browser-demo/index.html
+++ b/bin/node/cli/browser-demo/index.html
@@ -19,7 +19,7 @@
// Build our client.
log('Starting client');
- let client = start_client(ws());
+ let client = await start_client(ws());
log('Client started');
client.rpcSubscribe('{"method":"chain_subscribeNewHead","params":[],"id":1,"jsonrpc":"2.0"}',
@@ -29,7 +29,7 @@
client
.rpcSend('{"method":"system_networkState","params":[],"id":1,"jsonrpc":"2.0"}')
.then((r) => log("Network state: " + r));
- }, 1000);
+ }, 20000);
}
start();
diff --git a/bin/node/cli/src/browser.rs b/bin/node/cli/src/browser.rs
index bd169cfae3448..9747a583c7808 100644
--- a/bin/node/cli/src/browser.rs
+++ b/bin/node/cli/src/browser.rs
@@ -15,45 +15,31 @@
// along with Substrate. If not, see .
use crate::ChainSpec;
-use futures01::{prelude::*, sync::oneshot, sync::mpsc};
-use libp2p::wasm_ext;
-use log::{debug, info};
-use std::sync::Arc;
-use sc_service::{AbstractService, RpcSession, Roles as ServiceRoles, Configuration, config::DatabaseConfig};
+use log::info;
use wasm_bindgen::prelude::*;
+use sc_service::Configuration;
+use browser_utils::{
+ Transport, Client,
+ browser_configuration, set_console_error_panic_hook, init_console_log,
+};
/// Starts the client.
-///
-/// You must pass a libp2p transport that supports .
#[wasm_bindgen]
-pub fn start_client(wasm_ext: wasm_ext::ffi::Transport) -> Result {
+pub async fn start_client(wasm_ext: Transport) -> Result {
start_inner(wasm_ext)
+ .await
.map_err(|err| JsValue::from_str(&err.to_string()))
}
-fn start_inner(wasm_ext: wasm_ext::ffi::Transport) -> Result> {
- console_error_panic_hook::set_once();
- console_log::init_with_level(log::Level::Info);
+async fn start_inner(wasm_ext: Transport) -> Result> {
+ set_console_error_panic_hook();
+ init_console_log(log::Level::Info)?;
- // Build the configuration to pass to the service.
- let config = {
- let wasm_ext = wasm_ext::ExtTransport::new(wasm_ext);
- let chain_spec = ChainSpec::FlamingFir.load().map_err(|e| format!("{:?}", e))?;
- let mut config = Configuration::<(), _, _>::default_with_spec_and_base_path(chain_spec, None);
- config.network.transport = sc_network::config::TransportConfig::Normal {
- wasm_external_transport: Some(wasm_ext.clone()),
- allow_private_ipv4: true,
- enable_mdns: false,
- };
- config.telemetry_external_transport = Some(wasm_ext);
- config.roles = ServiceRoles::LIGHT;
- config.name = "Browser node".to_string();
- config.database = {
- let db = Arc::new(kvdb_memorydb::create(10));
- DatabaseConfig::Custom(db)
- };
- config
- };
+ let chain_spec = ChainSpec::FlamingFir.load()
+ .map_err(|e| format!("{:?}", e))?;
+
+ let config: Configuration<(), _, _> = browser_configuration(wasm_ext, chain_spec)
+ .await?;
info!("Substrate browser node");
info!(" version {}", config.full_version());
@@ -63,98 +49,8 @@ fn start_inner(wasm_ext: wasm_ext::ffi::Transport) -> Result();
- wasm_bindgen_futures::spawn_local(futures01::future::poll_fn(move || {
- loop {
- match rpc_send_rx.poll() {
- Ok(Async::Ready(Some(message))) => {
- let fut = service.rpc_query(&message.session, &message.rpc_json);
- let _ = message.send_back.send(Box::new(fut));
- },
- Ok(Async::NotReady) => break,
- Err(_) | Ok(Async::Ready(None)) => return Ok(Async::Ready(())),
- }
- }
-
- loop {
- match service.poll().map_err(|_| ())? {
- Async::Ready(()) => return Ok(Async::Ready(())),
- Async::NotReady => break
- }
- }
-
- Ok(Async::NotReady)
- }));
-
- Ok(Client {
- rpc_send_tx,
- })
-}
-
-/// A running client.
-#[wasm_bindgen]
-pub struct Client {
- rpc_send_tx: mpsc::UnboundedSender,
-}
-
-struct RpcMessage {
- rpc_json: String,
- session: RpcSession,
- send_back: oneshot::Sender, Error = ()>>>,
-}
-
-#[wasm_bindgen]
-impl Client {
- /// Allows starting an RPC request. Returns a `Promise` containing the result of that request.
- #[wasm_bindgen(js_name = "rpcSend")]
- pub fn rpc_send(&mut self, rpc: &str) -> js_sys::Promise {
- let rpc_session = RpcSession::new(mpsc::channel(1).0);
- let (tx, rx) = oneshot::channel();
- let _ = self.rpc_send_tx.unbounded_send(RpcMessage {
- rpc_json: rpc.to_owned(),
- session: rpc_session,
- send_back: tx,
- });
- let fut = rx
- .map_err(|_| ())
- .and_then(|fut| fut)
- .map(|s| JsValue::from_str(&s.unwrap_or(String::new())))
- .map_err(|_| JsValue::NULL);
- wasm_bindgen_futures::future_to_promise(fut)
- }
+ let service = crate::service::new_light(config)
+ .map_err(|e| format!("{:?}", e))?;
- /// Subscribes to an RPC pubsub endpoint.
- #[wasm_bindgen(js_name = "rpcSubscribe")]
- pub fn rpc_subscribe(&mut self, rpc: &str, callback: js_sys::Function) {
- let (tx, rx) = mpsc::channel(4);
- let rpc_session = RpcSession::new(tx);
- let (fut_tx, fut_rx) = oneshot::channel();
- let _ = self.rpc_send_tx.unbounded_send(RpcMessage {
- rpc_json: rpc.to_owned(),
- session: rpc_session.clone(),
- send_back: fut_tx,
- });
- let fut_rx = fut_rx
- .map_err(|_| ())
- .and_then(|fut| fut);
- wasm_bindgen_futures::spawn_local(fut_rx.then(|_| Ok(())));
- wasm_bindgen_futures::spawn_local(rx.for_each(move |s| {
- match callback.call1(&callback, &JsValue::from_str(&s)) {
- Ok(_) => Ok(()),
- Err(_) => Err(()),
- }
- }).then(move |v| {
- // We need to keep `rpc_session` alive.
- debug!("RPC subscription has ended");
- drop(rpc_session);
- v
- }));
- }
+ Ok(browser_utils::start_client(service))
}
diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs
index 846f155dedd89..ebc037a970040 100644
--- a/client/cli/src/lib.rs
+++ b/client/cli/src/lib.rs
@@ -28,7 +28,7 @@ pub mod informant;
use sc_client_api::execution_extensions::ExecutionStrategies;
use sc_service::{
- config::{Configuration, DatabaseConfig},
+ config::{Configuration, DatabaseConfig, KeystoreConfig},
ServiceBuilderCommand,
RuntimeGenesis, ChainSpecExtension, PruningMode, ChainSpec,
};
@@ -754,20 +754,22 @@ fn fill_config_keystore_password(
config: &mut sc_service::Configuration,
cli: &RunCmd,
) -> Result<(), String> {
- config.keystore_password = if cli.password_interactive {
- #[cfg(not(target_os = "unknown"))]
- {
- Some(input_keystore_password()?.into())
- }
- #[cfg(target_os = "unknown")]
- None
- } else if let Some(ref file) = cli.password_filename {
- Some(fs::read_to_string(file).map_err(|e| format!("{}", e))?.into())
- } else if let Some(ref password) = cli.password {
- Some(password.clone().into())
- } else {
- None
- };
+ if let KeystoreConfig::Path { password, .. } = &mut config.keystore {
+ *password = if cli.password_interactive {
+ #[cfg(not(target_os = "unknown"))]
+ {
+ Some(input_keystore_password()?.into())
+ }
+ #[cfg(target_os = "unknown")]
+ None
+ } else if let Some(ref file) = cli.password_filename {
+ Some(fs::read_to_string(file).map_err(|e| format!("{}", e))?.into())
+ } else if let Some(ref password) = cli.password {
+ Some(password.clone().into())
+ } else {
+ None
+ };
+ }
Ok(())
}
@@ -873,7 +875,11 @@ where
)?
}
- config.keystore_path = cli.keystore_path.or_else(|| config.in_chain_config_dir(DEFAULT_KEYSTORE_CONFIG_PATH));
+ let default_keystore_path = config.in_chain_config_dir(DEFAULT_KEYSTORE_CONFIG_PATH);
+
+ if let KeystoreConfig::Path { path, ..} = &mut config.keystore {
+ *path = path.clone().or(default_keystore_path);
+ }
// set sentry mode (i.e. act as an authority but **never** actively participate)
config.sentry_mode = cli.sentry;
diff --git a/client/keystore/src/lib.rs b/client/keystore/src/lib.rs
index a4d150a8483c0..f8794aa05e8f6 100644
--- a/client/keystore/src/lib.rs
+++ b/client/keystore/src/lib.rs
@@ -71,7 +71,7 @@ impl std::error::Error for Error {
///
/// Every pair that is being generated by a `seed`, will be placed in memory.
pub struct Store {
- path: PathBuf,
+ path: Option,
additional: HashMap<(KeyTypeId, Vec), Vec>,
password: Option>,
}
@@ -84,10 +84,19 @@ impl Store {
let path = path.into();
fs::create_dir_all(&path)?;
- let instance = Self { path, additional: HashMap::new(), password };
+ let instance = Self { path: Some(path), additional: HashMap::new(), password };
Ok(Arc::new(RwLock::new(instance)))
}
+ /// Create a new in-memory store.
+ pub fn new_in_memory() -> KeyStorePtr {
+ Arc::new(RwLock::new(Self {
+ path: None,
+ additional: HashMap::new(),
+ password: None
+ }))
+ }
+
/// Get the public/private key pair for the given public key and key type.
fn get_additional_pair(
&self,
@@ -113,9 +122,11 @@ impl Store {
///
/// Places it into the file system store.
fn insert_unknown(&self, key_type: KeyTypeId, suri: &str, public: &[u8]) -> Result<()> {
- let mut file = File::create(self.key_file_path(public, key_type)).map_err(Error::Io)?;
- serde_json::to_writer(&file, &suri).map_err(Error::Json)?;
- file.flush().map_err(Error::Io)?;
+ if let Some(path) = self.key_file_path(public, key_type) {
+ let mut file = File::create(path).map_err(Error::Io)?;
+ serde_json::to_writer(&file, &suri).map_err(Error::Json)?;
+ file.flush().map_err(Error::Io)?;
+ }
Ok(())
}
@@ -144,9 +155,11 @@ impl Store {
/// Places it into the file system store.
pub fn generate_by_type(&self, key_type: KeyTypeId) -> Result {
let (pair, phrase, _) = Pair::generate_with_phrase(self.password.as_ref().map(|p| &***p));
- let mut file = File::create(self.key_file_path(pair.public().as_slice(), key_type))?;
- serde_json::to_writer(&file, &phrase)?;
- file.flush()?;
+ if let Some(path) = self.key_file_path(pair.public().as_slice(), key_type) {
+ let mut file = File::create(path)?;
+ serde_json::to_writer(&file, &phrase)?;
+ file.flush()?;
+ }
Ok(pair)
}
@@ -186,7 +199,8 @@ impl Store {
return Ok(pair)
}
- let path = self.key_file_path(public.as_slice(), key_type);
+ let path = self.key_file_path(public.as_slice(), key_type)
+ .ok_or_else(|| Error::Unavailable)?;
let file = File::open(path)?;
let phrase: String = serde_json::from_reader(&file)?;
@@ -219,19 +233,21 @@ impl Store {
})
.collect();
- for entry in fs::read_dir(&self.path)? {
- let entry = entry?;
- let path = entry.path();
-
- // skip directories and non-unicode file names (hex is unicode)
- if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
- match hex::decode(name) {
- Ok(ref hex) if hex.len() > 4 => {
- if &hex[0..4] != &key_type.0 { continue }
- let public = TPublic::from_slice(&hex[4..]);
- public_keys.push(public);
+ if let Some(path) = &self.path {
+ for entry in fs::read_dir(&path)? {
+ let entry = entry?;
+ let path = entry.path();
+
+ // skip directories and non-unicode file names (hex is unicode)
+ if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
+ match hex::decode(name) {
+ Ok(ref hex) if hex.len() > 4 => {
+ if &hex[0..4] != &key_type.0 { continue }
+ let public = TPublic::from_slice(&hex[4..]);
+ public_keys.push(public);
+ }
+ _ => continue,
}
- _ => continue,
}
}
}
@@ -251,12 +267,12 @@ impl Store {
}
/// Returns the file path for the given public key and key type.
- fn key_file_path(&self, public: &[u8], key_type: KeyTypeId) -> PathBuf {
- let mut buf = self.path.clone();
+ fn key_file_path(&self, public: &[u8], key_type: KeyTypeId) -> Option {
+ let mut buf = self.path.as_ref()?.clone();
let key_type = hex::encode(key_type.0);
let key = hex::encode(public);
buf.push(key_type + key.as_str());
- buf
+ Some(buf)
}
}
diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs
index be7a6fb677c4a..e456efe365b4e 100644
--- a/client/service/src/builder.rs
+++ b/client/service/src/builder.rs
@@ -17,7 +17,7 @@
use crate::{Service, NetworkStatus, NetworkState, error::Error, DEFAULT_PROTOCOL_ID};
use crate::{SpawnTaskHandle, start_rpc_servers, build_network_future, TransactionPoolAdapter};
use crate::status_sinks;
-use crate::config::{Configuration, DatabaseConfig};
+use crate::config::{Configuration, DatabaseConfig, KeystoreConfig};
use sc_client_api::{
self,
BlockchainEvents,
@@ -165,10 +165,13 @@ fn new_full_parts(
TGen: sp_runtime::BuildStorage + serde::Serialize + for<'de> serde::Deserialize<'de>,
TCSExt: Extension,
{
- let keystore = Keystore::open(
- config.keystore_path.clone().ok_or("No basepath configured")?,
- config.keystore_password.clone()
- )?;
+ let keystore = match &config.keystore {
+ KeystoreConfig::Path { path, password } => Keystore::open(
+ path.clone().ok_or("No basepath configured")?,
+ password.clone()
+ )?,
+ KeystoreConfig::InMemory => Keystore::new_in_memory()
+ };
let executor = NativeExecutor::::new(
config.wasm_method,
@@ -286,10 +289,13 @@ where TGen: RuntimeGenesis, TCSExt: Extension {
(),
TLightBackend,
>, Error> {
- let keystore = Keystore::open(
- config.keystore_path.clone().ok_or("No basepath configured")?,
- config.keystore_password.clone()
- )?;
+ let keystore = match &config.keystore {
+ KeystoreConfig::Path { path, password } => Keystore::open(
+ path.clone().ok_or("No basepath configured")?,
+ password.clone()
+ )?,
+ KeystoreConfig::InMemory => Keystore::new_in_memory()
+ };
let executor = NativeExecutor::::new(
config.wasm_method,
diff --git a/client/service/src/config.rs b/client/service/src/config.rs
index 8bb8dfeb09a40..94872129dff4c 100644
--- a/client/service/src/config.rs
+++ b/client/service/src/config.rs
@@ -45,8 +45,8 @@ pub struct Configuration {
pub network: NetworkConfiguration,
/// Path to the base configuration directory.
pub config_dir: Option,
- /// Path to key files.
- pub keystore_path: Option,
+ /// Configuration for the keystore.
+ pub keystore: KeystoreConfig,
/// Configuration for the database.
pub database: DatabaseConfig,
/// Size of internal state cache in Bytes
@@ -92,8 +92,6 @@ pub struct Configuration {
pub force_authoring: bool,
/// Disable GRANDPA when running in validator mode
pub disable_grandpa: bool,
- /// Node keystore's password
- pub keystore_password: Option>,
/// Development key seed.
///
/// When running in development mode, the seed will be used to generate authority keys by the keystore.
@@ -106,6 +104,20 @@ pub struct Configuration {
pub tracing_receiver: sc_tracing::TracingReceiver,
}
+/// Configuration of the client keystore.
+#[derive(Clone)]
+pub enum KeystoreConfig {
+ /// Keystore at a path on-disk. Recommended for native nodes.
+ Path {
+ /// The path of the keystore. Will panic if no path is specified.
+ path: Option,
+ /// Node keystore's password.
+ password: Option>
+ },
+ /// In-memory keystore. Recommended for in-browser nodes.
+ InMemory
+}
+
/// Configuration of the database of the client.
#[derive(Clone)]
pub enum DatabaseConfig {
@@ -138,7 +150,10 @@ impl Configuration where
roles: Roles::FULL,
transaction_pool: Default::default(),
network: Default::default(),
- keystore_path: config_dir.map(|c| c.join("keystore")),
+ keystore: KeystoreConfig::Path {
+ path: config_dir.map(|c| c.join("keystore")),
+ password: None
+ },
database: DatabaseConfig::Path {
path: Default::default(),
cache_size: Default::default(),
@@ -161,7 +176,6 @@ impl Configuration where
sentry_mode: false,
force_authoring: false,
disable_grandpa: false,
- keystore_password: None,
dev_key_seed: None,
tracing_targets: Default::default(),
tracing_receiver: Default::default(),
diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs
index cc0e6a72e6abc..d76064300c5a5 100644
--- a/client/service/test/src/lib.rs
+++ b/client/service/test/src/lib.rs
@@ -29,7 +29,7 @@ use sc_service::{
AbstractService,
ChainSpec,
Configuration,
- config::DatabaseConfig,
+ config::{DatabaseConfig, KeystoreConfig},
Roles,
Error,
};
@@ -173,8 +173,10 @@ fn node_config (
roles: role,
transaction_pool: Default::default(),
network: network_config,
- keystore_path: Some(root.join("key")),
- keystore_password: None,
+ keystore: KeystoreConfig::Path {
+ path: Some(root.join("key")),
+ password: None
+ },
config_dir: Some(root.clone()),
database: DatabaseConfig::Path {
path: root.join("db"),
diff --git a/utils/browser/Cargo.toml b/utils/browser/Cargo.toml
new file mode 100644
index 0000000000000..861aae4962d0e
--- /dev/null
+++ b/utils/browser/Cargo.toml
@@ -0,0 +1,27 @@
+[package]
+name = "browser-utils"
+version = "2.0.0"
+authors = ["Parity Technologies "]
+description = "Utilities for creating a browser light-client."
+edition = "2018"
+
+[dependencies]
+futures = "0.3"
+futures01 = { package = "futures", version = "0.1.29" }
+log = "0.4.8"
+libp2p = { version = "0.13.2", default-features = false }
+console_error_panic_hook = "0.1.6"
+console_log = "0.1.2"
+js-sys = "0.3.34"
+wasm-bindgen = "0.2.57"
+wasm-bindgen-futures = "0.4.7"
+kvdb-web = "0.2"
+service = { version = "2.0.0", package = "sc-service", path = "../../client/service", default-features = false }
+network = { package = "sc-network", path = "../../client/network" }
+chain-spec = { package = "sc-chain-spec", path = "../../client/chain-spec" }
+
+# Imported just for the `no_cc` feature
+clear_on_drop = { version = "0.2.3", features = ["no_cc"] }
+# Imported just for the `wasm-bindgen` feature
+rand6 = { package = "rand", version = "0.6", features = ["wasm-bindgen"] }
+rand = { version = "0.7", features = ["wasm-bindgen"] }
diff --git a/utils/browser/src/lib.rs b/utils/browser/src/lib.rs
new file mode 100644
index 0000000000000..fd4ad9f69e101
--- /dev/null
+++ b/utils/browser/src/lib.rs
@@ -0,0 +1,173 @@
+// Copyright 2019 Parity Technologies (UK) Ltd.
+// This file is part of Substrate.
+
+// Substrate is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Substrate is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Substrate. If not, see .
+
+use futures01::sync::mpsc as mpsc01;
+use log::{debug, info};
+use std::sync::Arc;
+use service::{
+ AbstractService, RpcSession, Roles, Configuration, config::{DatabaseConfig, KeystoreConfig},
+ ChainSpec, RuntimeGenesis
+};
+use wasm_bindgen::prelude::*;
+use futures::{
+ TryFutureExt as _, FutureExt as _, Stream as _, Future as _, TryStreamExt as _,
+ channel::{oneshot, mpsc}, future::{poll_fn, ok}, compat::*,
+};
+use std::task::Poll;
+use std::pin::Pin;
+use chain_spec::Extension;
+
+pub use libp2p::wasm_ext::{ExtTransport, ffi::Transport};
+pub use console_error_panic_hook::set_once as set_console_error_panic_hook;
+pub use console_log::init_with_level as init_console_log;
+
+/// Create a service configuration from a chain spec and the websocket transport.
+///
+/// This configuration contains good defaults for a browser light client.
+pub async fn browser_configuration(
+ transport: Transport,
+ chain_spec: ChainSpec,
+) -> Result, Box>
+where
+ C: Default,
+ G: RuntimeGenesis,
+ E: Extension,
+{
+ let name = chain_spec.name().to_string();
+
+ let transport = ExtTransport::new(transport);
+ let mut config = Configuration::default_with_spec_and_base_path(chain_spec, None);
+ config.network.transport = network::config::TransportConfig::Normal {
+ wasm_external_transport: Some(transport.clone()),
+ allow_private_ipv4: true,
+ enable_mdns: false,
+ };
+ config.telemetry_external_transport = Some(transport);
+ config.roles = Roles::LIGHT;
+ config.name = format!("{} (Browser)", name);
+ config.database = {
+ info!("Opening Indexed DB database '{}'...", name);
+ let db = kvdb_web::Database::open(name, 10)
+ .await?;
+ DatabaseConfig::Custom(Arc::new(db))
+ };
+ config.keystore = KeystoreConfig::InMemory;
+
+ Ok(config)
+}
+
+/// A running client.
+#[wasm_bindgen]
+pub struct Client {
+ rpc_send_tx: mpsc::UnboundedSender,
+}
+
+struct RpcMessage {
+ rpc_json: String,
+ session: RpcSession,
+ send_back: oneshot::Sender> + Send>>>,
+}
+
+/// Create a Client object that connects to a service.
+pub fn start_client(service: impl AbstractService) -> Client {
+ let mut service = service.compat();
+ // We dispatch a background task responsible for processing the service.
+ //
+ // The main action performed by the code below consists in polling the service with
+ // `service.poll()`.
+ // The rest consists in handling RPC requests.
+ let (rpc_send_tx, mut rpc_send_rx) = mpsc::unbounded::();
+ wasm_bindgen_futures::spawn_local(poll_fn(move |cx| {
+ loop {
+ match Pin::new(&mut rpc_send_rx).poll_next(cx) {
+ Poll::Ready(Some(message)) => {
+ let fut = service.get_ref()
+ .rpc_query(&message.session, &message.rpc_json)
+ .compat()
+ .unwrap_or_else(|_| None)
+ .boxed();
+ let _ = message.send_back.send(fut);
+ },
+ Poll::Pending => break,
+ Poll::Ready(None) => return Poll::Ready(()),
+ }
+ }
+
+ Pin::new(&mut service)
+ .poll(cx)
+ .map(drop)
+ }));
+
+ Client {
+ rpc_send_tx,
+ }
+}
+
+#[wasm_bindgen]
+impl Client {
+ /// Allows starting an RPC request. Returns a `Promise` containing the result of that request.
+ #[wasm_bindgen(js_name = "rpcSend")]
+ pub fn rpc_send(&mut self, rpc: &str) -> js_sys::Promise {
+ let rpc_session = RpcSession::new(mpsc01::channel(1).0);
+ let (tx, rx) = oneshot::channel();
+ let _ = self.rpc_send_tx.unbounded_send(RpcMessage {
+ rpc_json: rpc.to_owned(),
+ session: rpc_session,
+ send_back: tx,
+ });
+ wasm_bindgen_futures::future_to_promise(async {
+ match rx.await {
+ Ok(fut) => {
+ fut.await
+ .map(|s| JsValue::from_str(&s))
+ .ok_or_else(|| JsValue::NULL)
+ },
+ Err(_) => Err(JsValue::NULL)
+ }
+ })
+ }
+
+ /// Subscribes to an RPC pubsub endpoint.
+ #[wasm_bindgen(js_name = "rpcSubscribe")]
+ pub fn rpc_subscribe(&mut self, rpc: &str, callback: js_sys::Function) {
+ let (tx, rx) = mpsc01::channel(4);
+ let rpc_session = RpcSession::new(tx);
+ let (fut_tx, fut_rx) = oneshot::channel();
+ let _ = self.rpc_send_tx.unbounded_send(RpcMessage {
+ rpc_json: rpc.to_owned(),
+ session: rpc_session.clone(),
+ send_back: fut_tx,
+ });
+ wasm_bindgen_futures::spawn_local(async {
+ if let Ok(fut) = fut_rx.await {
+ fut.await;
+ }
+ });
+
+ wasm_bindgen_futures::spawn_local(async move {
+ let _ = rx.compat()
+ .try_for_each(|s| {
+ let _ = callback.call1(&callback, &JsValue::from_str(&s));
+ ok(())
+ })
+ .await;
+
+ // We need to keep `rpc_session` alive.
+ debug!("RPC subscription has ended");
+ drop(rpc_session);
+ });
+ }
+}