evgrd: deserialize and print privmsg on new event

This commit is contained in:
darkfi
2024-09-19 18:22:35 +02:00
parent 3067d970ea
commit a915e34d66

View File

@@ -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!")
}