From efedb55705ffff57dbba90d142635a09f393db45 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Wed, 24 Nov 2021 13:40:11 -0700 Subject: [PATCH] bank: factor tx log getter out to method on `TransactionLogCollector` --- runtime/src/bank.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 97e17252e2..28b0e3bbce 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -575,6 +575,21 @@ pub struct TransactionLogCollector { pub mentioned_address_map: HashMap>, } +impl TransactionLogCollector { + pub fn get_logs_for_address( + &self, + address: Option<&Pubkey>, + ) -> Option> { + match address { + None => Some(self.logs.clone()), + Some(address) => self + .mentioned_address_map + .get(address) + .map(|log_indices| log_indices.iter().map(|i| self.logs[*i].clone()).collect()), + } + } +} + pub trait NonceInfo { fn address(&self) -> &Pubkey; fn account(&self) -> &AccountSharedData; @@ -5302,20 +5317,10 @@ impl Bank { &self, address: Option<&Pubkey>, ) -> Option> { - let transaction_log_collector = self.transaction_log_collector.read().unwrap(); - - match address { - None => Some(transaction_log_collector.logs.clone()), - Some(address) => transaction_log_collector - .mentioned_address_map - .get(address) - .map(|log_indices| { - log_indices - .iter() - .map(|i| transaction_log_collector.logs[*i].clone()) - .collect() - }), - } + self.transaction_log_collector + .read() + .unwrap() + .get_logs_for_address(address) } pub fn get_all_accounts_modified_since_parent(&self) -> Vec<(Pubkey, AccountSharedData)> {