From a915e34d666f5070819f3d195f55b4af9b38f6d4 Mon Sep 17 00:00:00 2001 From: darkfi Date: Thu, 19 Sep 2024 18:22:35 +0200 Subject: [PATCH] evgrd: deserialize and print privmsg on new event --- script/evgrd/bin/test.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/script/evgrd/bin/test.rs b/script/evgrd/bin/test.rs index ee231a13e..cddf06e63 100644 --- a/script/evgrd/bin/test.rs +++ b/script/evgrd/bin/test.rs @@ -22,7 +22,10 @@ use darkfi::{ util::path::expand_path, Error, Result, }; -use darkfi_serial::{AsyncDecodable, AsyncEncodable}; +use darkfi_serial::{ + async_trait, deserialize_async_partial, AsyncDecodable, AsyncEncodable, SerialDecodable, + SerialEncodable, +}; use log::{error, info}; use sled_overlay::sled; use smol::fs; @@ -30,6 +33,13 @@ use url::Url; use evgrd::{FetchEventsMessage, LocalEventGraph, VersionMessage, MSG_EVENT, MSG_FETCHEVENTS}; +#[derive(Clone, Debug, SerialEncodable, SerialDecodable)] +pub struct Privmsg { + pub channel: String, + pub nick: String, + pub msg: String, +} + async fn amain() -> Result<()> { info!("Instantiating event DAG"); let ex = std::sync::Arc::new(smol::Executor::new()); @@ -76,7 +86,17 @@ async fn amain() -> Result<()> { ev.validate(&evgr.dag, genesis_timestamp, evgr.days_rotation, None).await? { println!("got {ev:?}"); - evgr.dag_insert(&[ev]).await.unwrap(); + evgr.dag_insert(&[ev.clone()]).await.unwrap(); + + let privmsg: Privmsg = match deserialize_async_partial(ev.content()).await { + Ok((v, _)) => v, + Err(e) => { + println!("Failed deserializing incoming Privmsg event: {}", e); + continue + } + }; + + println!("privmsg: {privmsg:?}"); } else { println!("Event is invalid!") }