From eaf54e724083a397db8477254e54866810914b40 Mon Sep 17 00:00:00 2001 From: Nikita Strygin Date: Wed, 13 Mar 2024 13:11:34 +0300 Subject: [PATCH] [refactor] #1981, #4195, #3068: Remove NotificationEvent Instead of it, expose TriggerCompletedEvent as a top-level event, same as ExecuteTriggerEvent Signed-off-by: Nikita Strygin --- .../tests/integration/events/notification.rs | 22 +++---- client_cli/src/main.rs | 9 ++- core/src/wsv.rs | 5 +- data_model/src/events/mod.rs | 24 +++---- .../{notification.rs => trigger_completed.rs} | 63 +------------------ docs/source/references/schema.json | 30 ++------- schema/gen/src/lib.rs | 2 - 7 files changed, 37 insertions(+), 118 deletions(-) rename data_model/src/events/{notification.rs => trigger_completed.rs} (85%) diff --git a/client/tests/integration/events/notification.rs b/client/tests/integration/events/notification.rs index 125eec3b8f9..e7738e04aaa 100644 --- a/client/tests/integration/events/notification.rs +++ b/client/tests/integration/events/notification.rs @@ -35,12 +35,11 @@ fn trigger_completion_success_should_produce_event() -> Result<()> { let thread_client = test_client.clone(); let (sender, receiver) = mpsc::channel(); let _handle = thread::spawn(move || -> Result<()> { - let mut event_it = - thread_client.listen_for_events(NotificationEventFilter::ByTriggerCompleted( - TriggerCompletedEventFilter::new() - .for_trigger(trigger_id) - .for_outcome(TriggerCompletedOutcomeType::Success), - ))?; + let mut event_it = thread_client.listen_for_events( + TriggerCompletedEventFilter::new() + .for_trigger(trigger_id) + .for_outcome(TriggerCompletedOutcomeType::Success), + )?; if event_it.next().is_some() { sender.send(())?; return Ok(()); @@ -84,12 +83,11 @@ fn trigger_completion_failure_should_produce_event() -> Result<()> { let thread_client = test_client.clone(); let (sender, receiver) = mpsc::channel(); let _handle = thread::spawn(move || -> Result<()> { - let mut event_it = - thread_client.listen_for_events(NotificationEventFilter::ByTriggerCompleted( - TriggerCompletedEventFilter::new() - .for_trigger(trigger_id) - .for_outcome(TriggerCompletedOutcomeType::Failure), - ))?; + let mut event_it = thread_client.listen_for_events( + TriggerCompletedEventFilter::new() + .for_trigger(trigger_id) + .for_outcome(TriggerCompletedOutcomeType::Failure), + )?; if event_it.next().is_some() { sender.send(())?; return Ok(()); diff --git a/client_cli/src/main.rs b/client_cli/src/main.rs index 1d06e1c8e5b..807d504a280 100644 --- a/client_cli/src/main.rs +++ b/client_cli/src/main.rs @@ -258,8 +258,10 @@ mod events { Pipeline, /// Gets data events Data, - /// Get notification events - Notification, + /// Get execute trigger events + ExecuteTrigger, + /// Get trigger completed events + TriggerCompleted, } impl RunArgs for Args { @@ -267,7 +269,8 @@ mod events { match self { Args::Pipeline => listen(PipelineEventFilter::new(), context), Args::Data => listen(DataEventFilter::Any, context), - Args::Notification => listen(NotificationEventFilter::ByAny, context), + Args::ExecuteTrigger => listen(ExecuteTriggerEventFilter::new(), context), + Args::TriggerCompleted => listen(TriggerCompletedEventFilter::new(), context), } } } diff --git a/core/src/wsv.rs b/core/src/wsv.rs index c736af16b22..fbe6730f77f 100644 --- a/core/src/wsv.rs +++ b/core/src/wsv.rs @@ -12,7 +12,7 @@ use iroha_crypto::HashOf; use iroha_data_model::{ account::AccountId, block::SignedBlock, - events::notification::{TriggerCompletedEvent, TriggerCompletedOutcome}, + events::trigger_completed::{TriggerCompletedEvent, TriggerCompletedOutcome}, isi::error::{InstructionExecutionError as Error, MathError}, parameter::{Parameter, ParameterValueBox}, permission::PermissionTokenSchema, @@ -567,8 +567,7 @@ impl WorldStateView { event } }; - self.events_buffer - .push(NotificationEvent::from(event).into()); + self.events_buffer.push(event.into()); } } diff --git a/data_model/src/events/mod.rs b/data_model/src/events/mod.rs index 8c3517ecdcc..daa9e544e26 100644 --- a/data_model/src/events/mod.rs +++ b/data_model/src/events/mod.rs @@ -13,9 +13,9 @@ pub use self::model::*; pub mod data; pub mod execute_trigger; -pub mod notification; pub mod pipeline; pub mod time; +pub mod trigger_completed; #[model] pub mod model { @@ -46,8 +46,8 @@ pub mod model { Time(time::TimeEvent), /// Trigger execution event. ExecuteTrigger(execute_trigger::ExecuteTriggerEvent), - /// Notification event. - Notification(notification::NotificationEvent), + /// Trigger completion event. + TriggerCompleted(trigger_completed::TriggerCompletedEvent), } /// Event type which could invoke trigger execution. @@ -92,8 +92,8 @@ pub mod model { Time(time::TimeEventFilter), /// Listen to trigger execution event with filter. ExecuteTrigger(execute_trigger::ExecuteTriggerEventFilter), - /// Listen to notifications event with filter. - Notification(notification::NotificationEventFilter), + /// Listen to trigger completion event with filter. + TriggerCompleted(trigger_completed::TriggerCompletedEventFilter), } /// Event filter which could be attached to trigger. @@ -165,19 +165,21 @@ impl EventFilter for EventFilterBox { (Event::Data(event), Self::Data(filter)) => filter.matches(event), (Event::Time(event), Self::Time(filter)) => filter.matches(event), (Event::ExecuteTrigger(event), Self::ExecuteTrigger(filter)) => filter.matches(event), - (Event::Notification(event), Self::Notification(filter)) => filter.matches(event), + (Event::TriggerCompleted(event), Self::TriggerCompleted(filter)) => { + filter.matches(event) + } // Fail to compile in case when new variant to event or filter is added ( Event::Pipeline(_) | Event::Data(_) | Event::Time(_) | Event::ExecuteTrigger(_) - | Event::Notification(_), + | Event::TriggerCompleted(_), Self::Pipeline(_) | Self::Data(_) | Self::Time(_) | Self::ExecuteTrigger(_) - | Self::Notification(_), + | Self::TriggerCompleted(_), ) => false, } } @@ -200,7 +202,7 @@ impl EventFilter for TriggeringEventFilterBox { | Event::Data(_) | Event::Time(_) | Event::ExecuteTrigger(_) - | Event::Notification(_), + | Event::TriggerCompleted(_), Self::Pipeline(_) | Self::Data(_) | Self::Time(_) | Self::ExecuteTrigger(_), ) => false, } @@ -249,8 +251,8 @@ pub mod prelude { #[cfg(feature = "transparent_api")] pub use super::EventFilter; pub use super::{ - data::prelude::*, execute_trigger::prelude::*, notification::prelude::*, - pipeline::prelude::*, time::prelude::*, Event, EventFilterBox, TriggeringEventFilterBox, + data::prelude::*, execute_trigger::prelude::*, pipeline::prelude::*, time::prelude::*, + trigger_completed::prelude::*, Event, EventFilterBox, TriggeringEventFilterBox, TriggeringEventType, }; } diff --git a/data_model/src/events/notification.rs b/data_model/src/events/trigger_completed.rs similarity index 85% rename from data_model/src/events/notification.rs rename to data_model/src/events/trigger_completed.rs index 5ee09c449d1..9d0d43d195c 100644 --- a/data_model/src/events/notification.rs +++ b/data_model/src/events/trigger_completed.rs @@ -19,27 +19,6 @@ use crate::trigger::TriggerId; pub mod model { use super::*; - /// Notification event for events that arise during block application process like trigger execution for example - #[derive( - Debug, - Clone, - PartialEq, - Eq, - PartialOrd, - Ord, - FromVariant, - Decode, - Encode, - Deserialize, - Serialize, - IntoSchema, - )] - #[ffi_type] - #[non_exhaustive] - pub enum NotificationEvent { - TriggerCompleted(TriggerCompletedEvent), - } - /// Event that notifies that a trigger was executed #[derive( Debug, @@ -95,28 +74,6 @@ pub mod model { Failure(String), } - /// Filter for [`NotificationEvent`] - #[derive( - Debug, - Clone, - FromVariant, - PartialEq, - Eq, - PartialOrd, - Ord, - Decode, - Encode, - Deserialize, - Serialize, - IntoSchema, - )] - #[ffi_type] - #[non_exhaustive] - pub enum NotificationEventFilter { - ByAny, - ByTriggerCompleted(TriggerCompletedEventFilter), - } - /// Filter [`TriggerCompletedEvent`] by /// 1. if `triger_id` is some filter based on trigger id /// 2. if `outcome_type` is some filter based on execution outcome (success/failure) @@ -144,22 +101,6 @@ pub mod model { } } -#[cfg(feature = "transparent_api")] -impl super::EventFilter for NotificationEventFilter { - type Event = NotificationEvent; - - /// Check if `self` accepts the `event`. - #[inline] - fn matches(&self, event: &Self::Event) -> bool { - match (self, event) { - (Self::ByAny, _) => true, - (Self::ByTriggerCompleted(filter), NotificationEvent::TriggerCompleted(event)) => { - filter.matches(event) - } - } - } -} - impl TriggerCompletedEventFilter { /// Creates a new [`TriggerCompletedEventFilter`] accepting all [`TriggerCompletedEvent`]s #[must_use] @@ -219,8 +160,8 @@ impl super::EventFilter for TriggerCompletedEventFilter { /// Exports common structs and enums from this module. pub mod prelude { pub use super::{ - NotificationEvent, NotificationEventFilter, TriggerCompletedEvent, - TriggerCompletedEventFilter, TriggerCompletedOutcome, TriggerCompletedOutcomeType, + TriggerCompletedEvent, TriggerCompletedEventFilter, TriggerCompletedOutcome, + TriggerCompletedOutcomeType, }; } diff --git a/docs/source/references/schema.json b/docs/source/references/schema.json index 93c774cd19d..04e5ed6c954 100644 --- a/docs/source/references/schema.json +++ b/docs/source/references/schema.json @@ -880,9 +880,9 @@ "type": "ExecuteTriggerEvent" }, { - "tag": "Notification", + "tag": "TriggerCompleted", "discriminant": 4, - "type": "NotificationEvent" + "type": "TriggerCompletedEvent" } ] }, @@ -909,9 +909,9 @@ "type": "ExecuteTriggerEventFilter" }, { - "tag": "Notification", + "tag": "TriggerCompleted", "discriminant": 4, - "type": "NotificationEventFilter" + "type": "TriggerCompletedEventFilter" } ] }, @@ -2214,28 +2214,6 @@ "NonTrivial>": "Vec>", "NonZero": "u32", "NonZero": "u64", - "NotificationEvent": { - "Enum": [ - { - "tag": "TriggerCompleted", - "discriminant": 0, - "type": "TriggerCompletedEvent" - } - ] - }, - "NotificationEventFilter": { - "Enum": [ - { - "tag": "ByAny", - "discriminant": 0 - }, - { - "tag": "ByTriggerCompleted", - "discriminant": 1, - "type": "TriggerCompletedEventFilter" - } - ] - }, "Numeric": { "Struct": [ { diff --git a/schema/gen/src/lib.rs b/schema/gen/src/lib.rs index 7995f54eaf6..259120b048d 100644 --- a/schema/gen/src/lib.rs +++ b/schema/gen/src/lib.rs @@ -233,8 +233,6 @@ types!( NonTrivial, NonZeroU32, NonZeroU64, - NotificationEvent, - NotificationEventFilter, Numeric, NumericSpec, Option,