Skip to content

Commit

Permalink
fix: patch block_results serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
joroshiba committed Jan 7, 2025
1 parent 4935612 commit 769c6a6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions tendermint/src/serializers/apphash.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! AppHash serialization with validation
use core::str::FromStr;

use alloc::borrow::Cow;

use serde::{de, ser, Deserialize, Deserializer, Serializer};
use subtle_encoding::hex;
use serde::{de, Deserialize, Deserializer, Serializer};

use crate::{prelude::*, AppHash};

Expand All @@ -13,16 +13,14 @@ where
D: Deserializer<'de>,
{
let hexstring = Option::<Cow<'_, str>>::deserialize(deserializer)?.unwrap_or(Cow::Borrowed(""));
AppHash::from_hex_upper(&hexstring).map_err(de::Error::custom)
AppHash::from_str(&hexstring).map_err(de::Error::custom)
}

/// Serialize from AppHash into hexstring
pub fn serialize<S>(value: &AppHash, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let hex_bytes = hex::encode_upper(value.as_ref());
let hex_string = String::from_utf8(hex_bytes).map_err(ser::Error::custom)?;
// Serialize as Option<String> for symmetry with deserialize
serializer.serialize_some(&hex_string)
serializer.serialize_some(&value.to_string())
}

0 comments on commit 769c6a6

Please sign in to comment.