Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…r-iroha#3068: match more exhaustively over events in DataEventFilter

This will produce a compile error in case a new top-level data event is introduced. It will not catch new Domain event types (like Account, Asset, AssetDefinition). Achieving that will require listing all (even non-hierarchical) event types, which is probably too much boilerplate

Signed-off-by: Nikita Strygin <[email protected]>

[refactor] hyperledger-iroha#1981, hyperledger-iroha#4195, hyperledger-iroha#3068: match more exhaustively over events in DataEventFilter

This will produce a compile error in case a new top-level data event is introduced. It will not catch new Domain event types (like Account, Asset, AssetDefinition). Achieving that will require listing all (even non-hierarchical) event types, which is probably too much boilerplate

Signed-off-by: Nikita Strygin <[email protected]>
  • Loading branch information
DCNick3 committed Mar 18, 2024
1 parent 8b2361a commit fb54f9d
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions data_model/src/events/data/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,23 +557,43 @@ impl EventFilter for DataEventFilter {
fn matches(&self, event: &DataEvent) -> bool {
use DataEventFilter::*;

match (self, event) {
(Any, _) => true,
(Peer(filter), DataEvent::Peer(event)) => filter.matches(event),
(Domain(filter), DataEvent::Domain(event)) => filter.matches(event),
(Account(filter), DataEvent::Domain(DomainEvent::Account(event))) => {
filter.matches(event)
}
match (event, self) {
(
Asset(filter),
DataEvent::Domain(DomainEvent::Account(AccountEvent::Asset(event))),
Asset(filter),
) => filter.matches(event),
(AssetDefinition(filter), DataEvent::Domain(DomainEvent::AssetDefinition(event))) => {
(DataEvent::Domain(DomainEvent::Account(event)), Account(filter)) => {
filter.matches(event)
}
(DataEvent::Domain(DomainEvent::AssetDefinition(event)), AssetDefinition(filter)) => {
filter.matches(event)
}
(Trigger(filter), DataEvent::Trigger(event)) => filter.matches(event),
(Role(filter), DataEvent::Role(event)) => filter.matches(event),
_ => false,
(DataEvent::Domain(event), Domain(filter)) => filter.matches(event),

(DataEvent::Peer(event), Peer(filter)) => filter.matches(event),
(DataEvent::Trigger(event), Trigger(filter)) => filter.matches(event),
(DataEvent::Role(event), Role(filter)) => filter.matches(event),

(
DataEvent::Peer(_)
| DataEvent::Domain(_)
| DataEvent::Trigger(_)
| DataEvent::Role(_)
| DataEvent::PermissionToken(_)
| DataEvent::Configuration(_)
| DataEvent::Executor(_),
Any,
) => true,
(
DataEvent::Peer(_)
| DataEvent::Domain(_)
| DataEvent::Trigger(_)
| DataEvent::Role(_)
| DataEvent::PermissionToken(_)
| DataEvent::Configuration(_)
| DataEvent::Executor(_),
_,
) => false,
}
}
}
Expand Down

0 comments on commit fb54f9d

Please sign in to comment.