Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…r-iroha#3068: Remove NotificationEvent

Instead of it, expose TriggerCompletedEvent as a top-level event, same as ExecuteTriggerEvent

Signed-off-by: Nikita Strygin <[email protected]>
  • Loading branch information
DCNick3 committed Mar 14, 2024
1 parent 083ad73 commit eaf54e7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 118 deletions.
22 changes: 10 additions & 12 deletions client/tests/integration/events/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down Expand Up @@ -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(());
Expand Down
9 changes: 6 additions & 3 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,19 @@ 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 {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
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),
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions core/src/wsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -567,8 +567,7 @@ impl WorldStateView {
event
}
};
self.events_buffer
.push(NotificationEvent::from(event).into());
self.events_buffer.push(event.into());
}
}

Expand Down
24 changes: 13 additions & 11 deletions data_model/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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,
};
}

Expand Down
30 changes: 4 additions & 26 deletions docs/source/references/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,9 @@
"type": "ExecuteTriggerEvent"
},
{
"tag": "Notification",
"tag": "TriggerCompleted",
"discriminant": 4,
"type": "NotificationEvent"
"type": "TriggerCompletedEvent"
}
]
},
Expand All @@ -909,9 +909,9 @@
"type": "ExecuteTriggerEventFilter"
},
{
"tag": "Notification",
"tag": "TriggerCompleted",
"discriminant": 4,
"type": "NotificationEventFilter"
"type": "TriggerCompletedEventFilter"
}
]
},
Expand Down Expand Up @@ -2214,28 +2214,6 @@
"NonTrivial<GenericPredicateBox<QueryOutputPredicate>>": "Vec<GenericPredicateBox<QueryOutputPredicate>>",
"NonZero<u32>": "u32",
"NonZero<u64>": "u64",
"NotificationEvent": {
"Enum": [
{
"tag": "TriggerCompleted",
"discriminant": 0,
"type": "TriggerCompletedEvent"
}
]
},
"NotificationEventFilter": {
"Enum": [
{
"tag": "ByAny",
"discriminant": 0
},
{
"tag": "ByTriggerCompleted",
"discriminant": 1,
"type": "TriggerCompletedEventFilter"
}
]
},
"Numeric": {
"Struct": [
{
Expand Down
2 changes: 0 additions & 2 deletions schema/gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ types!(
NonTrivial<PredicateBox>,
NonZeroU32,
NonZeroU64,
NotificationEvent,
NotificationEventFilter,
Numeric,
NumericSpec,
Option<u32>,
Expand Down

0 comments on commit eaf54e7

Please sign in to comment.