diff --git a/crates/rpc/rpc/src/txpool.rs b/crates/rpc/rpc/src/txpool.rs index e6f7d66b51e..202d69b575a 100644 --- a/crates/rpc/rpc/src/txpool.rs +++ b/crates/rpc/rpc/src/txpool.rs @@ -87,10 +87,9 @@ where inspect: &mut BTreeMap>, ) { let entry = inspect.entry(tx.sender()).or_default(); - let key = tx.nonce().to_string(); let tx = tx.to_recovered_transaction(); entry.insert( - key, + tx.nonce().to_string(), TxpoolInspectSummary { to: tx.to(), value: tx.value(), @@ -100,17 +99,18 @@ where ); } - let mut inspect = TxpoolInspect::default(); let AllPoolTransactions { pending, queued } = self.pool.all_transactions(); - for pending in pending { - insert(&pending.transaction, &mut inspect.pending); - } - for queued in queued { - insert(&queued.transaction, &mut inspect.queued); - } - - Ok(inspect) + Ok(TxpoolInspect { + pending: pending.iter().fold(Default::default(), |mut acc, tx| { + insert(&tx.transaction, &mut acc); + acc + }), + queued: queued.iter().fold(Default::default(), |mut acc, tx| { + insert(&tx.transaction, &mut acc); + acc + }), + }) } /// Retrieves the transactions contained within the txpool, returning pending as well as queued