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
Add the code for compiling node-cli for WASM-browser #3974
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0d6a0f6
Extract CLI to separate module in node/cli
tomaka 222a6de
Make node/cli compile for WASM
tomaka 2a282e9
More work on node/cli browser
tomaka 40b0dd1
More work on browser node
tomaka ca27dcd
More work
tomaka eb5b5c8
More work
tomaka 677b8b5
Purge a bit the CI script
tomaka bf9c5ed
More clean up
tomaka c49401f
Remove substrate-finality-grandpa from the CI
tomaka 84f3392
Address review
tomaka 708a59e
Add rocksdb feature to the service
tomaka fdb4f76
Fix substrate-service WASM CI
tomaka e89e188
Apply suggestions from code review
tomaka cbe0f81
Don't WASM-compile substrate-service altogether
tomaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,4 @@ | ||||||||
cd .. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Can you not just give the path to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't possible back when I wrote by initial prototype, but seems possible now 👍 |
||||||||
wasm-pack build --target web --out-dir ./browser-demo/pkg --no-typescript --release -- --no-default-features --features "browser" | ||||||||
cd browser-demo | ||||||||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this change might break
node-template
and Polkadot.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added
rocksdb
as an enabled-by-default feature onsubstrate-service
. When you import the service, you have to explicitly saydefault-features = false
if you don't want rocksdb. This should be fairly fail-safe.For context, what happens in the worst case scenario is an error at initialization, so it's not that big of a deal. What I'm mostly trying to avoid is the surprise factor.