Make TxBuilder actually Clone

it derived Clone but in practice it was never clone because some of the
parameters were not Clone.
This commit is contained in:
LLFourn 2021-02-08 15:25:44 +11:00
parent a7183f34ef
commit 9a918f285d
No known key found for this signature in database
GPG Key ID: A27093B54DA11F65
2 changed files with 13 additions and 2 deletions

View 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 /// 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. /// from the largest ones until the required amount is reached.
#[derive(Debug, Default)] #[derive(Debug, Default, Clone, Copy)]
pub struct LargestFirstCoinSelection; pub struct LargestFirstCoinSelection;
impl<D: Database> CoinSelectionAlgorithm<D> for LargestFirstCoinSelection { impl<D: Database> CoinSelectionAlgorithm<D> for LargestFirstCoinSelection {

View File

@ -129,7 +129,7 @@ impl TxBuilderContext for BumpFee {}
/// [`build_fee_bump`]: Wallet::build_fee_bump /// [`build_fee_bump`]: Wallet::build_fee_bump
/// [`finish`]: Self::finish /// [`finish`]: Self::finish
/// [`coin_selection`]: Self::coin_selection /// [`coin_selection`]: Self::coin_selection
#[derive(Clone, Debug)] #[derive(Debug)]
pub struct TxBuilder<'a, B, D, Cs, Ctx> { pub struct TxBuilder<'a, B, D, Cs, Ctx> {
pub(crate) wallet: &'a Wallet<B, D>, pub(crate) wallet: &'a Wallet<B, D>,
// params and coin_selection are Options not becasue they are optionally set (they are always // 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 // methods supported by both contexts, for any CoinSelectionAlgorithm
impl<'a, B, D: BatchDatabase, Cs: CoinSelectionAlgorithm<D>, Ctx: TxBuilderContext> impl<'a, B, D: BatchDatabase, Cs: CoinSelectionAlgorithm<D>, Ctx: TxBuilderContext>
TxBuilder<'a, B, D, Cs, Ctx> TxBuilder<'a, B, D, Cs, Ctx>