Skip to content

Commit f78e159

Browse files
authored
Merge pull request #91 from danielgranhao/support-wasm
Support wasm
2 parents 4520445 + 662ab3b commit f78e159

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4127
-2669
lines changed

.github/workflows/build.yaml

+31-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
on:
22
push:
33
branches:
4-
- master
4+
- master
55
pull_request:
66

77
name: build
@@ -15,16 +15,14 @@ jobs:
1515
matrix:
1616
rust:
1717
- stable
18-
- nightly
19-
features:
20-
- default
18+
- nightly
2119
steps:
2220
- name: checkout
2321
uses: actions/checkout@v3
2422
- name: Generate cache key
25-
run: echo "${{ matrix.rust }} ${{ matrix.features }}" | tee .cache_key
23+
run: echo "${{ matrix.rust }}" | tee .cache_key
2624
- name: cache
27-
uses: actions/cache@v2
25+
uses: actions/cache@v3
2826
with:
2927
path: |
3028
~/.cargo/registry
@@ -33,9 +31,35 @@ jobs:
3331
key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
3432
- name: Set default toolchain
3533
run: rustup default ${{ matrix.rust }}
34+
- name: Add wasm target
35+
run: rustup target add wasm32-unknown-unknown
3636
- name: Set profile
3737
run: rustup set profile minimal
3838
- name: Update toolchain
3939
run: rustup update
4040
- name: Build
41-
run: cargo build --features ${{ matrix.features }}
41+
run: make cargo-build
42+
- name: Build wasm
43+
run: make wasm-build
44+
45+
build-as-wasm-dependency:
46+
name: Build as wasm dependency
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: checkout
50+
uses: actions/checkout@v3
51+
- name: Add wasm target
52+
run: rustup target add wasm32-unknown-unknown
53+
- name: Install wasm-pack
54+
run: cargo install wasm-pack
55+
- name: Create wasm project
56+
run: |
57+
wasm-pack new wasm-project
58+
cd wasm-project
59+
sed -i.bak -e 's/edition = .*/edition = "2021"/' Cargo.toml
60+
rm Cargo.toml.bak
61+
# Patch needed until secp256k1-zkp wasm compatibility is fixed
62+
echo -e '\n[workspace]\n\n[patch.crates-io]\nsecp256k1-zkp = { git = "https://github.com/danielgranhao/rust-secp256k1-zkp.git", rev = "eac2e479255a6e32b5588bc25ee53c642fdd8395" }' >> Cargo.toml
63+
# In this test, we reference the checked out repo (e.g. this PR branch)
64+
cargo add --path ../ boltz-client
65+
wasm-pack build --target web

.github/workflows/lint.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
on:
22
push:
33
branches:
4-
- master
4+
- master
55
pull_request:
66

77
name: lint
@@ -22,9 +22,13 @@ jobs:
2222
run: rustup component add rustfmt
2323
- name: Add clippy
2424
run: rustup component add clippy
25+
- name: Add wasm target
26+
run: rustup target add wasm32-unknown-unknown
2527
- name: Update toolchain
2628
run: rustup update
2729
- name: Check fmt
2830
run: cargo fmt --all -- --check
2931
- name: Clippy
30-
run: cargo clippy --all-targets --all-features -- -D warnings
32+
run: make cargo-clippy
33+
- name: Clippy wasm
34+
run: make wasm-clippy

.github/workflows/test.yaml

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
on:
22
push:
33
branches:
4-
- master
4+
- master
55
pull_request:
66

77
name: test
@@ -17,5 +17,41 @@ jobs:
1717
run: rustup default nightly
1818
- name: Set profile
1919
run: rustup set profile minimal
20+
- name: Add wasm target
21+
run: rustup target add wasm32-unknown-unknown
22+
- name: Install wasm-pack
23+
run: cargo install wasm-pack
2024
- name: Run cargo test
21-
run: cargo test -- --nocapture
25+
run: make cargo-test
26+
- name: Run wasm-pack test
27+
run: make wasm-test
28+
29+
regtest-test:
30+
name: Run regtest tests
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
with:
36+
submodules: true
37+
- name: Set up Docker
38+
uses: docker/setup-buildx-action@v2
39+
- name: Set up Docker Compose
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install -y docker-compose
43+
- name: Set default toolchain
44+
run: rustup default nightly
45+
- name: Set profile
46+
run: rustup set profile minimal
47+
- name: Add wasm target
48+
run: rustup target add wasm32-unknown-unknown
49+
- name: Install wasm-pack
50+
run: cargo install wasm-pack
51+
- name: Start regtest environment
52+
working-directory: regtest
53+
run: sh start.sh
54+
- name: Run cargo regtest tests
55+
run: make cargo-regtest-test
56+
- name: Run WASM regtest tests
57+
run: make wasm-regtest-test

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "regtest/boltz"]
2+
path = regtest/boltz
3+
url = https://github.com/BoltzExchange/regtest

Cargo.toml

+44-14
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
name = "boltz-client"
33
description = "a boltz exchange client for swaps between BTC/LBTC & LN"
44
authors = ["i5hi <[email protected]>", "Rajarshi Maitra <[email protected]>"]
5-
version = "0.2.0"
5+
version = "0.3.0"
66
edition = "2021"
7-
license="MIT"
7+
license = "MIT"
88

99
[lib]
1010
name = "boltz_client"
1111
path = "src/lib.rs"
1212
doctest = false
13-
crate-type = ["lib"]
13+
crate-type = ["lib"]
14+
15+
[workspace]
16+
members = [
17+
"macros"
18+
]
1419

1520
[profile.release]
1621
strip = true
@@ -22,28 +27,53 @@ panic = "abort"
2227
[dependencies]
2328
serde = { version = "1.0.0", features = ["derive"] }
2429
serde_json = "1.0.0"
25-
ureq = { version = "2.5.0", features = ["json", "native-tls"] }
2630
bip39 = "2.0.0"
27-
electrum-client = { version = "0.21.0", default-features=false, features = ["use-rustls-ring", "proxy"] }
28-
bitcoin = {version = "0.32.2", features = ["rand", "base64", "rand-std"]}
31+
bitcoin = { version = "0.32.2", features = ["rand", "base64", "rand-std"] }
2932
elements = { version = "0.25.0", features = ["serde"] }
3033
lightning-invoice = "0.32.0"
31-
tungstenite = { version = "0.21.0", features = ["native-tls-vendored"] }
3234
url = "2.5.0"
3335
log = "^0.4"
3436
env_logger = "0.7"
35-
native-tls = "0.2.11"
3637
hex = "0.4"
37-
lnurl-rs = { version = "0.8.0", optional = true }
38+
lnurl-rs = { version = "0.9.0", default-features = false, features = ["async", "async-https"], optional = true }
39+
# Pin to commit until https://github.com/seanmonstar/reqwest/pull/1760 gets released
40+
reqwest = { git = "https://github.com/seanmonstar/reqwest", rev = "00b15b9a893d350388af513179e1a973dfa26f85", features = ["json"] }
41+
tokio-tungstenite-wasm = { version = "0.5.0", features = ["native-tls-vendored"] }
42+
async-trait = "0.1.86"
43+
macros = { path = "macros" }
44+
45+
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
46+
electrum-client = { version = "0.21.0", default-features = false, features = ["use-rustls-ring", "proxy"], optional = true }
47+
tokio = "1.43.0"
48+
49+
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
50+
getrandom = { version = "0.2", features = ["js"] }
51+
js-sys = "0.3.77"
52+
web-sys = "0.3.77"
53+
wasm-bindgen-futures = "0.4.50"
3854

3955
[patch.crates-io]
40-
secp256k1-zkp = { git = "https://github.com/dangeross/rust-secp256k1-zkp.git", rev = "57d29b15269ca2ce3c3b118b6a72b66c1169e7b1" }
56+
secp256k1-zkp = { git = "https://github.com/danielgranhao/rust-secp256k1-zkp.git", rev = "eac2e479255a6e32b5588bc25ee53c642fdd8395" }
4157

4258
[dev-dependencies]
43-
bitcoind = {version = "0.36.0", features = ["25_0"] }
44-
elementsd = {version = "0.11.0", features = ["22_1_1"] }
59+
futures-util = "0.3.31"
60+
serial_test = "3.2.0"
61+
62+
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dev-dependencies]
63+
bitcoind = { version = "0.36.0", features = ["25_0"] }
64+
elementsd = { version = "0.11.0", features = ["22_1_1"] }
65+
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
66+
67+
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies]
68+
wasm-bindgen-test = "0.3.50"
69+
wasm-bindgen = "0.2.100"
70+
gloo-timers = { version = "0.3.0", features = ["futures"] }
71+
futures = "0.3.31"
4572

46-
#Empty default feature set, (helpful to generalise in github actions)
4773
[features]
48-
default = []
74+
default = ["esplora"]
4975
lnurl = ["dep:lnurl-rs"]
76+
esplora = []
77+
electrum = ["dep:electrum-client"]
78+
# Feature to enable tests that require previous initialization of a regtest environment
79+
regtest = []

Makefile

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
UNAME := $(shell uname)
2+
3+
ifeq ($(UNAME), Darwin)
4+
CLANG_PREFIX += AR=$(shell brew --prefix llvm)/bin/llvm-ar CC=$(shell brew --prefix llvm)/bin/clang
5+
endif
6+
7+
LND_MACAROON_HEX=$(shell xxd -p regtest/boltz/data/lnd1/data/chain/bitcoin/regtest/admin.macaroon | tr -d '\n')
8+
BITCOIND_COOKIE=$(shell cat regtest/boltz/data/bitcoind/regtest/.cookie)
9+
REGTEST_PREFIX = LND_MACAROON_HEX=$(LND_MACAROON_HEX) BITCOIND_COOKIE=$(BITCOIND_COOKIE)
10+
11+
init:
12+
cargo install wasm-pack
13+
14+
build: cargo-build cargo-clippy
15+
16+
cargo-build:
17+
cargo build --all-targets --all-features
18+
19+
wasm-build:
20+
cargo build --target=wasm32-unknown-unknown --all-features
21+
22+
clippy: cargo-clippy wasm-clippy
23+
24+
test: cargo-test wasm-test
25+
26+
regtest-test: cargo-regtest-test wasm-regtest-test
27+
28+
cargo-clippy:
29+
cargo clippy --all-targets --all-features -- -D warnings
30+
31+
cargo-test:
32+
cargo test --features "esplora, electrum, lnurl" -- --nocapture
33+
34+
cargo-regtest-test:
35+
$(REGTEST_PREFIX) cargo test regtest --features "electrum, regtest" -- --nocapture
36+
37+
wasm-clippy:
38+
$(CLANG_PREFIX) cargo clippy --target=wasm32-unknown-unknown --all-features -- -D warnings
39+
40+
BROWSER ?= firefox
41+
42+
wasm-test:
43+
$(CLANG_PREFIX) wasm-pack test --headless --$(BROWSER)
44+
45+
wasm-test-chrome:
46+
BROWSER=chrome $(MAKE) wasm-test
47+
48+
wasm-test-safari:
49+
BROWSER=safari $(MAKE) wasm-test
50+
51+
wasm-regtest-test:
52+
$(CLANG_PREFIX) $(REGTEST_PREFIX) WASM_BINDGEN_TEST_TIMEOUT=500 wasm-pack test --headless --$(BROWSER) --features regtest -- regtest
53+
54+
wasm-regtest-test-chrome:
55+
BROWSER=chrome $(MAKE) wasm-regtest-test
56+
57+
wasm-regtest-test-safari:
58+
BROWSER=safari $(MAKE) wasm-regtest-test

0 commit comments

Comments
 (0)