Skip to content

Commit

Permalink
[refactor] hyperledger-iroha#1981, hyperledger-iroha#4195: Refactor t…
Browse files Browse the repository at this point in the history
…he event filters (even further)

- Remove the FilterOpt combinator, fuse it with DataEventFilter
- Rename DataEntityFilter to DataEventFilter
- Add `Any` suffix to nested events matchers
- Add doc-comments to event filters & their variants

Signed-off-by: Nikita Strygin <[email protected]>
  • Loading branch information
DCNick3 committed Feb 6, 2024
1 parent 1686240 commit f58fbe9
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 188 deletions.
4 changes: 2 additions & 2 deletions client/tests/integration/events/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn transaction_execution_should_produce_events(
let listener = client.clone();
let (init_sender, init_receiver) = mpsc::channel();
let (event_sender, event_receiver) = mpsc::channel();
let event_filter = DataEventFilter::AcceptAll.into();
let event_filter = FilterBox::Data(DataEventFilter::ByAny);
thread::spawn(move || -> Result<()> {
let event_iterator = listener.listen_for_events(event_filter)?;
init_sender.send(())?;
Expand Down Expand Up @@ -184,7 +184,7 @@ fn produce_multiple_events() -> Result<()> {
let listener = client.clone();
let (init_sender, init_receiver) = mpsc::channel();
let (event_sender, event_receiver) = mpsc::channel();
let event_filter = DataEventFilter::AcceptAll.into();
let event_filter = FilterBox::Data(DataEventFilter::ByAny);
thread::spawn(move || -> Result<()> {
let event_iterator = listener.listen_for_events(event_filter)?;
init_sender.send(())?;
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/events/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn trigger_completion_success_should_produce_event() -> Result<()> {
let (sender, receiver) = mpsc::channel();
let _handle = thread::spawn(move || -> Result<()> {
let mut event_it = thread_client.listen_for_events(
NotificationEventFilter::TriggerCompleted(TriggerCompletedEventFilter::new(
NotificationEventFilter::ByTriggerCompleted(TriggerCompletedEventFilter::new(
Some(trigger_id),
Some(TriggerCompletedOutcomeType::Success),
))
Expand Down Expand Up @@ -84,7 +84,7 @@ fn trigger_completion_failure_should_produce_event() -> Result<()> {
let (sender, receiver) = mpsc::channel();
let _handle = thread::spawn(move || -> Result<()> {
let mut event_it = thread_client.listen_for_events(
NotificationEventFilter::TriggerCompleted(TriggerCompletedEventFilter::new(
NotificationEventFilter::ByTriggerCompleted(TriggerCompletedEventFilter::new(
Some(trigger_id),
Some(TriggerCompletedOutcomeType::Failure),
))
Expand Down
14 changes: 6 additions & 8 deletions client/tests/integration/triggers/data_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ fn must_execute_both_triggers() -> Result<()> {
[instruction.clone()],
Repeats::Indefinitely,
account_id.clone(),
// FIXME: rewrite the filters using the builder DSL https://github.com/hyperledger/iroha/issues/3068
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByAccount(AccountEventFilter {
TriggeringFilterBox::Data(DataEventFilter::ByAccount(AccountEventFilter {
id_matcher: None,
event_matcher: Some(AccountEventMatcher::ByCreated),
}))),
})),
),
));
test_client.submit_blocking(register_trigger)?;
Expand All @@ -35,10 +34,10 @@ fn must_execute_both_triggers() -> Result<()> {
[instruction],
Repeats::Indefinitely,
account_id,
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByDomain(DomainEventFilter {
TriggeringFilterBox::Data(DataEventFilter::ByDomain(DomainEventFilter {
id_matcher: None,
event_matcher: Some(DomainEventMatcher::ByCreated),
}))),
})),
),
));
test_client.submit_blocking(register_trigger)?;
Expand Down Expand Up @@ -89,11 +88,10 @@ fn domain_scoped_trigger_must_be_executed_only_on_events_in_its_domain() -> Resu
[Mint::asset_quantity(1_u32, asset_id.clone())],
Repeats::Indefinitely,
account_id,
// FIXME: rewrite the filters using the builder DSL https://github.com/hyperledger/iroha/issues/3068
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByAccount(AccountEventFilter {
TriggeringFilterBox::Data(DataEventFilter::ByAccount(AccountEventFilter {
id_matcher: None,
event_matcher: Some(AccountEventMatcher::ByCreated),
}))),
})),
),
));
test_client.submit_blocking(register_trigger)?;
Expand Down
5 changes: 2 additions & 3 deletions client/tests/integration/triggers/event_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ fn test_mint_asset_when_new_asset_definition_created() -> Result<()> {
vec![instruction],
Repeats::Indefinitely,
account_id,
// FIXME: rewrite the filters using the builder DSL https://github.com/hyperledger/iroha/issues/3068
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByAssetDefinition(
TriggeringFilterBox::Data(DataEventFilter::ByAssetDefinition(
AssetDefinitionEventFilter {
id_matcher: None,
event_matcher: Some(AssetDefinitionEventMatcher::ByCreated),
},
))),
)),
),
));
test_client.submit(register_trigger)?;
Expand Down
4 changes: 2 additions & 2 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ mod events {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let filter = match self {
Args::Pipeline => FilterBox::Pipeline(PipelineEventFilter::new()),
Args::Data => FilterBox::Data(DataEventFilter::AcceptAll),
Args::Notification => FilterBox::Notification(NotificationEventFilter::AcceptAll),
Args::Data => FilterBox::Data(DataEventFilter::ByAny),
Args::Notification => FilterBox::Notification(NotificationEventFilter::ByAny),
};
listen(filter, context)
}
Expand Down
Binary file modified configs/peer/executor.wasm
Binary file not shown.
2 changes: 0 additions & 2 deletions data_model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ strum = { workspace = true, features = ["derive"] }
base64 = { workspace = true, features = ["alloc"] }
once_cell = { workspace = true, optional = true }

cfg-if = "1.0.0"

[dev-dependencies]
trybuild = { workspace = true }
criterion = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions data_model/src/events/data/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ macro_rules! data_event {
};
}

// NOTE: if adding/editing events here, make sure to update the corresponding event filter in [`super::filter`]

#[model]
pub mod model {
use super::*;
Expand Down
Loading

0 comments on commit f58fbe9

Please sign in to comment.