Skip to content

Commit

Permalink
Emit a different event for each log
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Feb 9, 2024
1 parent 3803728 commit 8c738b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/edr_napi/src/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl SubscriberCallback {
.and_then(|filter_id| event.set_named_property("filterId", filter_id))?;

let result = match ctx.value.result {
edr_provider::SubscriptionEventData::Logs(logs) => ctx.env.to_js_value(&logs),
edr_provider::SubscriptionEventData::Log(log) => ctx.env.to_js_value(&log),
edr_provider::SubscriptionEventData::NewHeads(block) => {
let block = eth::Block::<B256>::from(block);
ctx.env.to_js_value(&block)
Expand Down
10 changes: 6 additions & 4 deletions crates/edr_provider/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,12 @@ impl<LoggerErrorT: Debug> ProviderData<LoggerErrorT> {

let mut filtered_logs = filter_logs(new_logs, criteria);
if filter.is_subscription {
(self.subscriber_callback)(SubscriptionEvent {
filter_id: *filter_id,
result: SubscriptionEventData::Logs(filtered_logs.clone()),
});
for log in filtered_logs {
(self.subscriber_callback)(SubscriptionEvent {
filter_id: *filter_id,
result: SubscriptionEventData::Log(log.clone()),
});
}
} else {
logs.append(&mut filtered_logs);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_provider/src/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct SubscriptionEvent {
/// Subscription event data.
#[derive(Clone, Debug)]
pub enum SubscriptionEventData {
Logs(Vec<LogOutput>),
Log(LogOutput),
NewHeads(BlockAndTotalDifficulty<BlockchainError>),
NewPendingTransactions(B256),
}
Expand Down

0 comments on commit 8c738b6

Please sign in to comment.