Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wasm #91

Merged
merged 28 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ef22334
Fix secp256k1-zkp WASM compatibility
danielgranhao Feb 20, 2025
e5c4f25
Enable js feature in getrandom
danielgranhao Feb 20, 2025
0ebb55b
Use async reqwest
danielgranhao Feb 24, 2025
85d56dc
Use tokio-tungstenite-wasm for websocket stream
danielgranhao Feb 24, 2025
c3af0f6
Add esplora support
danielgranhao Feb 25, 2025
89da463
Adjust GH actions
danielgranhao Feb 25, 2025
9a353e7
Update README.md
danielgranhao Feb 26, 2025
04e2408
Fix esplora timeout const name
danielgranhao Feb 26, 2025
2ff289d
Esplora fixes
danielgranhao Feb 26, 2025
3598ac2
Use test macros where missing
danielgranhao Feb 26, 2025
2ea8ad7
Add missing esplora conditionals
danielgranhao Feb 26, 2025
d7395ba
Fix get swap
danielgranhao Feb 26, 2025
840404a
Fix fmt lint
danielgranhao Feb 27, 2025
8aab73a
Run tests on regtest
danielgranhao Mar 5, 2025
e2b7034
Update secp256k1-zkp patch
danielgranhao Mar 7, 2025
a6d9d1c
Allow chain client reuse
danielgranhao Mar 7, 2025
b6b46ca
Update readme
danielgranhao Mar 7, 2025
a27d7b5
Rename const
danielgranhao Mar 7, 2025
c1caf6c
Add missing new line
danielgranhao Mar 10, 2025
3cebee2
Switch to vendored native tls on tokio-tungetenite
danielgranhao Mar 10, 2025
3f7ee4c
Expose WebSocketStream
danielgranhao Mar 10, 2025
2fb92c9
Optimize electrum's fetch_utxos_core
danielgranhao Mar 10, 2025
58f93e5
Rename fetch_utxo_core to extract_address_utxos
danielgranhao Mar 10, 2025
bd904fc
Split configs and chain into Bitcoin and Liquid counterparts
danielgranhao Mar 10, 2025
d43ffc9
Expose entire tokio-tungstenite-wasm
danielgranhao Mar 10, 2025
73a41a3
Drop client configs
danielgranhao Mar 10, 2025
f48f3d5
Refactor ws message structs and add ping/pong messages
danielgranhao Mar 12, 2025
662ab3b
Bump crate version
danielgranhao Mar 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
push:
branches:
- master
- master
pull_request:

name: build
Expand All @@ -15,16 +15,14 @@ jobs:
matrix:
rust:
- stable
- nightly
features:
- default
- nightly
steps:
- name: checkout
uses: actions/checkout@v3
- name: Generate cache key
run: echo "${{ matrix.rust }} ${{ matrix.features }}" | tee .cache_key
run: echo "${{ matrix.rust }}" | tee .cache_key
- name: cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
Expand All @@ -33,9 +31,35 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
- name: Set default toolchain
run: rustup default ${{ matrix.rust }}
- name: Add wasm target
run: rustup target add wasm32-unknown-unknown
- name: Set profile
run: rustup set profile minimal
- name: Update toolchain
run: rustup update
- name: Build
run: cargo build --features ${{ matrix.features }}
run: make cargo-build
- name: Build wasm
run: make wasm-build

build-as-wasm-dependency:
name: Build as wasm dependency
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: Add wasm target
run: rustup target add wasm32-unknown-unknown
- name: Install wasm-pack
run: cargo install wasm-pack
- name: Create wasm project
run: |
wasm-pack new wasm-project
cd wasm-project
sed -i.bak -e 's/edition = .*/edition = "2021"/' Cargo.toml
rm Cargo.toml.bak
# Patch needed until secp256k1-zkp wasm compatibility is fixed
echo -e '\n[workspace]\n\n[patch.crates-io]\nsecp256k1-zkp = { git = "https://github.com/danielgranhao/rust-secp256k1-zkp.git", rev = "eac2e479255a6e32b5588bc25ee53c642fdd8395" }' >> Cargo.toml
# In this test, we reference the checked out repo (e.g. this PR branch)
cargo add --path ../ boltz-client
wasm-pack build --target web
8 changes: 6 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
push:
branches:
- master
- master
pull_request:

name: lint
Expand All @@ -22,9 +22,13 @@ jobs:
run: rustup component add rustfmt
- name: Add clippy
run: rustup component add clippy
- name: Add wasm target
run: rustup target add wasm32-unknown-unknown
- name: Update toolchain
run: rustup update
- name: Check fmt
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
run: make cargo-clippy
- name: Clippy wasm
run: make wasm-clippy
40 changes: 38 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
push:
branches:
- master
- master
pull_request:

name: test
Expand All @@ -17,5 +17,41 @@ jobs:
run: rustup default nightly
- name: Set profile
run: rustup set profile minimal
- name: Add wasm target
run: rustup target add wasm32-unknown-unknown
- name: Install wasm-pack
run: cargo install wasm-pack
- name: Run cargo test
run: cargo test -- --nocapture
run: make cargo-test
- name: Run wasm-pack test
run: make wasm-test

regtest-test:
name: Run regtest tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Set up Docker
uses: docker/setup-buildx-action@v2
- name: Set up Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Set default toolchain
run: rustup default nightly
- name: Set profile
run: rustup set profile minimal
- name: Add wasm target
run: rustup target add wasm32-unknown-unknown
- name: Install wasm-pack
run: cargo install wasm-pack
- name: Start regtest environment
working-directory: regtest
run: sh start.sh
- name: Run cargo regtest tests
run: make cargo-regtest-test
- name: Run WASM regtest tests
run: make wasm-regtest-test
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "regtest/boltz"]
path = regtest/boltz
url = https://github.com/BoltzExchange/regtest
56 changes: 43 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ description = "a boltz exchange client for swaps between BTC/LBTC & LN"
authors = ["i5hi <[email protected]>", "Rajarshi Maitra <[email protected]>"]
version = "0.2.0"
edition = "2021"
license="MIT"
license = "MIT"

[lib]
name = "boltz_client"
path = "src/lib.rs"
doctest = false
crate-type = ["lib"]
crate-type = ["lib"]

[workspace]
members = [
"macros"
]

[profile.release]
strip = true
Expand All @@ -22,28 +27,53 @@ panic = "abort"
[dependencies]
serde = { version = "1.0.0", features = ["derive"] }
serde_json = "1.0.0"
ureq = { version = "2.5.0", features = ["json", "native-tls"] }
bip39 = "2.0.0"
electrum-client = { version = "0.21.0", default-features=false, features = ["use-rustls-ring", "proxy"] }
bitcoin = {version = "0.32.2", features = ["rand", "base64", "rand-std"]}
bitcoin = { version = "0.32.2", features = ["rand", "base64", "rand-std"] }
elements = { version = "0.25.0", features = ["serde"] }
lightning-invoice = "0.32.0"
tungstenite = { version = "0.21.0", features = ["native-tls-vendored"] }
url = "2.5.0"
log = "^0.4"
env_logger = "0.7"
native-tls = "0.2.11"
hex = "0.4"
lnurl-rs = { version = "0.8.0", optional = true }
lnurl-rs = { version = "0.9.0", default-features = false, features = ["async", "async-https"], optional = true }
# Pin to commit until https://github.com/seanmonstar/reqwest/pull/1760 gets released
reqwest = { git = "https://github.com/seanmonstar/reqwest", rev = "00b15b9a893d350388af513179e1a973dfa26f85", features = ["json"] }
tokio-tungstenite-wasm = { version = "0.5.0", features = ["native-tls"] }
async-trait = "0.1.86"
macros = { path = "macros" }

[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
electrum-client = { version = "0.21.0", default-features = false, features = ["use-rustls-ring", "proxy"], optional = true }
tokio = "1.43.0"

[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
js-sys = "0.3.77"
web-sys = "0.3.77"
wasm-bindgen-futures = "0.4.50"

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

[dev-dependencies]
bitcoind = {version = "0.36.0", features = ["25_0"] }
elementsd = {version = "0.11.0", features = ["22_1_1"] }
futures-util = "0.3.31"
serial_test = "3.2.0"

[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dev-dependencies]
bitcoind = { version = "0.36.0", features = ["25_0"] }
elementsd = { version = "0.11.0", features = ["22_1_1"] }
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }

[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies]
wasm-bindgen-test = "0.3.50"
wasm-bindgen = "0.2.100"
gloo-timers = { version = "0.3.0", features = ["futures"] }
futures = "0.3.31"

#Empty default feature set, (helpful to generalise in github actions)
[features]
default = []
default = ["esplora"]
lnurl = ["dep:lnurl-rs"]
esplora = []
electrum = ["dep:electrum-client"]
# Feature to enable tests that require previous initialization of a regtest environment
regtest = []
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
UNAME := $(shell uname)

ifeq ($(UNAME), Darwin)
CLANG_PREFIX += AR=$(shell brew --prefix llvm)/bin/llvm-ar CC=$(shell brew --prefix llvm)/bin/clang
endif

LND_MACAROON_HEX=$(shell xxd -p regtest/boltz/data/lnd1/data/chain/bitcoin/regtest/admin.macaroon | tr -d '\n')
BITCOIND_COOKIE=$(shell cat regtest/boltz/data/bitcoind/regtest/.cookie)
REGTEST_PREFIX = LND_MACAROON_HEX=$(LND_MACAROON_HEX) BITCOIND_COOKIE=$(BITCOIND_COOKIE)

init:
cargo install wasm-pack

build: cargo-build cargo-clippy

cargo-build:
cargo build --all-targets --all-features

wasm-build:
cargo build --target=wasm32-unknown-unknown --all-features

clippy: cargo-clippy wasm-clippy

test: cargo-test wasm-test

regtest-test: cargo-regtest-test wasm-regtest-test

cargo-clippy:
cargo clippy --all-targets --all-features -- -D warnings

cargo-test:
cargo test --features "esplora, electrum, lnurl" -- --nocapture

cargo-regtest-test:
$(REGTEST_PREFIX) cargo test regtest --features "electrum, regtest" -- --nocapture

wasm-clippy:
$(CLANG_PREFIX) cargo clippy --target=wasm32-unknown-unknown --all-features -- -D warnings

BROWSER ?= firefox

wasm-test:
$(CLANG_PREFIX) wasm-pack test --headless --$(BROWSER)

wasm-test-chrome:
BROWSER=chrome $(MAKE) wasm-test

wasm-test-safari:
BROWSER=safari $(MAKE) wasm-test

wasm-regtest-test:
$(CLANG_PREFIX) $(REGTEST_PREFIX) WASM_BINDGEN_TEST_TIMEOUT=500 wasm-pack test --headless --$(BROWSER) --features regtest -- regtest

wasm-regtest-test-chrome:
BROWSER=chrome $(MAKE) wasm-regtest-test

wasm-regtest-test-safari:
BROWSER=safari $(MAKE) wasm-regtest-test
Loading