Skip to content

Commit

Permalink
Merge #117: Update bdk cli for wasm
Browse files Browse the repository at this point in the history
731dc74 Add wasm build in CI (Daniela Brozzoni)
b3469b4 Add wasm support (Daniela Brozzoni)

Pull request description:

  ### Description

  This PR adds a module to bdk-cli that exposes some structures/functions to WASM. You can see it in use here: bitcoindevkit/bitcoindevkit.org#118

  ### Notes to the reviewers

  Based on #116

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk-cli/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [ ] I've added docs for the new feature
  * [x] I've updated `CHANGELOG.md`

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [ ] I'm linking the issue being fixed by this PR

ACKs for top commit:
  rajarshimaitra:
    ACK 731dc74

Tree-SHA512: 69011ab6cb421f7e6f7dd000f9eaf5581428b2288358e31ffaec4425996951443fa2fc79f99db7de9c030d6a3fda57d25eee11564cf2fab9c745da593324f763
  • Loading branch information
rajarshimaitra committed Sep 26, 2022
2 parents 183e85e + 731dc74 commit b5f9177
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 22 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,41 @@ jobs:
- name: Test
run: cargo test --no-default-features --features repl,${{ matrix.features }}

wasm-build:
name: Build WASM
runs-on: ubuntu-latest
env:
CC: clang-10
CFLAGS: -I/usr/include
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Generate cache key
run: echo "Build WASM" | tee .cache_key
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
# Install a recent version of clang that supports wasm32
- run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - || exit 1
- run: sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-10 main" || exit 1
- run: sudo apt-get update || exit 1
- run: sudo apt-get install -y libclang-common-10-dev clang-10 libc6-dev-i386 || exit 1
- name: Set default toolchain
run: rustup default 1.56.1 # MSRV
- name: Set profile
run: rustup set profile minimal
- name: Add target wasm32
run: rustup target add wasm32-unknown-unknown
- name: Update toolchain
run: rustup update
- name: Build
run: cargo build --target wasm32-unknown-unknown --no-default-features --features esplora-reqwest,async-interface,compiler

fmt:
name: Rust fmt
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add new `bdk-cli node <command> [<args>]` to control the backend node deployed by `regtest-*` features.
- Add an integration testing framework in `src/tests/integration.rs`. This framework uses the `regtest-*` feature to run automated testing with bdk-cli.
- Add possible values for `network` option to improve help message, and fix typo in doc.
- Add a module `wasm` containing objects to use bdk-cli from web assembly

## [0.5.0]

Expand Down
55 changes: 38 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ fd-lock = { version = "=3.0.2", optional = true }
regex = { version = "1", optional = true }
bdk-reserves = { version = "0.22", optional = true }
electrsd = { version= "0.19", features = ["bitcoind_22_0"], optional = true}
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"], optional = true }

# Platform-specific dependencies
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "=0.2.79", features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4" }
js-sys = "=0.3.56"
wasm-logger = "0.2.0"
secp256k1 = { version = "0.22.0", default-features = false }
rand = { version = "^0.6", features = ["wasm-bindgen"] }
serde = { version = "^1.0", features = ["derive"] }
regex = { version = "1" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }

[features]
default = ["repl", "sqlite-db"]
Expand All @@ -45,7 +58,7 @@ electrum = ["bdk/electrum"]
compact_filters = ["bdk/compact_filters"]
esplora = []
esplora-ureq = ["esplora", "bdk/use-esplora-ureq"]
async-interface = ["bdk/async-interface", "tokio"]
async-interface = ["bdk/async-interface"]
esplora-reqwest = ["esplora", "bdk/use-esplora-reqwest", "bdk/reqwest-default-tls", "async-interface"]

# Use this to consensus verify transactions at sync time
Expand All @@ -68,4 +81,4 @@ regtest-bitcoin = ["regtest-node" , "rpc"]
regtest-electrum = ["regtest-node", "electrum", "electrsd/electrs_0_8_10"]
#TODO: Check why esplora in electrsd isn't working.
#regtest-esplora-ureq = ["regtest-node", "esplora-ureq", "electrsd/esplora_a33e97e1"]
#regtest-esplora-reqwest = ["regtest-node", "esplora-reqwest", "electrsd/esplora_a33e97e1"]
#regtest-esplora-reqwest = ["regtest-node", "esplora-reqwest", "electrsd/esplora_a33e97e1"]
2 changes: 1 addition & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ pub enum KeySubCommand {
}

/// Subcommands available in REPL mode.
#[cfg(feature = "repl")]
#[cfg(any(feature = "repl", target_arch = "wasm32"))]
#[derive(Debug, StructOpt, Clone, PartialEq)]
#[structopt(global_settings =&[AppSettings::NoBinaryName], rename_all = "lower")]
pub enum ReplSubCommand {
Expand Down
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ mod commands;
mod handlers;
mod nodes;
mod utils;
#[cfg(target_arch = "wasm32")]
mod wasm;

use bitcoin::Network;

use log::{debug, error, warn};
Expand All @@ -24,10 +27,11 @@ use bdk::{bitcoin, Error};
use bdk_macros::{maybe_async, maybe_await};
use structopt::StructOpt;

#[cfg(feature = "repl")]
#[cfg(any(feature = "repl", target_arch = "wasm32"))]
const REPL_LINE_SPLIT_REGEX: &str = r#""([^"]*)"|'([^']*)'|([\w\-]+)"#;

#[maybe_async]
#[cfg(not(target_arch = "wasm32"))]
#[cfg_attr(feature = "async-interface", tokio::main)]
fn main() {
env_logger::init();
Expand All @@ -50,3 +54,7 @@ fn main() {
},
}
}

// wasm32 requires a non-async main
#[cfg(target_arch = "wasm32")]
fn main() {}
Loading

0 comments on commit b5f9177

Please sign in to comment.