Skip to content

Commit

Permalink
Add wasm support
Browse files Browse the repository at this point in the history
Add a module "wasm" with utilities to be used in the bdk playground:
- A WasmWallet structure, to create a wallet and run commands
- A compile function, to compile policies into descriptors
  • Loading branch information
danielabrozzoni committed Sep 14, 2022
1 parent a4f58dc commit 2ca6a91
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Change rpc `--skip-blocks` option to `--start-time` which specifies time initial sync will start scanning from.
- 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 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 @@ -537,7 +537,7 @@ pub enum KeySubCommand {
},
}

#[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 2ca6a91

Please sign in to comment.