diff --git a/rusk/src/lib/http/event.rs b/rusk/src/lib/http/event.rs index 298e4ce63..562b7c618 100644 --- a/rusk/src/lib/http/event.rs +++ b/rusk/src/lib/http/event.rs @@ -834,6 +834,22 @@ impl From for RuesEvent { } } +#[cfg(feature = "node")] +impl From for RuesEvent { + fn from(value: node_data::events::NodeEvent) -> Self { + let mut headers = serde_json::Map::new(); + headers.insert( + "Content-Location".into(), + format!("/on/{}:{}/{}", value.target, value.id, value.topic).into(), + ); + + Self { + headers: serde_json::Map::new(), + data: RuesEventData::Other(value.data.into()), + } + } +} + /// Types of event data that RUES supports. #[derive(Debug, Clone, PartialEq, Eq)] pub enum RuesEventData { diff --git a/rusk/src/lib/node/events.rs b/rusk/src/lib/node/events.rs index 4e5748c4f..2e724eaf6 100644 --- a/rusk/src/lib/node/events.rs +++ b/rusk/src/lib/node/events.rs @@ -12,7 +12,7 @@ use node::{LongLivedService, Network}; use node_data::events::NodeEvent; use tokio::sync::broadcast; use tokio::sync::mpsc::Receiver; -use tracing::info; +use tracing::error; use crate::http::RuesEvent; @@ -22,15 +22,6 @@ pub(crate) struct NodeEventStreamer { pub rues_sender: broadcast::Sender, } -// impl From for RuesEvent { -// fn from(value: NodeEvent) -> Self { -// Self { -// headers: serde_json::Map::new(), -// data: RuesEventData::Contract(event), -// } -// } -// } - #[async_trait] impl LongLivedService for NodeEventStreamer @@ -42,9 +33,10 @@ impl _: Arc>, ) -> anyhow::Result { loop { - if let Some(_msg) = self.node_receiver.recv().await { - // self.sender.send() - info!("event received"); + if let Some(msg) = self.node_receiver.recv().await { + if let Err(e) = self.rues_sender.send(msg.into()) { + error!("Cannot send to rues {e:?}"); + } } } }