-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rusk: move node events to own module
- Loading branch information
1 parent
3a7200d
commit b131e96
Showing
2 changed files
with
60 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) DUSK NETWORK. All rights reserved. | ||
|
||
use std::sync::Arc; | ||
|
||
use async_trait::async_trait; | ||
use node::database::{self}; | ||
use node::{LongLivedService, Network}; | ||
use node_data::events::NodeEvent; | ||
use tokio::sync::broadcast; | ||
use tokio::sync::mpsc::Receiver; | ||
use tracing::info; | ||
|
||
use crate::http::RuesEvent; | ||
|
||
pub(crate) struct NodeEventStreamer { | ||
pub node_receiver: Receiver<NodeEvent>, | ||
#[allow(dead_code)] | ||
pub rues_sender: broadcast::Sender<RuesEvent>, | ||
} | ||
|
||
// impl From<NodeEvent> for RuesEvent { | ||
// fn from(value: NodeEvent) -> Self { | ||
// Self { | ||
// headers: serde_json::Map::new(), | ||
// data: RuesEventData::Contract(event), | ||
// } | ||
// } | ||
// } | ||
|
||
#[async_trait] | ||
impl<N: Network, DB: database::DB, VM: node::vm::VMExecution> | ||
LongLivedService<N, DB, VM> for NodeEventStreamer | ||
{ | ||
async fn execute( | ||
&mut self, | ||
_: Arc<tokio::sync::RwLock<N>>, | ||
_: Arc<tokio::sync::RwLock<DB>>, | ||
_: Arc<tokio::sync::RwLock<VM>>, | ||
) -> anyhow::Result<usize> { | ||
loop { | ||
if let Some(_msg) = self.node_receiver.recv().await { | ||
// self.sender.send() | ||
info!("event received"); | ||
} | ||
} | ||
} | ||
|
||
/// Returns service name. | ||
fn name(&self) -> &'static str { | ||
"event streamer" | ||
} | ||
} |