From 9279da78562874cf24c80163dce898555d2fcdeb Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Thu, 8 Aug 2024 15:21:20 +0200 Subject: [PATCH] node-data: change Event to only support JSON --- node-data/src/events.rs | 12 ++---------- node-data/src/events/blocks.rs | 15 ++++++++------- node-data/src/events/transactions.rs | 4 ++-- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/node-data/src/events.rs b/node-data/src/events.rs index 17b7367592..431697cf40 100644 --- a/node-data/src/events.rs +++ b/node-data/src/events.rs @@ -15,7 +15,7 @@ pub struct Event { pub component: &'static str, pub topic: &'static str, pub entity: String, - pub data: EventData, + pub data: Option, } pub trait EventSource { @@ -23,7 +23,7 @@ pub trait EventSource { fn topic(&self) -> &'static str; fn entity(&self) -> String; - fn data(&self) -> EventData; + fn data(&self) -> Option; } impl From for Event { @@ -36,11 +36,3 @@ impl From for Event { } } } - -#[derive(Clone, Debug)] -pub enum EventData { - None, - Json(serde_json::Value), - Text(String), - Binary(Vec), -} diff --git a/node-data/src/events/blocks.rs b/node-data/src/events/blocks.rs index 8aacc2abae..b8b5cb56b2 100644 --- a/node-data/src/events/blocks.rs +++ b/node-data/src/events/blocks.rs @@ -16,26 +16,27 @@ impl EventSource for BlockEvent<'_> { Self::StateChange { .. } => "statechange", } } - fn data(&self) -> EventData { - match self { + fn data(&self) -> Option { + let data = match self { Self::Accepted(b) => { let header = b.header(); let header = serde_json::to_value(header) .expect("json to be serialized"); let txs: Vec<_> = b.txs().iter().map(|t| hex::encode(t.id())).collect(); - EventData::Json(serde_json::json!({ + serde_json::json!({ "header": header, "transactions": txs, - })) + }) } Self::StateChange { state, height, .. } => { - EventData::Json(serde_json::json!({ + serde_json::json!({ "state": state, "atHeight": height, - })) + }) } - } + }; + Some(data) } fn entity(&self) -> String { let hash = match self { diff --git a/node-data/src/events/transactions.rs b/node-data/src/events/transactions.rs index bb9d791221..0d2491c7b8 100644 --- a/node-data/src/events/transactions.rs +++ b/node-data/src/events/transactions.rs @@ -24,8 +24,8 @@ impl EventSource for TransactionEvent<'_> { Self::Included(_) => "included", } } - fn data(&self) -> EventData { - EventData::None + fn data(&self) -> Option { + None } fn entity(&self) -> String { let hash = match self {