Skip to content

Commit

Permalink
darkirc/irc/mod: do full deserialization of Msg
Browse files Browse the repository at this point in the history
  • Loading branch information
skoupidi committed Jan 24, 2025
1 parent 9605973 commit da39c8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions bin/darkirc/src/irc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crypto_box::ChaChaBox;
use darkfi::{Error, Result};
use darkfi_sdk::crypto::{schnorr::SchnorrSecret, PublicKey, SecretKey};
use darkfi_serial::{
async_trait, deserialize_async_partial, serialize, Encodable, SerialDecodable, SerialEncodable,
async_trait, deserialize_async, serialize, Encodable, SerialDecodable, SerialEncodable,
};

/// IRC client state
Expand Down Expand Up @@ -153,18 +153,15 @@ pub enum Msg {

impl Msg {
pub async fn deserialize(bytes: &[u8]) -> Result<Self> {
let old_privmsg = deserialize_async_partial(bytes).await;
if let Ok((old_msg, _)) = old_privmsg {
if let Ok(old_msg) = deserialize_async(bytes).await {
return Ok(Msg::V1(old_msg))
}

let new_privmsg = deserialize_async_partial(bytes).await;
if let Ok((new_msg, _)) = new_privmsg {
if let Ok(new_msg) = deserialize_async(bytes).await {
return Ok(Msg::V2(new_msg))
}

let mod_msg = deserialize_async_partial(bytes).await;
if let Ok((mod_msg, _)) = mod_msg {
if let Ok(mod_msg) = deserialize_async(bytes).await {
return Ok(Msg::Mod(mod_msg))
}

Expand Down
2 changes: 1 addition & 1 deletion bin/darkirc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
println!("mod_secret_key = \"{}\"", moderator_keypair.secret);
println!("#mod_mublic_key = \"{}\"", moderator_keypair.public);
println!("\nDon't forget to add your public key in the channel moderators vector like:\n");
println!("moderators = \"{}\"", moderator_keypair.public);
println!("moderators = [\"{}\"]", moderator_keypair.public);
return Ok(())
}

Expand Down

0 comments on commit da39c8c

Please sign in to comment.