Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
using case insensitive matching for checking whether pubsub client ha…
Browse files Browse the repository at this point in the history
…s subscribed to a certain topic of interest or not
  • Loading branch information
itzmeanjan committed Jan 31, 2021
1 parent b2193c3 commit da0c3df
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/pubsub/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func (s *SubscriptionRequest) DoesMatchWithPublishedEventData(event *data.Event)
// --- Matching specific topic signature provided by client
// application with received event data, published by
// redis pub-sub
matchTopicXInEvent := func(topic string, x int) bool {
matchTopicXInEvent := func(topic string, x uint8) bool {
// Not all topics will have 4 elements in topics array
//
// For those cases, if topic signature for that index is {"", "*"}
// provided by consumer, then we're safely going to say it's a match
if !(x < len(event.Topics)) {
if !(int(x) < len(event.Topics)) {
return topic == "" || topic == "*"
}

Expand All @@ -114,7 +114,7 @@ func (s *SubscriptionRequest) DoesMatchWithPublishedEventData(event *data.Event)
status = true
// match with specific `topic` signature
default:
status = topic == event.Topics[x]
status = CheckSimilarity(topic, event.Topics[x])
}

return status
Expand All @@ -135,7 +135,7 @@ func (s *SubscriptionRequest) DoesMatchWithPublishedEventData(event *data.Event)
status = matchTopicXInEvent(filters[1], 0) && matchTopicXInEvent(filters[2], 1) && matchTopicXInEvent(filters[3], 2) && matchTopicXInEvent(filters[4], 3)
// match with provided `contract` address
default:
if filters[0] == event.Origin {
if CheckSimilarity(filters[0], event.Origin) {
status = matchTopicXInEvent(filters[1], 0) && matchTopicXInEvent(filters[2], 1) && matchTopicXInEvent(filters[3], 2) && matchTopicXInEvent(filters[4], 3)
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func (s *SubscriptionRequest) DoesMatchWithPublishedTransactionData(tx *data.Tra
status = true
// match with specific `to` address
default:
status = to == tx.To
status = CheckSimilarity(to, tx.To)
}

return status
Expand All @@ -211,7 +211,7 @@ func (s *SubscriptionRequest) DoesMatchWithPublishedTransactionData(tx *data.Tra
status = matchToFieldInTx(filters[1])
// match with provided `from` address
default:
if filters[0] == tx.From {
if CheckSimilarity(filters[0], tx.From) {
status = matchToFieldInTx(filters[1])
}
}
Expand Down

0 comments on commit da0c3df

Please sign in to comment.