From df32c849bb3f6b28aa63b18ecb93d7062fe37b12 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Mon, 25 Jan 2021 15:13:45 -0500 Subject: [PATCH 1/4] Add a function to return the version of BDK at runtime --- CHANGELOG.md | 4 ++++ src/lib.rs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b1108de..be596822 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Misc +#### Added +- Added a function to get the version of BDK at runtime + ## [v0.3.0] - [v0.2.0] ### Descriptor diff --git a/src/lib.rs b/src/lib.rs index 1712296e..c3ac1ac0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -265,3 +265,8 @@ pub use wallet::address_validator; pub use wallet::signer; pub use wallet::tx_builder::TxBuilder; pub use wallet::Wallet; + +/// Get the version of BDK at runtime +pub fn version() -> &'static str { + env!("CARGO_PKG_VERSION", "unknown") +} From 2e0ca4fe05f03d94ebb0b173220de2749c9819bc Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Tue, 26 Jan 2021 09:34:14 -0500 Subject: [PATCH 2/4] Fix the crate version in `src/lib.rs` --- DEVELOPMENT_CYCLE.md | 21 +++++++++++---------- src/lib.rs | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/DEVELOPMENT_CYCLE.md b/DEVELOPMENT_CYCLE.md index 6d733fbd..16b859e9 100644 --- a/DEVELOPMENT_CYCLE.md +++ b/DEVELOPMENT_CYCLE.md @@ -32,13 +32,14 @@ Pre-`v1.0.0` our "major" releases only affect the "minor" semver value. Accordin - If it's a minor issue you can just fix it in the release branch, since it will be merged back to `master` eventually - For bigger issues you can fix them on `master` and then *cherry-pick* the commit to the release branch 6. Update the changelog with the new release version. -7. On release day, make a commit on the release branch to bump the version to `x.y.z`. The message should be "Bump version to x.y.z". -8. Add a tag to this commit. The tag name should be `vx.y.z` (for example `v0.5.0`), and the message "Release x.y.z". Make sure the tag is signed, for extra safety use the explicit `--sign` flag. -9. Push the new commits to the upstream release branch, wait for the CI to finish one last time. -10. Publish **all** the updated crates to crates.io. -11. Make a new commit to bump the version value to `x.y.(z+1)-dev`. The message should be "Bump version to x.y.(z+1)-dev". -12. Merge the release branch back into `master`. -13. Create the release on GitHub: go to "tags", click on the dots on the right and select "Create Release". Then set the title to `vx.y.z` and write down some brief release notes. -14. Make sure the new release shows up on crates.io and that the docs are built correctly on docs.rs. -15. Announce the release on Twitter, Discord and Telegram. -16. Celebrate :tada: +7. Update `src/lib.rs` with the new version (line ~59) +8. On release day, make a commit on the release branch to bump the version to `x.y.z`. The message should be "Bump version to x.y.z". +9. Add a tag to this commit. The tag name should be `vx.y.z` (for example `v0.5.0`), and the message "Release x.y.z". Make sure the tag is signed, for extra safety use the explicit `--sign` flag. +10. Push the new commits to the upstream release branch, wait for the CI to finish one last time. +11. Publish **all** the updated crates to crates.io. +12. Make a new commit to bump the version value to `x.y.(z+1)-dev`. The message should be "Bump version to x.y.(z+1)-dev". +13. Merge the release branch back into `master`. +14. Create the release on GitHub: go to "tags", click on the dots on the right and select "Create Release". Then set the title to `vx.y.z` and write down some brief release notes. +15. Make sure the new release shows up on crates.io and that the docs are built correctly on docs.rs. +16. Announce the release on Twitter, Discord and Telegram. +17. Celebrate :tada: diff --git a/src/lib.rs b/src/lib.rs index c3ac1ac0..d2737b47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,7 +56,7 @@ //! interact with the bitcoin P2P network. //! //! ```toml -//! bdk = "0.2.0" +//! bdk = "0.3.0" //! ``` //! //! ## Sync the balance of a descriptor From c431a601716a1ecd26fa852f106ab5de305a1362 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Mon, 25 Jan 2021 15:04:56 -0500 Subject: [PATCH 3/4] [signer] Add `Signer::id()` Closes #261 --- CHANGELOG.md | 4 ++++ src/wallet/mod.rs | 5 ++--- src/wallet/signer.rs | 36 ++++++++++++++++++++++++++++-------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be596822..6a525138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Added - Added a function to get the version of BDK at runtime +### Wallet +#### Changed +- Removed the explicit `id` argument from `Wallet::add_signer()` since that's now part of `Signer` itself + ## [v0.3.0] - [v0.2.0] ### Descriptor diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 1a82f16f..cabb9b42 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -57,7 +57,7 @@ pub(crate) mod utils; pub use utils::IsDust; use address_validator::AddressValidator; -use signer::{Signer, SignerId, SignerOrdering, SignersContainer}; +use signer::{Signer, SignerOrdering, SignersContainer}; use tx_builder::{BumpFee, CreateTx, FeePolicy, TxBuilder, TxBuilderContext}; use utils::{ check_nlocktime, check_nsequence_rbf, descriptor_to_pk_ctx, After, Older, SecpCtx, @@ -228,7 +228,6 @@ where pub fn add_signer( &mut self, keychain: KeychainKind, - id: SignerId, ordering: SignerOrdering, signer: Arc, ) { @@ -237,7 +236,7 @@ where KeychainKind::Internal => Arc::make_mut(&mut self.change_signers), }; - signers.add_external(id, ordering, signer); + signers.add_external(signer.id(&self.secp), ordering, signer); } /// Add an address validator diff --git a/src/wallet/signer.rs b/src/wallet/signer.rs index 650bdf26..8d0a70d8 100644 --- a/src/wallet/signer.rs +++ b/src/wallet/signer.rs @@ -33,7 +33,6 @@ //! # use bitcoin::secp256k1::{Secp256k1, All}; //! # use bitcoin::*; //! # use bitcoin::util::psbt; -//! # use bitcoin::util::bip32::Fingerprint; //! # use bdk::signer::*; //! # use bdk::database::*; //! # use bdk::*; @@ -46,6 +45,9 @@ //! # fn connect() -> Self { //! # CustomHSM //! # } +//! # fn get_id(&self) -> SignerId { +//! # SignerId::Dummy(0) +//! # } //! # } //! #[derive(Debug)] //! struct CustomSigner { @@ -71,6 +73,10 @@ //! Ok(()) //! } //! +//! fn id(&self, _secp: &Secp256k1) -> SignerId { +//! self.device.get_id() +//! } +//! //! fn sign_whole_tx(&self) -> bool { //! false //! } @@ -82,7 +88,6 @@ //! let mut wallet = Wallet::new_offline(descriptor, None, Network::Testnet, MemoryDatabase::default())?; //! wallet.add_signer( //! KeychainKind::External, -//! Fingerprint::from_str("e30f11b8").unwrap().into(), //! SignerOrdering(200), //! Arc::new(custom_signer) //! ); @@ -118,6 +123,8 @@ pub enum SignerId { PkHash(hash160::Hash), /// The fingerprint of a BIP32 extended key Fingerprint(Fingerprint), + /// Dummy identifier + Dummy(u64), } impl From for SignerId { @@ -184,6 +191,12 @@ pub trait Signer: fmt::Debug + Send + Sync { /// input individually fn sign_whole_tx(&self) -> bool; + /// Return the [`SignerId`] for this signer + /// + /// The [`SignerId`] can be used to lookup a signer in the [`Wallet`](crate::Wallet)'s signers map or to + /// compare two signers. + fn id(&self, secp: &SecpCtx) -> SignerId; + /// Return the secret key for the signer /// /// This is used internally to reconstruct the original descriptor that may contain secrets. @@ -234,6 +247,10 @@ impl Signer for DescriptorXKey { false } + fn id(&self, secp: &SecpCtx) -> SignerId { + SignerId::from(self.root_fingerprint(&secp)) + } + fn descriptor_secret_key(&self) -> Option { Some(DescriptorSecretKey::XPrv(self.clone())) } @@ -285,6 +302,10 @@ impl Signer for PrivateKey { false } + fn id(&self, secp: &SecpCtx) -> SignerId { + SignerId::from(self.public_key(secp).to_pubkeyhash()) + } + fn descriptor_secret_key(&self) -> Option { Some(DescriptorSecretKey::SinglePriv(DescriptorSinglePriv { key: *self, @@ -345,12 +366,7 @@ impl From for SignersContainer { for (_, secret) in keymap { match secret { DescriptorSecretKey::SinglePriv(private_key) => container.add_external( - SignerId::from( - private_key - .key - .public_key(&Secp256k1::signing_only()) - .to_pubkeyhash(), - ), + SignerId::from(private_key.key.public_key(&secp).to_pubkeyhash()), SignerOrdering::default(), Arc::new(private_key.key), ), @@ -650,6 +666,10 @@ mod signers_container_tests { Ok(()) } + fn id(&self, _secp: &SecpCtx) -> SignerId { + SignerId::Dummy(42) + } + fn sign_whole_tx(&self) -> bool { true } From eb96ac374ba070aeba877073815de7a1fd25b18f Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Wed, 27 Jan 2021 14:00:44 -0800 Subject: [PATCH 4/4] [ci] Update rust toolchains --- .github/workflows/cont_integration.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 1cc3b255..cf176d95 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -41,6 +41,8 @@ jobs: run: rustup set profile minimal - name: Add clippy run: rustup component add clippy + - name: Update toolchain + run: rustup update - name: Build run: cargo build --features ${{ matrix.features }} --no-default-features - name: Clippy @@ -66,6 +68,8 @@ jobs: run: rustup default nightly - name: Set profile run: rustup set profile minimal + - name: Update toolchain + run: rustup update - name: Test run: cargo test --features test-md-docs --no-default-features -- doctest::ReadmeDoctests @@ -96,6 +100,8 @@ jobs: run: $HOME/.cargo/bin/rustup default stable - name: Set profile run: $HOME/.cargo/bin/rustup set profile minimal + - name: Update toolchain + run: $HOME/.cargo/bin/rustup update - name: Start core run: ./ci/start-core.sh - name: Test @@ -129,6 +135,8 @@ jobs: run: rustup set profile minimal - name: Add target wasm32 run: rustup target add wasm32-unknown-unknown + - name: Update toolchain + run: rustup update - name: Check run: cargo check --target wasm32-unknown-unknown --features esplora --no-default-features @@ -144,5 +152,7 @@ jobs: run: rustup set profile minimal - name: Add clippy run: rustup component add rustfmt + - name: Update toolchain + run: rustup update - name: Check fmt run: cargo fmt --all -- --check