Skip to content

Commit 5702036

Browse files
committed
ChannelId deserialization
Signed-off-by: Lachezar Lechev <[email protected]>
1 parent 97467af commit 5702036

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Cargo.lock

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

primitives/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ ethereum-types = "0.13"
104104
parse-display = "0.5"
105105
# CID & multihash / multibase
106106
cid = "0.8"
107-
hex = { version = "0.4", features = ["serde"] }
107+
hex = "0.4"
108108
merkletree = "0.10"
109109
tiny-keccak = { version = "2", features = ["keccak"] }
110110
url = { version = "2", features = ["serde"] }

primitives/src/channel.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use hex::{FromHex, FromHexError};
88

99
use crate::{Address, ToHex, Validator, ValidatorId};
1010

11-
#[derive(Deserialize, PartialEq, Eq, Copy, Clone, Hash)]
12-
#[serde(transparent)]
13-
pub struct ChannelId(#[serde(deserialize_with = "deserialize_channel_id")] [u8; 32]);
11+
#[derive(PartialEq, Eq, Copy, Clone, Hash)]
12+
pub struct ChannelId([u8; 32]);
1413

1514
impl ChannelId {
1615
pub fn as_bytes(&self) -> &[u8; 32] {
@@ -32,6 +31,15 @@ where
3231
validate_channel_id(&channel_id).map_err(serde::de::Error::custom)
3332
}
3433

34+
impl<'de> Deserialize<'de> for ChannelId {
35+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
36+
where
37+
D: Deserializer<'de>,
38+
{
39+
deserialize_channel_id(deserializer).map(ChannelId)
40+
}
41+
}
42+
3543
impl Serialize for ChannelId {
3644
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
3745
where
@@ -334,6 +342,7 @@ mod postgres {
334342
#[cfg(test)]
335343
mod test {
336344
use crate::{channel::Nonce, postgres::POSTGRES_POOL};
345+
337346
#[tokio::test]
338347
async fn nonce_to_from_sql() {
339348
let client = POSTGRES_POOL.get().await.unwrap();

0 commit comments

Comments
 (0)