Skip to content

Commit

Permalink
Add default cases to filter event emitters
Browse files Browse the repository at this point in the history
  • Loading branch information
wizeguyy committed Oct 23, 2024
1 parent 2dd3f20 commit af02843
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions quai/filters/filter_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ func (es *EventSystem) handleLogs(filters filterIndex, ev []*types.Log) {
}
matchedLogs := filterLogs(ev, f.logsCrit.FromBlock, f.logsCrit.ToBlock, addresses, f.logsCrit.Topics)
if len(matchedLogs) > 0 {
f.logs <- matchedLogs
select {
case f.logs <- matchedLogs:
es.backend.Logger().Error("Failed to deliver logs event to a subscriber")
default:
}
}
}
}
Expand All @@ -371,7 +375,11 @@ func (es *EventSystem) handlePendingLogs(filters filterIndex, ev []*types.Log) {
}
matchedLogs := filterLogs(ev, nil, f.logsCrit.ToBlock, addresses, f.logsCrit.Topics)
if len(matchedLogs) > 0 {
f.logs <- matchedLogs
select {
case f.logs <- matchedLogs:
default:
es.backend.Logger().Error("Failed to deliver pending logs event to a subscriber")
}
}
}
}
Expand All @@ -387,7 +395,11 @@ func (es *EventSystem) handleRemovedLogs(filters filterIndex, ev core.RemovedLog
}
matchedLogs := filterLogs(ev.Logs, f.logsCrit.FromBlock, f.logsCrit.ToBlock, addresses, f.logsCrit.Topics)
if len(matchedLogs) > 0 {
f.logs <- matchedLogs
select {
case f.logs <- matchedLogs:
default:
es.backend.Logger().Error("Failed to deliver removed logs event to a subscriber")
}
}
}
}
Expand All @@ -398,19 +410,31 @@ func (es *EventSystem) handleTxsEvent(filters filterIndex, ev core.NewTxsEvent)
hashes = append(hashes, tx.Hash())
}
for _, f := range filters[PendingTransactionsSubscription] {
f.hashes <- hashes
select {
case f.hashes <- hashes:
default:
es.backend.Logger().Error("Failed to deliver txs event to a subscriber")
}
}
}

func (es *EventSystem) handleChainEvent(filters filterIndex, ev core.ChainEvent) {
for _, f := range filters[BlocksSubscription] {
f.headers <- ev.Block
select {
case f.headers <- ev.Block:
default:
es.backend.Logger().Error("Failed to deliver chain event to a subscriber")
}
}
}

func (es *EventSystem) handleUnlocksEvent(filters filterIndex, ev core.UnlocksEvent) {
for _, f := range filters[UnlocksSubscription] {
f.unlocks <- ev
select {
case f.unlocks <- ev:
default:
es.backend.Logger().Error("Failed to deliver unlocks event to a subscriber")
}
}
}

Expand Down

0 comments on commit af02843

Please sign in to comment.