diff --git a/crates/relayer-types/src/core/ics23_commitment/commitment.rs b/crates/relayer-types/src/core/ics23_commitment/commitment.rs index 82c105538..1d3f5548c 100644 --- a/crates/relayer-types/src/core/ics23_commitment/commitment.rs +++ b/crates/relayer-types/src/core/ics23_commitment/commitment.rs @@ -14,6 +14,7 @@ use super::merkle::MerkleProof; #[serde(transparent)] pub struct CommitmentRoot { #[serde(serialize_with = "crate::serializers::ser_hex_upper")] + #[serde(deserialize_with = "crate::serializers::deser_hex_upper")] bytes: Vec, } diff --git a/crates/relayer-types/src/serializers.rs b/crates/relayer-types/src/serializers.rs index bd6f34633..f30107f06 100644 --- a/crates/relayer-types/src/serializers.rs +++ b/crates/relayer-types/src/serializers.rs @@ -1,4 +1,7 @@ -use serde::ser::{Serialize, Serializer}; +use serde::{ + ser::{Serialize, Serializer}, + Deserialize, Deserializer, +}; use subtle_encoding::{Encoding, Hex}; pub fn ser_hex_upper(data: T, serializer: S) -> Result @@ -10,6 +13,15 @@ where hex.serialize(serializer) } +pub fn deser_hex_upper<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let data = alloc::string::String::deserialize(deserializer)?; + let decoded = Hex::upper_case().decode_from_str(data).unwrap(); + Ok(decoded) +} + pub mod serde_string { use alloc::string::String; use core::fmt::Display;