From 9a918f285d5e830a522ac785d4e9ece84173502c Mon Sep 17 00:00:00 2001 From: LLFourn Date: Mon, 8 Feb 2021 15:25:44 +1100 Subject: [PATCH] Make TxBuilder actually Clone it derived Clone but in practice it was never clone because some of the parameters were not Clone. --- src/wallet/coin_selection.rs | 2 +- src/wallet/tx_builder.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index c4666e00..493a2bdf 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -163,7 +163,7 @@ pub trait CoinSelectionAlgorithm: std::fmt::Debug { /// /// This coin selection algorithm sorts the available UTXOs by value and then picks them starting /// from the largest ones until the required amount is reached. -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone, Copy)] pub struct LargestFirstCoinSelection; impl CoinSelectionAlgorithm for LargestFirstCoinSelection { diff --git a/src/wallet/tx_builder.rs b/src/wallet/tx_builder.rs index e92ec9af..f1fdf82a 100644 --- a/src/wallet/tx_builder.rs +++ b/src/wallet/tx_builder.rs @@ -129,7 +129,7 @@ impl TxBuilderContext for BumpFee {} /// [`build_fee_bump`]: Wallet::build_fee_bump /// [`finish`]: Self::finish /// [`coin_selection`]: Self::coin_selection -#[derive(Clone, Debug)] +#[derive(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 @@ -183,6 +183,17 @@ impl std::default::Default for FeePolicy { } } +impl<'a, Cs: Clone, Ctx, B, D> Clone for TxBuilder<'a, B, D, Cs, Ctx> { + fn clone(&self) -> Self { + TxBuilder { + wallet: self.wallet, + params: self.params.clone(), + coin_selection: self.coin_selection.clone(), + phantom: PhantomData, + } + } +} + // methods supported by both contexts, for any CoinSelectionAlgorithm impl<'a, B, D: BatchDatabase, Cs: CoinSelectionAlgorithm, Ctx: TxBuilderContext> TxBuilder<'a, B, D, Cs, Ctx>