]> Untitled Git - bdk/commitdiff
Make TxBuilder actually Clone
authorLLFourn <lloyd.fourn@gmail.com>
Mon, 8 Feb 2021 04:25:44 +0000 (15:25 +1100)
committerLLFourn <lloyd.fourn@gmail.com>
Fri, 26 Feb 2021 02:33:52 +0000 (13:33 +1100)
it derived Clone but in practice it was never clone because some of the
parameters were not Clone.

src/wallet/coin_selection.rs
src/wallet/tx_builder.rs

index c4666e00471f07edf1de41c0be45ab797fce8986..493a2bdf926255b18fe65957dbb533685c734347 100644 (file)
@@ -163,7 +163,7 @@ pub trait CoinSelectionAlgorithm<D: Database>: 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<D: Database> CoinSelectionAlgorithm<D> for LargestFirstCoinSelection {
index e92ec9af95e7a9cf905f878986d5f9b95a0256b7..f1fdf82a50f5d1c614f10a959e74c72e680c945f 100644 (file)
@@ -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<B, D>,
     // 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<D>, Ctx: TxBuilderContext>
     TxBuilder<'a, B, D, Cs, Ctx>