This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the code for compiling node-cli for WASM-browser (#3974)
* Extract CLI to separate module in node/cli * Make node/cli compile for WASM * More work on node/cli browser * More work on browser node * More work * More work * Purge a bit the CI script * More clean up * Remove substrate-finality-grandpa from the CI Its tests use tokio, which fails to compile. * Address review * Add rocksdb feature to the service * Fix substrate-service WASM CI * Apply suggestions from code review Co-Authored-By: Bastian Köcher <[email protected]> * Don't WASM-compile substrate-service altogether
- Loading branch information
Showing
18 changed files
with
687 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,12 @@ version = "2.0.0" | |
authors = ["Parity Technologies <[email protected]>"] | ||
edition = "2018" | ||
|
||
[features] | ||
default = ["rocksdb"] | ||
# The RocksDB feature activates the RocksDB database backend. If it is not activated, and you pass | ||
# a path to a database, an error will be produced at runtime. | ||
rocksdb = ["client_db/kvdb-rocksdb"] | ||
|
||
[dependencies] | ||
derive_more = "0.15.0" | ||
futures = "0.1.29" | ||
|
@@ -29,7 +35,7 @@ consensus_common = { package = "substrate-consensus-common", path = "../../core/ | |
network = { package = "substrate-network", path = "../../core/network" } | ||
chain-spec = { package = "substrate-chain-spec", path = "../chain-spec" } | ||
client = { package = "substrate-client", path = "../../core/client" } | ||
client_db = { package = "substrate-client-db", path = "../../core/client/db", features = ["kvdb-rocksdb"] } | ||
client_db = { package = "substrate-client-db", path = "../../core/client/db" } | ||
codec = { package = "parity-scale-codec", version = "1.0.0" } | ||
substrate-executor = { path = "../../core/executor" } | ||
transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# How to run this demo | ||
|
||
```sh | ||
cargo install wasm-pack # If necessary | ||
|
||
# From the `node/cli` directory (parent from this README) | ||
wasm-pack build --target web --out-dir ./demo/pkg --no-typescript --release -- --no-default-features --features "browser" | ||
|
||
xdg-open index.html | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/> | ||
<title>Substrate node</title> | ||
<link rel="shortcut icon" href="/favicon.png" /> | ||
<script type="module"> | ||
import { start_client, default as init } from './pkg/node_cli.js'; | ||
import ws from './ws.js'; | ||
|
||
function log(msg) { | ||
document.getElementsByTagName('body')[0].innerHTML += msg + '\n'; | ||
} | ||
|
||
async function start() { | ||
log('Loading WASM'); | ||
await init('./pkg/node_cli_bg.wasm'); | ||
log('Successfully loaded WASM'); | ||
|
||
// Build our client. | ||
log('Starting client'); | ||
let client = start_client(ws()); | ||
log('Client started'); | ||
|
||
client.rpcSubscribe('{"method":"chain_subscribeNewHead","params":[],"id":1,"jsonrpc":"2.0"}', | ||
(r) => log("New chain head: " + r)); | ||
|
||
setInterval(() => { | ||
client | ||
.rpcSend('{"method":"system_networkState","params":[],"id":1,"jsonrpc":"2.0"}') | ||
.then((r) => log("Network state: " + r)); | ||
}, 1000); | ||
} | ||
|
||
start(); | ||
</script> | ||
</head> | ||
<body style="white-space: pre"></body> | ||
</html> |
Oops, something went wrong.