Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…r-iroha#3068: Remove some more redundancy when constructing event filters

Signed-off-by: Nikita Strygin <[email protected]>
  • Loading branch information
DCNick3 committed Mar 18, 2024
1 parent c8d87d4 commit cebdda9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,16 @@ mod events {

impl RunArgs for Args {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let filter = match self {
Args::Pipeline => EventFilterBox::Pipeline(PipelineEventFilter::new()),
Args::Data => EventFilterBox::Data(DataEventFilter::Any),
Args::Notification => EventFilterBox::Notification(NotificationEventFilter::ByAny),
};
listen(filter, context)
match self {
Args::Pipeline => listen(PipelineEventFilter::new(), context),
Args::Data => listen(DataEventFilter::Any, context),
Args::Notification => listen(NotificationEventFilter::ByAny, context),
}
}
}

fn listen(filter: EventFilterBox, context: &mut dyn RunContext) -> Result<()> {
fn listen(filter: impl Into<EventFilterBox>, context: &mut dyn RunContext) -> Result<()> {
let filter = filter.into();
let iroha_client = context.client_from_config();
eprintln!("Listening to events with filter: {filter:?}");
iroha_client
Expand Down
4 changes: 2 additions & 2 deletions core/test_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ pub trait TestClient: Sized {
fn test_with_account(api_url: &SocketAddr, keys: KeyPair, account_id: &AccountId) -> Self;

/// Loop for events with filter and handler function
fn for_each_event(self, event_filter: EventFilterBox, f: impl Fn(Result<Event>));
fn for_each_event(self, event_filter: impl Into<EventFilterBox>, f: impl Fn(Result<Event>));

/// Submit instruction with polling
///
Expand Down Expand Up @@ -811,7 +811,7 @@ impl TestClient for Client {
Client::new(config)
}

fn for_each_event(self, event_filter: EventFilterBox, f: impl Fn(Result<Event>)) {
fn for_each_event(self, event_filter: impl Into<EventFilterBox>, f: impl Fn(Result<Event>)) {
for event_result in self
.listen_for_events(event_filter)
.expect("Failed to create event iterator.")
Expand Down
2 changes: 1 addition & 1 deletion tools/parity_scale_decoder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mod tests {
);
let rose_id = AssetId::new(rose_definition_id, account_id.clone());
let trigger_id = "mint_rose".parse().expect("Valid");
let action = Action::<EventFilterBox>::new(
let action = Action::new(
vec![Mint::asset_numeric(1u32, rose_id)],
Repeats::Indefinitely,
account_id,
Expand Down

0 comments on commit cebdda9

Please sign in to comment.