From a56fd3bfe5ed2cbb3d8795a022d35ae136096d3d Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 26 Oct 2023 22:45:23 -0500 Subject: [PATCH] refactor!(bdk): require std feature for all impl of fmt::Display on Errors use anyhow::Error in more doc tests --- crates/bdk/src/descriptor/error.rs | 1 + crates/bdk/src/descriptor/policy.rs | 1 + crates/bdk/src/keys/mod.rs | 1 + crates/bdk/src/wallet/coin_selection.rs | 4 +++- crates/bdk/src/wallet/error.rs | 1 + crates/bdk/src/wallet/signer.rs | 1 + crates/bdk/src/wallet/tx_builder.rs | 11 +++++++---- 7 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/bdk/src/descriptor/error.rs b/crates/bdk/src/descriptor/error.rs index 3a704d2ead..90c16479fa 100644 --- a/crates/bdk/src/descriptor/error.rs +++ b/crates/bdk/src/descriptor/error.rs @@ -55,6 +55,7 @@ impl From for Error { } } +#[cfg(feature = "std")] impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/crates/bdk/src/descriptor/policy.rs b/crates/bdk/src/descriptor/policy.rs index 186af8b0bf..1a4840a0f0 100644 --- a/crates/bdk/src/descriptor/policy.rs +++ b/crates/bdk/src/descriptor/policy.rs @@ -518,6 +518,7 @@ pub enum PolicyError { IncompatibleConditions, } +#[cfg(feature = "std")] impl fmt::Display for PolicyError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/crates/bdk/src/keys/mod.rs b/crates/bdk/src/keys/mod.rs index 2050c7f8a0..6640d0fac1 100644 --- a/crates/bdk/src/keys/mod.rs +++ b/crates/bdk/src/keys/mod.rs @@ -944,6 +944,7 @@ impl From for KeyError { } } +#[cfg(feature = "std")] impl fmt::Display for KeyError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/crates/bdk/src/wallet/coin_selection.rs b/crates/bdk/src/wallet/coin_selection.rs index 2de7aec24c..afbf8ef882 100644 --- a/crates/bdk/src/wallet/coin_selection.rs +++ b/crates/bdk/src/wallet/coin_selection.rs @@ -31,6 +31,7 @@ //! # use bdk_chain::PersistBackend; //! # use bdk::*; //! # use bdk::wallet::coin_selection::decide_change; +//! # use anyhow::Error; //! # const TXIN_BASE_WEIGHT: usize = (32 + 4 + 4) * 4; //! #[derive(Debug)] //! struct AlwaysSpendEverything; @@ -96,7 +97,7 @@ //! //! // inspect, sign, broadcast, ... //! -//! # Ok::<(), CreateTxError<<() as PersistBackend>::WriteError>>(()) +//! # Ok::<(), anyhow::Error>(()) //! ``` use crate::types::FeeRate; @@ -139,6 +140,7 @@ pub enum Error { BnBTotalTriesExceeded, } +#[cfg(feature = "std")] impl fmt::Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { diff --git a/crates/bdk/src/wallet/error.rs b/crates/bdk/src/wallet/error.rs index 328ab291b6..c94e14b984 100644 --- a/crates/bdk/src/wallet/error.rs +++ b/crates/bdk/src/wallet/error.rs @@ -30,6 +30,7 @@ pub enum MiniscriptPsbtError { OutputUpdate(miniscript::psbt::OutputUpdateError), } +#[cfg(feature = "std")] impl fmt::Display for MiniscriptPsbtError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/crates/bdk/src/wallet/signer.rs b/crates/bdk/src/wallet/signer.rs index 970d0cafbf..b4ef1683b9 100644 --- a/crates/bdk/src/wallet/signer.rs +++ b/crates/bdk/src/wallet/signer.rs @@ -177,6 +177,7 @@ impl From for SignerError { } } +#[cfg(feature = "std")] impl fmt::Display for SignerError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/crates/bdk/src/wallet/tx_builder.rs b/crates/bdk/src/wallet/tx_builder.rs index 29d71c668b..f531f1a047 100644 --- a/crates/bdk/src/wallet/tx_builder.rs +++ b/crates/bdk/src/wallet/tx_builder.rs @@ -20,8 +20,9 @@ //! # use bdk::wallet::ChangeSet; //! # use bdk::wallet::error::CreateTxError; //! # use bdk::wallet::tx_builder::CreateTx; -//! # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked(); //! # use bdk_chain::PersistBackend; +//! # use anyhow::Error; +//! # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked(); //! # let mut wallet = doctest_wallet!(); //! // create a TxBuilder from a wallet //! let mut tx_builder = wallet.build_tx(); @@ -36,7 +37,7 @@ //! // Turn on RBF signaling //! .enable_rbf(); //! let psbt = tx_builder.finish()?; -//! # Ok::<(), CreateTxError<<() as PersistBackend>::WriteError>>(()) +//! # Ok::<(), anyhow::Error>(()) //! ``` use crate::collections::BTreeMap; @@ -87,6 +88,7 @@ impl TxBuilderContext for BumpFee {} /// # use bdk::wallet::ChangeSet; /// # use bdk::wallet::error::CreateTxError; /// # use bdk_chain::PersistBackend; +/// # use anyhow::Error; /// # let mut wallet = doctest_wallet!(); /// # let addr1 = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked(); /// # let addr2 = addr1.clone(); @@ -111,7 +113,7 @@ impl TxBuilderContext for BumpFee {} /// }; /// /// assert_eq!(psbt1.unsigned_tx.output[..2], psbt2.unsigned_tx.output[..2]); -/// # Ok::<(), CreateTxError<<() as PersistBackend>::WriteError>>(()) +/// # Ok::<(), anyhow::Error>(()) /// ``` /// /// At the moment [`coin_selection`] is an exception to the rule as it consumes `self`. @@ -655,6 +657,7 @@ impl<'a, D, Cs: CoinSelectionAlgorithm> TxBuilder<'a, D, Cs, CreateTx> { /// # use bdk::wallet::error::CreateTxError; /// # use bdk::wallet::tx_builder::CreateTx; /// # use bdk_chain::PersistBackend; + /// # use anyhow::Error; /// # let to_address = /// Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt") /// .unwrap() @@ -670,7 +673,7 @@ impl<'a, D, Cs: CoinSelectionAlgorithm> TxBuilder<'a, D, Cs, CreateTx> { /// .fee_rate(bdk::FeeRate::from_sat_per_vb(5.0)) /// .enable_rbf(); /// let psbt = tx_builder.finish()?; - /// # Ok::<(), CreateTxError<<() as PersistBackend>::WriteError>>(()) + /// # Ok::<(), anyhow::Error>(()) /// ``` /// /// [`allow_shrinking`]: Self::allow_shrinking