Skip to content

Commit 1bc360d

Browse files
Implement avail-light-web
1 parent 59159e1 commit 1bc360d

File tree

13 files changed

+296
-10
lines changed

13 files changed

+296
-10
lines changed

.github/workflows/default.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ jobs:
3333
- uses: actions-rust-lang/setup-rust-toolchain@v1
3434
with:
3535
components: clippy
36-
- run: cargo clippy --workspace -- -D warnings
36+
# TODO: Enable avail-light-web once issue with rocksdb feature being applied
37+
# accross the workspace is resolved
38+
- run: cargo clippy --workspace --exclude avail-light-web -- -D warnings
3739

3840
test:
3941
name: cargo test
@@ -42,7 +44,9 @@ jobs:
4244
- uses: actions/checkout@v4
4345
- uses: arduino/setup-protoc@v2
4446
- uses: actions-rust-lang/setup-rust-toolchain@v1
45-
- run: cargo test --workspace --benches --tests
47+
# TODO: Enable avail-light-web once issue with rocksdb feature being applied
48+
# accross the workspace is resolved
49+
- run: cargo test --workspace --benches --tests --exclude avail-light-web
4650
env:
4751
RUSTFLAGS: "-C instrument-coverage"
4852
LLVM_PROFILE_FILE: "profile-%p-%m.profraw"

Cargo.lock

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"crawler",
88
"fat",
99
"relay",
10+
"web",
1011
]
1112
default-members = ["client"]
1213
resolver = "2"
@@ -25,7 +26,7 @@ anyhow = "1.0.71"
2526
async-std = { version = "1.12.0", features = ["attributes"] }
2627
async-trait = "0.1.73"
2728
clap = { version = "4.4.4", features = ["derive", "cargo"] }
28-
color-eyre = "0.6.2"
29+
color-eyre = { version = "0.6.2", default-features = false }
2930
confy = "0.5.1"
3031
hex = "0.4.3"
3132
rand = { version = "0.8.5", default-features = false }

core/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ async-stream = "0.3.5"
1717
async-trait = { workspace = true }
1818
base64 = "0.21.0"
1919
better-panic = "0.3.0"
20+
chrono = "0.4.19"
2021
clap = { workspace = true }
2122
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full", "bit-vec"] }
22-
color-eyre = { workspace = true }
2323
convert_case = "0.6.0"
24+
color-eyre = { workspace = true, default-features = true }
25+
confy = { workspace = true }
2426
derive_more = { version = "1", features = ["from"] }
2527
dusk-bytes = "0.1.7"
2628
futures = { workspace = true }
@@ -75,16 +77,17 @@ opentelemetry_sdk = { workspace = true }
7577

7678
[target.'cfg(target_arch = "wasm32")'.dependencies]
7779
blake2b_simd = "1.0.2"
80+
color-eyre = { workspace = true }
7881
ed25519-compact = "2.1.1"
7982
# NOTE: This is used due bug explained at: https://github.com/tomaka/wasm-timer/pull/13
8083
fluvio-wasm-timer = "0.2.5"
8184
libp2p = { workspace = true, features = ["wasm-bindgen"] }
8285
libp2p-webrtc-websys = { workspace = true }
83-
thiserror-no-std = "2.0.2"
8486
rand = { workspace = true, features = ["std_rng"] }
87+
thiserror-no-std = "2.0.2"
8588
tokio_with_wasm = { version = "0.7.1", default-features = false, features = ["sync", "macros", "rt", "time"] }
86-
wasm-bindgen = "0.2.90"
8789
web-time = "1.1.0"
90+
wasm-bindgen = "0.2.90"
8891

8992
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
9093
hex-literal = "0.4.1"

core/src/light_client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use crate::{
4343
utils::{blake2_256, calculate_confidence, extract_kate},
4444
};
4545

46+
#[derive(Debug)]
4647
pub enum OutputEvent {
4748
RecordBlockProcessingDelay(f64),
4849
CountSessionBlocks,

core/src/network/p2p.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,9 @@ async fn build_swarm(
315315
};
316316
#[cfg(target_arch = "wasm32")]
317317
{
318+
use libp2p_webrtc_websys as webrtc;
318319
swarm = tokio_swarm
319-
.with_other_transport(|key| {
320-
libp2p_webrtc_websys::Transport::new(libp2p_webrtc_websys::Config::new(&key))
321-
})?
320+
.with_other_transport(|key| webrtc::Transport::new(webrtc::Config::new(&key)))?
322321
.with_relay_client(noise::Config::new, yamux::Config::default)?
323322
.with_behaviour(behaviour)?
324323
.with_swarm_config(|c| generate_config(c, cfg))

core/src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use avail_rust::{
66
avail_core::DataLookup,
77
kate_recovery::{commitments, matrix::Dimensions},
88
sp_core::{bytes, ed25519},
9-
AvailHeader, Keypair, H256,
9+
AvailHeader, H256,
1010
};
1111
#[cfg(not(target_arch = "wasm32"))]
1212
use avail_rust::{
@@ -15,6 +15,7 @@ use avail_rust::{
1515
bip39::{Language, Mnemonic},
1616
SecretString, SecretUri,
1717
},
18+
Keypair,
1819
};
1920
use base64::{engine::general_purpose, DecodeError, Engine};
2021
use codec::{Decode, Encode, Input};

core/src/utils.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,19 @@ pub fn filter_auth_set_changes(header: &AvailHeader) -> Vec<Vec<(AuthorityId, u6
119119
}
120120

121121
pub fn install_panic_hooks(shutdown: Controller<String>) -> Result<()> {
122+
#[cfg(not(target_arch = "wasm32"))]
122123
// initialize color-eyre hooks
123124
let (panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default()
124125
.display_location_section(true)
125126
.display_env_section(true)
126127
.into_hooks();
127128

129+
#[cfg(target_arch = "wasm32")]
130+
// initialize color-eyre hooks
131+
let (panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default()
132+
.display_env_section(true)
133+
.into_hooks();
134+
128135
// install hook as global handler
129136
eyre_hook.install()?;
130137

web/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "avail-light-web"
3+
version = "0.1.0"
4+
authors.workspace = true
5+
edition = "2021"
6+
repository.workspace = true
7+
8+
[lib]
9+
crate-type = ["cdylib", "rlib"]
10+
11+
[features]
12+
default = ["console_error_panic_hook"]
13+
14+
[dependencies]
15+
avail-light-core = { workspace = true }
16+
avail-rust = { workspace = true }
17+
clap = { workspace = true }
18+
console_error_panic_hook = { version = "0.1.7", optional = true }
19+
futures = { workspace = true }
20+
libp2p = { workspace = true }
21+
sp-io = { version = "30", features = ["disable_allocator", "disable_panic_handler"], default-features = false }
22+
tokio = { version = "^1", default-features = false, features = ["sync", "macros", "io-util", "rt"] }
23+
tokio_with_wasm = { version = "0.7.1", features = ["sync", "macros", "rt"] }
24+
tracing = { workspace = true }
25+
tracing-subscriber = { workspace = true }
26+
tracing-wasm = "0.2.1"
27+
wasm-bindgen = "0.2.93"
28+
wasm-bindgen-futures = "0.4.43"
29+
web-sys = { version = "0.3.70", features = ["console", "Window", "UrlSearchParams"] }
30+
web-time = "1.1.0"

web/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Avail Light Client (Web)
2+
3+
## Compile
4+
5+
`wasm-pack build --target web --dev`
6+
7+
## Run
8+
9+
`cp www/index.html pkg/`
10+
`cd pkg`
11+
`python3 -m http.server --directory .`
12+
13+
# Start LC
14+
15+
- Safari: http://localhost:8000/?network=hex&bootstrap=%2Fip4%2F209.38.38.158%2Fudp%2F39001%2Fwebrtc-direct%2Fcerthash%2FuEiCVz-CTCrMq4I2xwW_WznQPML3dos4GNWiXE_fJjvHiIg
16+
- Firefox: 0.0.0.0:8000/?network=hex&bootstrap=%2Fip4%2F209.38.38.158%2Fudp%2F39001%2Fwebrtc-direct%2Fcerthash%2FuEiCVz-CTCrMq4I2xwW_WznQPML3dos4GNWiXE_fJjvHiIg

0 commit comments

Comments
 (0)