Skip to content

Commit 64b5916

Browse files
committed
f: remove a collect call in into_sorted_transactions
1 parent 1ef9442 commit 64b5916

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

src/tx_broadcaster.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,24 @@ const BCAST_PACKAGE_QUEUE_SIZE: usize = 50;
2424
/// call, along with each transaction's type. Queued until the background task classifies and
2525
/// broadcasts it. Built only via [`BroadcastPackage::new`] from such a call, so unrelated
2626
/// transactions can't be grouped into one package by accident.
27-
pub(crate) struct BroadcastPackage(Vec<(Transaction, Option<LdkTransactionType>)>);
27+
pub(crate) struct BroadcastPackage(Vec<Transaction>, Vec<Option<LdkTransactionType>>);
2828

2929
impl BroadcastPackage {
3030
/// Builds a package from the transactions of a single `broadcast_transactions` call.
3131
fn new(txs: &[(&Transaction, LdkTransactionType)]) -> Self {
32-
Self(txs.iter().map(|(tx, tx_type)| ((*tx).clone(), Some(tx_type.clone()))).collect())
32+
let (txs, types) =
33+
txs.iter().map(|(tx, tx_type)| ((*tx).clone(), Some(tx_type.clone()))).unzip();
34+
Self(txs, types)
3335
}
3436

3537
/// Builds a package for wallet-originated broadcasts that have no LDK classification.
3638
fn unclassified(tx: Transaction) -> Self {
37-
Self(vec![(tx, None)])
38-
}
39-
40-
/// The packaged transactions and their types, for classification.
41-
fn transactions(&self) -> &[(Transaction, Option<LdkTransactionType>)] {
42-
&self.0
39+
Self(vec![tx], vec![None])
4340
}
4441

4542
/// Consumes the package into its transactions, ready for the chain client.
4643
pub(crate) fn into_sorted_transactions(self) -> SortedTransactions {
47-
let txs = self.0.into_iter().map(|(tx, _)| tx).collect();
48-
SortedTransactions::sort_parents_child_package_topologically(txs)
44+
SortedTransactions::sort_parents_child_package_topologically(self.0)
4945
}
5046
}
5147

@@ -141,7 +137,7 @@ where
141137
) -> Result<BroadcastPackage, Error> {
142138
let wallet_opt = self.wallet.lock().expect("lock").as_ref().and_then(Weak::upgrade);
143139
if let Some(wallet) = wallet_opt {
144-
for (tx, tx_type) in package.transactions() {
140+
for (tx, tx_type) in package.0.iter().zip(package.1.iter()) {
145141
if let Some(tx_type) = tx_type {
146142
wallet.classify_broadcast(tx, tx_type).await?;
147143
}

0 commit comments

Comments
 (0)