Skip to content

Commit c2f1b5f

Browse files
committed
Changed valdiate function to retturn u8 32 array in the result
1 parent 6359c85 commit c2f1b5f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

primitives/src/channel.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ where
3232
D: Deserializer<'de>,
3333
{
3434
let channel_id = String::deserialize(deserializer)?;
35-
let channel_id = validate_channel_id(&channel_id).map_err(serde::de::Error::custom)?;
36-
<[u8; 32] as FromHex>::from_hex(channel_id).map_err(serde::de::Error::custom)
35+
validate_channel_id(&channel_id).map_err(serde::de::Error::custom)
3736
}
3837

39-
fn validate_channel_id(s: &str) -> Result<&str, FromHexError> {
38+
fn validate_channel_id(s: &str) -> Result<[u8; 32], FromHexError> {
4039
match (s.get(0..2), s.get(2..)) {
41-
(Some(prefix), Some(hex)) => if hex.len() != 64 || prefix != "0x" {
42-
Err(FromHexError::InvalidStringLength)
43-
} else {
44-
Ok(hex)
45-
},
46-
_ => Err(FromHexError::InvalidStringLength)
40+
(Some(prefix), Some(hex)) => {
41+
if hex.len() != 64 || prefix != "0x" {
42+
Err(FromHexError::InvalidStringLength)
43+
} else {
44+
Ok(<[u8; 32] as FromHex>::from_hex(s)?)
45+
}
46+
}
47+
_ => Err(FromHexError::InvalidStringLength),
4748
}
4849
}
4950

0 commit comments

Comments
 (0)