From 11a853e9f24e36e430faabe9a9aaa610108ad45c Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Tue, 6 Aug 2024 15:29:17 +0200 Subject: [PATCH] node-data: change EventSource component to be const --- node-data/src/events.rs | 9 +++++---- node-data/src/events/blocks.rs | 5 ++--- node-data/src/events/transactions.rs | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/node-data/src/events.rs b/node-data/src/events.rs index da4d0cfa25..17b7367592 100644 --- a/node-data/src/events.rs +++ b/node-data/src/events.rs @@ -19,19 +19,20 @@ pub struct Event { } pub trait EventSource { - fn component(&self) -> &'static str; + const COMPONENT: &'static str; + fn topic(&self) -> &'static str; fn entity(&self) -> String; fn data(&self) -> EventData; } -impl From for Event { - fn from(value: B) -> Self { +impl From for Event { + fn from(value: ES) -> Self { Self { data: value.data(), topic: value.topic(), entity: value.entity(), - component: value.component(), + component: ES::COMPONENT, } } } diff --git a/node-data/src/events/blocks.rs b/node-data/src/events/blocks.rs index cb09b9fa89..44fdebbc0d 100644 --- a/node-data/src/events/blocks.rs +++ b/node-data/src/events/blocks.rs @@ -8,9 +8,8 @@ use super::*; use crate::ledger::{Block, Hash}; impl EventSource for BlockEvent<'_> { - fn component(&self) -> &'static str { - "blocks" - } + const COMPONENT: &'static str = "blocks"; + fn topic(&self) -> &'static str { match self { Self::Accepted(_) => "accepted", diff --git a/node-data/src/events/transactions.rs b/node-data/src/events/transactions.rs index 71518cfa93..bb9d791221 100644 --- a/node-data/src/events/transactions.rs +++ b/node-data/src/events/transactions.rs @@ -15,9 +15,8 @@ pub enum TransactionEvent<'t> { } impl EventSource for TransactionEvent<'_> { - fn component(&self) -> &'static str { - "transactions" - } + const COMPONENT: &'static str = "transactions"; + fn topic(&self) -> &'static str { match self { Self::Removed(_) => "removed",