Skip to content

Commit

Permalink
fix: fix CommitmentRoot deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Nov 7, 2023
1 parent 70c525d commit 21a6302
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
}

Expand Down
14 changes: 13 additions & 1 deletion crates/relayer-types/src/serializers.rs
Original file line number Diff line number Diff line change
@@ -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<S, T>(data: T, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -10,6 +13,15 @@ where
hex.serialize(serializer)
}

pub fn deser_hex_upper<'de, D>(deserializer: D) -> Result<alloc::vec::Vec<u8>, 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;
Expand Down

0 comments on commit 21a6302

Please sign in to comment.