style: small refactor for txpool_inspect (#8348)

This commit is contained in:
Thomas Coratger
2024-05-22 21:01:27 +02:00
committed by GitHub
parent 7653e81d6f
commit dbc65ad694

View File

@ -87,10 +87,9 @@ where
inspect: &mut BTreeMap<Address, BTreeMap<String, TxpoolInspectSummary>>,
) {
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