diff --git a/crates/starknet-types-core/src/felt/mod.rs b/crates/starknet-types-core/src/felt/mod.rs index 6910392..fe2b5d8 100644 --- a/crates/starknet-types-core/src/felt/mod.rs +++ b/crates/starknet-types-core/src/felt/mod.rs @@ -959,9 +959,12 @@ mod serde_impl { impl<'de> de::Visitor<'de> for FeltVisitor { type Value = Felt; - // TODO(xrvdg) change this fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_str("Failed to deserialize hexadecimal string") + // The message below is append to “This Visitor expects to receive …” + write!( + formatter, + "a 32 byte array ([u8;32]) or a hexadecimal string." + ) } fn visit_str(self, value: &str) -> Result @@ -973,22 +976,17 @@ mod serde_impl { .strip_prefix("0x") .and_then(|v| FieldElement::::from_hex(v).ok()) .map(Felt) - .ok_or(String::from("Expected hex string to be prefixed by '0x'")) + .ok_or(String::from("expected hex string to be prefixed by '0x'")) .map_err(de::Error::custom) } - fn visit_bytes(self, v: &[u8]) -> Result + fn visit_bytes(self, value: &[u8]) -> Result where E: de::Error, { - let nv: Result<[u8; 32], _> = v.try_into(); - match nv { + match value.try_into() { Ok(v) => Ok(Felt::from_bytes_be(&v)), - // TODO(xrvdg) use error::invalid length instead - _ => Err(de::Error::custom(format!( - "Felt bytestring needs to be 32 bytes long, it is {}", - v.len() - ))), + _ => Err(de::Error::invalid_length(value.len(), &self)), } } }