Skip to content

Commit 0cd8c5f

Browse files
authored
refactor: document and rename topics method (#1735)
1 parent 39478fa commit 0cd8c5f

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/eth/primitives/execution.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,18 @@ impl EvmExecution {
131131
// compare logs pairs
132132
for (log_index, (execution_log, receipt_log)) in self.logs.iter().zip(&receipt.logs).enumerate() {
133133
// compare log topics length
134-
if execution_log.topics().len() != receipt_log.topics.len() {
134+
if execution_log.topics_non_empty().len() != receipt_log.topics.len() {
135135
return log_and_err!(format!(
136136
"log topics length mismatch | hash={} log_index={} execution={} receipt={}",
137137
receipt.hash(),
138138
log_index,
139-
execution_log.topics().len(),
139+
execution_log.topics_non_empty().len(),
140140
receipt_log.topics.len(),
141141
));
142142
}
143143

144144
// compare log topics content
145-
for (topic_index, (execution_log_topic, receipt_log_topic)) in execution_log.topics().iter().zip(&receipt_log.topics).enumerate() {
145+
for (topic_index, (execution_log_topic, receipt_log_topic)) in execution_log.topics_non_empty().iter().zip(&receipt_log.topics).enumerate() {
146146
if execution_log_topic.as_ref() != receipt_log_topic.as_ref() {
147147
return log_and_err!(format!(
148148
"log topic content mismatch | hash={} log_index={} topic_index={} execution={} receipt={:#x}",

src/eth/primitives/log.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ pub struct Log {
2323
}
2424

2525
impl Log {
26-
pub fn topics(&self) -> Vec<LogTopic> {
27-
self.topics_array().into_iter().flatten().collect()
26+
/// Returns all topics in the log.
27+
pub fn topics(&self) -> [Option<LogTopic>; 4] {
28+
[self.topic0, self.topic1, self.topic2, self.topic3]
2829
}
2930

30-
pub fn topics_array(&self) -> [Option<LogTopic>; 4] {
31-
[self.topic0, self.topic1, self.topic2, self.topic3]
31+
/// Returns all non-empty topics in the log.
32+
pub fn topics_non_empty(&self) -> Vec<LogTopic> {
33+
self.topics().into_iter().flatten().collect()
3234
}
3335
}
3436

src/eth/primitives/log_filter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl LogFilter {
3737
}
3838

3939
let filter_topics = &self.original_input.topics;
40-
let log_topics = log.log.topics_array();
40+
let log_topics = log.log.topics();
4141

4242
// (https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getlogs)
4343
// Matching rules for filtering topics in `eth_getLogs`:

src/eth/primitives/log_mined.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ impl LogMined {
4040
&self.log.address
4141
}
4242

43-
/// Returns the topics emitted in the log.
44-
pub fn topics(&self) -> Vec<LogTopic> {
45-
self.log.topics()
43+
/// Returns all non-empty topics in the log.
44+
pub fn topics_non_empty(&self) -> Vec<LogTopic> {
45+
self.log.topics_non_empty()
4646
}
4747

4848
/// Serializes itself to JSON-RPC log format.
@@ -77,7 +77,7 @@ impl From<LogMined> for EthersLog {
7777
Self {
7878
// log
7979
address: value.log.address.into(),
80-
topics: value.topics().into_iter().map_into().collect_vec(),
80+
topics: value.topics_non_empty().into_iter().map_into().collect_vec(),
8181
data: value.log.data.into(),
8282
log_index: Some(value.log_index.into()),
8383
removed: Some(false),

src/eth/primitives/logs_bloom.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl LogsBloom {
2121

2222
pub fn accrue_log(&mut self, log: &Log) {
2323
self.accrue(ethereum_types::BloomInput::Raw(log.address.as_ref()));
24-
for topic in log.topics() {
24+
for topic in log.topics_non_empty() {
2525
self.accrue(ethereum_types::BloomInput::Raw(topic.as_ref()));
2626
}
2727
}

0 commit comments

Comments
 (0)