From 6fe3be02434a12505a4c36c898f45b53b5e67634 Mon Sep 17 00:00:00 2001 From: LLFourn Date: Fri, 22 Jan 2021 14:11:29 +1100 Subject: [PATCH] Derive Clone + Debug for TxBuilder And make Wallet Debug while I'm at it. --- examples/address_validator.rs | 1 + src/wallet/address_validator.rs | 4 +++- src/wallet/mod.rs | 1 + src/wallet/tx_builder.rs | 5 +++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/address_validator.rs b/examples/address_validator.rs index d00a239a..8730fb79 100644 --- a/examples/address_validator.rs +++ b/examples/address_validator.rs @@ -35,6 +35,7 @@ use bitcoin::hashes::hex::FromHex; use bitcoin::util::bip32::Fingerprint; use bitcoin::{Network, Script}; +#[derive(Debug)] struct DummyValidator; impl AddressValidator for DummyValidator { fn validate( diff --git a/src/wallet/address_validator.rs b/src/wallet/address_validator.rs index b84bee0c..4484efef 100644 --- a/src/wallet/address_validator.rs +++ b/src/wallet/address_validator.rs @@ -45,6 +45,7 @@ //! # use bdk::address_validator::*; //! # use bdk::database::*; //! # use bdk::*; +//! #[derive(Debug)] //! struct PrintAddressAndContinue; //! //! impl AddressValidator for PrintAddressAndContinue { @@ -111,7 +112,7 @@ impl std::error::Error for AddressValidatorError {} /// validator will be propagated up to the original caller that triggered the address generation. /// /// For a usage example see [this module](crate::address_validator)'s documentation. -pub trait AddressValidator: Send + Sync { +pub trait AddressValidator: Send + Sync + fmt::Debug { /// Validate or inspect an address fn validate( &self, @@ -128,6 +129,7 @@ mod test { use super::*; use crate::wallet::test::{get_funded_wallet, get_test_wpkh}; + #[derive(Debug)] struct TestValidator; impl AddressValidator for TestValidator { fn validate( diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 7921a189..3b223bba 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -87,6 +87,7 @@ const CACHE_ADDR_BATCH_SIZE: u32 = 100; /// A wallet can be either "online" if the [`blockchain`](crate::blockchain) type provided /// implements [`Blockchain`], or "offline" if it is the unit type `()`. Offline wallets only expose /// methods that don't need any interaction with the blockchain to work. +#[derive(Debug)] pub struct Wallet { descriptor: ExtendedDescriptor, change_descriptor: Option, diff --git a/src/wallet/tx_builder.rs b/src/wallet/tx_builder.rs index 92ea37c1..b8bc715d 100644 --- a/src/wallet/tx_builder.rs +++ b/src/wallet/tx_builder.rs @@ -127,6 +127,7 @@ impl TxBuilderContext for BumpFee {} /// [`build_fee_bump`]: Wallet::build_fee_bump /// [`finish`]: Self::finish /// [`coin_selection`]: Self::coin_selection +#[derive(Clone, Debug)] pub struct TxBuilder<'a, B, D, Cs, Ctx> { pub(crate) wallet: &'a Wallet, // params and coin_selection are Options not becasue they are optionally set (they are always @@ -139,7 +140,7 @@ pub struct TxBuilder<'a, B, D, Cs, Ctx> { /// The parameters for transaction creation sans coin selection algorithm. //TODO: TxParams should eventually be exposed publicly. -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone)] pub(crate) struct TxParams { pub(crate) recipients: Vec<(Script, u64)>, pub(crate) drain_wallet: bool, @@ -168,7 +169,7 @@ pub(crate) struct PreviousFee { pub rate: f32, } -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub(crate) enum FeePolicy { FeeRate(FeeRate), FeeAmount(u64),