mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 15:04:22 +00:00
pubsub: use concrete queries instead of an interface (#7686)
Remove the pubsub.Query interface and instead use the concrete query type. Nothing uses any other implementation but pubsub/query. * query: remove the error from the Matches method * Update all usage.
This commit is contained in:
@@ -67,13 +67,18 @@ func Compile(ast syntax.Query) (*Query, error) {
|
||||
return &Query{ast: ast, conds: conds}, nil
|
||||
}
|
||||
|
||||
// Matches satisfies part of the pubsub.Query interface. This implementation
|
||||
// never reports an error. A nil *Query matches all events.
|
||||
func (q *Query) Matches(events []types.Event) (bool, error) {
|
||||
// Matches reports whether q matches the given events. If q == nil, the query
|
||||
// matches any non-empty collection of events.
|
||||
func (q *Query) Matches(events []types.Event) bool {
|
||||
if q == nil {
|
||||
return true, nil
|
||||
return true
|
||||
}
|
||||
return q.matchesEvents(events), nil
|
||||
for _, cond := range q.conds {
|
||||
if !cond.matchesAny(events) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return len(events) != 0
|
||||
}
|
||||
|
||||
// String matches part of the pubsub.Query interface.
|
||||
@@ -92,16 +97,6 @@ func (q *Query) Syntax() syntax.Query {
|
||||
return q.ast
|
||||
}
|
||||
|
||||
// matchesEvents reports whether all the conditions match the given events.
|
||||
func (q *Query) matchesEvents(events []types.Event) bool {
|
||||
for _, cond := range q.conds {
|
||||
if !cond.matchesAny(events) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return len(events) != 0
|
||||
}
|
||||
|
||||
// A condition is a compiled match condition. A condition matches an event if
|
||||
// the event has the designated type, contains an attribute with the given
|
||||
// name, and the match function returns true for the attribute value.
|
||||
|
||||
Reference in New Issue
Block a user