From b87c7c5dc7c2c2c37495298b62d84fa0bfaad14f Mon Sep 17 00:00:00 2001 From: LLFourn Date: Wed, 21 Oct 2020 15:53:55 +1100 Subject: [PATCH] [wallet] Make 'unspendable' into a HashSet to avoid awkwardly later on. --- src/wallet/mod.rs | 9 ++------- src/wallet/tx_builder.rs | 7 ++++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index ba4100e3..ac350d45 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -969,14 +969,9 @@ where &self, change_policy: tx_builder::ChangeSpendPolicy, utxo: &Option>, - unspendable: &Option>, + unspendable: &HashSet, send_all: bool, ) -> Result<(Vec<(UTXO, usize)>, bool), Error> { - let unspendable_set = match unspendable { - None => HashSet::new(), - Some(vec) => vec.iter().collect(), - }; - let external_weight = self .get_descriptor_for_script_type(ScriptType::External) .0 @@ -1016,7 +1011,7 @@ where // otherwise limit ourselves to the spendable utxos for the selected policy, and the `send_all` setting None => { let utxos = self.list_unspent()?.into_iter().filter(|u| { - change_policy.is_satisfied_by(u) && !unspendable_set.contains(&u.outpoint) + change_policy.is_satisfied_by(u) && !unspendable.contains(&u.outpoint) }); Ok((utxos.map(add_weight).collect(), send_all)) diff --git a/src/wallet/tx_builder.rs b/src/wallet/tx_builder.rs index 65171c3e..f72bf48d 100644 --- a/src/wallet/tx_builder.rs +++ b/src/wallet/tx_builder.rs @@ -42,6 +42,7 @@ //! ``` use std::collections::BTreeMap; +use std::collections::HashSet; use std::default::Default; use std::marker::PhantomData; @@ -63,7 +64,7 @@ pub struct TxBuilder> { pub(crate) fee_policy: Option, pub(crate) policy_path: Option>>, pub(crate) utxos: Option>, - pub(crate) unspendable: Option>, + pub(crate) unspendable: HashSet, pub(crate) sighash: Option, pub(crate) ordering: TxOrdering, pub(crate) locktime: Option, @@ -197,7 +198,7 @@ impl> TxBuilder { /// [`TxBuilder::add_utxo`] have priority over these. See the docs of the two linked methods /// for more details. pub fn unspendable(mut self, unspendable: Vec) -> Self { - self.unspendable = Some(unspendable); + self.unspendable = unspendable.into_iter().collect(); self } @@ -207,7 +208,7 @@ impl> TxBuilder { /// [`TxBuilder::add_utxo`] have priority over this. See the docs of the two linked methods /// for more details. pub fn add_unspendable(mut self, unspendable: OutPoint) -> Self { - self.unspendable.get_or_insert(vec![]).push(unspendable); + self.unspendable.insert(unspendable); self }