From cf1815a1c05989d701710f8902909460d6bea51b Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Mon, 30 Aug 2021 10:27:24 -0700 Subject: [PATCH 1/9] Bump version to 0.11.0-rc.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index adb36231..a46966f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk" -version = "0.10.1-dev" +version = "0.11.0-rc1" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org" From 56a7bc9874185ea194e4a7b5bfb836808d2af63d Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sat, 4 Sep 2021 10:44:44 -0700 Subject: [PATCH 2/9] Update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8a556d1..90805b0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [v0.11.0] - [v0.10.0] + - Added `flush` method to the `Database` trait to explicitly flush to disk latest changes on the db. ## [v0.10.0] - [v0.9.0] @@ -362,7 +364,7 @@ final transaction is created by calling `finish` on the builder. - Use `MemoryDatabase` in the compiler example - Make the REPL return JSON -[unreleased]: https://github.com/bitcoindevkit/bdk/compare/v0.10.0...HEAD +[unreleased]: https://github.com/bitcoindevkit/bdk/compare/v0.11.0...HEAD [0.1.0-beta.1]: https://github.com/bitcoindevkit/bdk/compare/96c87ea5...0.1.0-beta.1 [v0.2.0]: https://github.com/bitcoindevkit/bdk/compare/0.1.0-beta.1...v0.2.0 [v0.3.0]: https://github.com/bitcoindevkit/bdk/compare/v0.2.0...v0.3.0 @@ -374,3 +376,4 @@ final transaction is created by calling `finish` on the builder. [v0.8.0]: https://github.com/bitcoindevkit/bdk/compare/v0.7.0...v0.8.0 [v0.9.0]: https://github.com/bitcoindevkit/bdk/compare/v0.8.0...v0.9.0 [v0.10.0]: https://github.com/bitcoindevkit/bdk/compare/v0.9.0...v0.10.0 +[v0.11.0]: https://github.com/bitcoindevkit/bdk/compare/v0.10.0...v0.11.0 \ No newline at end of file From 8c570ae7ebbe885f060451fe3f9435b80988a434 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sat, 4 Sep 2021 10:45:18 -0700 Subject: [PATCH 3/9] Update version in src/lib.rs --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index b340deb2..83bb0238 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,7 @@ //! interact with the bitcoin P2P network. //! //! ```toml -//! bdk = "0.10.0" +//! bdk = "0.11.0" //! ``` #![cfg_attr( feature = "electrum", From aa786fbb210d70eba7575e8e07982f3460fc67c0 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sat, 4 Sep 2021 10:46:03 -0700 Subject: [PATCH 4/9] Bump version to 0.11.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a46966f6..0249b4a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk" -version = "0.11.0-rc1" +version = "0.11.0" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org" From 5694b98304cc7aed4d9a73e30045fc5dec4759cc Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sat, 4 Sep 2021 11:43:24 -0700 Subject: [PATCH 5/9] Bump version to 0.11.1-dev --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0249b4a3..6c91eadd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk" -version = "0.11.0" +version = "0.11.1-dev" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org" From 6e12468b12a31275ad5ab772a2563132667ddbbd Mon Sep 17 00:00:00 2001 From: rajarshimaitra Date: Tue, 31 Aug 2021 14:23:24 +0530 Subject: [PATCH 6/9] Update Cargo.toml - Changed to local bdk-macro - Added back tokio - Update esplora-reqwest and test-esplora feature guards (cherry picked from commit 2459740f7218603447307b20bd3776dc14898a6e) --- Cargo.toml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6c91eadd..add6c397 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" license = "MIT OR Apache-2.0" [dependencies] -bdk-macros = "0.5" +bdk-macros = { path = "macros"} # TODO: Change this to version number after next release. log = "^0.4" miniscript = "^6.0" bitcoin = { version = "^0.27", features = ["use-serde", "base64"] } @@ -38,6 +38,10 @@ bitcoinconsensus = { version = "0.19.0-3", optional = true } # Needed by bdk_blockchain_tests macro core-rpc = { version = "0.14", optional = true } +# Platform-specific dependencies +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +tokio = { version = "1", features = ["rt"] } + [target.'cfg(target_arch = "wasm32")'.dependencies] async-trait = "0.1" js-sys = "0.3" @@ -70,7 +74,7 @@ rpc = ["core-rpc"] async-interface = ["async-trait"] electrum = ["electrum-client"] # MUST ALSO USE `--no-default-features`. -use-esplora-reqwest = ["async-interface", "esplora", "reqwest", "futures"] +use-esplora-reqwest = ["esplora", "reqwest", "futures"] use-esplora-ureq = ["esplora", "ureq"] # Typical configurations will not need to use `esplora` feature directly. esplora = [] @@ -80,7 +84,7 @@ esplora = [] test-blockchains = ["core-rpc", "electrum-client"] test-electrum = ["electrum", "electrsd/electrs_0_8_10", "test-blockchains"] test-rpc = ["rpc", "electrsd/electrs_0_8_10", "test-blockchains"] -test-esplora = ["esplora", "ureq", "electrsd/legacy", "electrsd/esplora_a33e97e1", "test-blockchains"] +test-esplora = ["electrsd/legacy", "electrsd/esplora_a33e97e1", "test-blockchains"] test-md-docs = ["electrum"] [dev-dependencies] From 7cb0116c44b56b750716c10acb6a665f79ebf956 Mon Sep 17 00:00:00 2001 From: rajarshimaitra Date: Tue, 31 Aug 2021 14:26:52 +0530 Subject: [PATCH 7/9] Fix reqwest blockchain test - add back await_or_block! to bdk-macros - use await_or_block! in reqwest tests (cherry picked from commit a41a0030dc212bc3685848c7aa5e9ce12c23720f) --- macros/src/lib.rs | 23 +++++++++++++++++++++++ src/blockchain/esplora/reqwest.rs | 20 ++++++++++---------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 3ba8741c..74eda5cf 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -121,3 +121,26 @@ pub fn maybe_await(expr: TokenStream) -> TokenStream { quoted.into() } + +/// Awaits if target_arch is "wasm32", uses `tokio::Runtime::block_on()` otherwise +/// +/// Requires the `tokio` crate as a dependecy with `rt-core` or `rt-threaded` to build on non-wasm32 platforms. +#[proc_macro] +pub fn await_or_block(expr: TokenStream) -> TokenStream { + let expr: proc_macro2::TokenStream = expr.into(); + let quoted = quote! { + { + #[cfg(all(not(target_arch = "wasm32"), not(feature = "async-interface")))] + { + tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(#expr) + } + + #[cfg(any(target_arch = "wasm32", feature = "async-interface"))] + { + #expr.await + } + } + }; + + quoted.into() +} diff --git a/src/blockchain/esplora/reqwest.rs b/src/blockchain/esplora/reqwest.rs index 056c3913..df3132da 100644 --- a/src/blockchain/esplora/reqwest.rs +++ b/src/blockchain/esplora/reqwest.rs @@ -106,19 +106,19 @@ impl Blockchain for EsploraBlockchain { } fn get_tx(&self, txid: &Txid) -> Result, Error> { - Ok(self.url_client._get_tx(txid).await?) + Ok(await_or_block!(self.url_client._get_tx(txid))?) } fn broadcast(&self, tx: &Transaction) -> Result<(), Error> { - Ok(self.url_client._broadcast(tx).await?) + Ok(await_or_block!(self.url_client._broadcast(tx))?) } fn get_height(&self) -> Result { - Ok(self.url_client._get_height().await?) + Ok(await_or_block!(self.url_client._get_height())?) } fn estimate_fee(&self, target: usize) -> Result { - let estimates = self.url_client._get_fee_estimates().await?; + let estimates = await_or_block!(self.url_client._get_fee_estimates())?; super::into_fee_rate(target, estimates) } } @@ -287,10 +287,10 @@ impl ElectrumLikeSync for UrlClient { for script in chunk { futs.push(self._script_get_history(script)); } - let partial_results: Vec> = futs.try_collect().await?; + let partial_results: Vec> = await_or_block!(futs.try_collect())?; results.extend(partial_results); } - Ok(stream::iter(results).collect().await) + Ok(await_or_block!(stream::iter(results).collect())) } fn els_batch_transaction_get<'s, I: IntoIterator>( @@ -303,10 +303,10 @@ impl ElectrumLikeSync for UrlClient { for txid in chunk { futs.push(self._get_tx_no_opt(txid)); } - let partial_results: Vec = futs.try_collect().await?; + let partial_results: Vec = await_or_block!(futs.try_collect())?; results.extend(partial_results); } - Ok(stream::iter(results).collect().await) + Ok(await_or_block!(stream::iter(results).collect())) } fn els_batch_block_header>( @@ -319,10 +319,10 @@ impl ElectrumLikeSync for UrlClient { for height in chunk { futs.push(self._get_header(height)); } - let partial_results: Vec = futs.try_collect().await?; + let partial_results: Vec = await_or_block!(futs.try_collect())?; results.extend(partial_results); } - Ok(stream::iter(results).collect().await) + Ok(await_or_block!(stream::iter(results).collect())) } } From 84b8579df506852d9c26572b1b3c64910ae2b425 Mon Sep 17 00:00:00 2001 From: rajarshimaitra Date: Tue, 31 Aug 2021 14:28:10 +0530 Subject: [PATCH 8/9] Test refactor - Fix esplora module level feature flag - Move esplora blockchain tests to module, to cover for both variants (cherry picked from commit 8d1d92e71e61f7c8094b3f3c8ed26b849cc8250b) --- src/blockchain/esplora/mod.rs | 38 ++++++++++--------------------- src/blockchain/esplora/reqwest.rs | 8 ------- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/blockchain/esplora/mod.rs b/src/blockchain/esplora/mod.rs index 917aa4ad..921a1e62 100644 --- a/src/blockchain/esplora/mod.rs +++ b/src/blockchain/esplora/mod.rs @@ -29,38 +29,16 @@ use bitcoin::{BlockHash, Txid}; use crate::error::Error; use crate::FeeRate; -#[cfg(all( - feature = "esplora", - feature = "reqwest", - any(feature = "async-interface", target_arch = "wasm32"), -))] +#[cfg(feature = "reqwest")] mod reqwest; -#[cfg(all( - feature = "esplora", - feature = "reqwest", - any(feature = "async-interface", target_arch = "wasm32"), -))] +#[cfg(feature = "reqwest")] pub use self::reqwest::*; -#[cfg(all( - feature = "esplora", - not(any( - feature = "async-interface", - feature = "reqwest", - target_arch = "wasm32" - )), -))] +#[cfg(feature = "ureq")] mod ureq; -#[cfg(all( - feature = "esplora", - not(any( - feature = "async-interface", - feature = "reqwest", - target_arch = "wasm32" - )), -))] +#[cfg(feature = "ureq")] pub use self::ureq::*; fn into_fee_rate(target: usize, estimates: HashMap) -> Result { @@ -141,3 +119,11 @@ impl_error!(io::Error, Io, EsploraError); impl_error!(std::num::ParseIntError, Parsing, EsploraError); impl_error!(consensus::encode::Error, BitcoinEncoding, EsploraError); impl_error!(bitcoin::hashes::hex::Error, Hex, EsploraError); + +#[cfg(test)] +#[cfg(feature = "test-esplora")] +crate::bdk_blockchain_tests! { + fn test_instance(test_client: &TestClient) -> EsploraBlockchain { + EsploraBlockchain::new(&format!("http://{}",test_client.electrsd.esplora_url.as_ref().unwrap()), 20) + } +} diff --git a/src/blockchain/esplora/reqwest.rs b/src/blockchain/esplora/reqwest.rs index df3132da..528fb7ad 100644 --- a/src/blockchain/esplora/reqwest.rs +++ b/src/blockchain/esplora/reqwest.rs @@ -350,11 +350,3 @@ impl ConfigurableBlockchain for EsploraBlockchain { Ok(blockchain) } } - -#[cfg(test)] -#[cfg(feature = "test-esplora")] -crate::bdk_blockchain_tests! { - fn test_instance(test_client: &TestClient) -> EsploraBlockchain { - EsploraBlockchain::new(&format!("http://{}",test_client.electrsd.esplora_url.as_ref().unwrap()), None, 20) - } -} From 9e508748a3be3925bec557e0bccae5a5ec2cf068 Mon Sep 17 00:00:00 2001 From: rajarshimaitra Date: Tue, 31 Aug 2021 14:34:19 +0530 Subject: [PATCH 9/9] Update CI blockchain tests (cherry picked from commit 10b53a56d71ca4a923464f9cd12b5738f280d84a) --- .github/workflows/cont_integration.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 92fe2990..d88b7851 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -78,15 +78,20 @@ jobs: run: cargo test --features test-md-docs --no-default-features -- doctest::ReadmeDoctests test-blockchains: - name: Test ${{ matrix.blockchain.name }} + name: Blockchain ${{ matrix.blockchain.features }} runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: blockchain: - name: electrum + features: test-electrum - name: rpc + features: test-rpc - name: esplora + features: test-esplora,use-esplora-reqwest + - name: esplora + features: test-esplora,use-esplora-ureq steps: - name: Checkout uses: actions/checkout@v2 @@ -104,8 +109,8 @@ jobs: toolchain: stable override: true - name: Test - run: cargo test --features test-${{ matrix.blockchain.name }} ${{ matrix.blockchain.name }}::bdk_blockchain_tests - + run: cargo test --no-default-features --features ${{ matrix.blockchain.features }} ${{ matrix.blockchain.name }}::bdk_blockchain_tests + check-wasm: name: Check WASM runs-on: ubuntu-16.04 @@ -139,7 +144,6 @@ jobs: - name: Check run: cargo check --target wasm32-unknown-unknown --features use-esplora-reqwest --no-default-features - fmt: name: Rust fmt runs-on: ubuntu-latest