From 3f2af5cf808210881125e8c3c5d8f4c3f3ea15ef Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 2 Jul 2024 02:06:59 +1000 Subject: [PATCH] Delete duplicated serde code (#6027) * Delete duplicated serde code --- consensus/types/src/indexed_attestation.rs | 41 ++-------------------- 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/consensus/types/src/indexed_attestation.rs b/consensus/types/src/indexed_attestation.rs index 19d15010753..9274600ed2c 100644 --- a/consensus/types/src/indexed_attestation.rs +++ b/consensus/types/src/indexed_attestation.rs @@ -53,10 +53,10 @@ use tree_hash_derive::TreeHash; pub struct IndexedAttestation { /// Lists validator registry indices, not committee indices. #[superstruct(only(Base), partial_getter(rename = "attesting_indices_base"))] - #[serde(with = "quoted_variable_list_u64")] + #[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")] pub attesting_indices: VariableList, #[superstruct(only(Electra), partial_getter(rename = "attesting_indices_electra"))] - #[serde(with = "quoted_variable_list_u64")] + #[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")] pub attesting_indices: VariableList, pub data: AttestationData, pub signature: AggregateSignature, @@ -203,43 +203,6 @@ impl Hash for IndexedAttestation { } } -/// Serialize a variable list of `u64` such that each int is quoted. Deserialize a variable -/// list supporting both quoted and un-quoted ints. -/// -/// E.g.,`["0", "1", "2"]` -mod quoted_variable_list_u64 { - use super::*; - use crate::Unsigned; - use serde::ser::SerializeSeq; - use serde::{Deserializer, Serializer}; - use serde_utils::quoted_u64_vec::{QuotedIntVecVisitor, QuotedIntWrapper}; - - pub fn serialize(value: &VariableList, serializer: S) -> Result - where - S: Serializer, - T: Unsigned, - { - let mut seq = serializer.serialize_seq(Some(value.len()))?; - for &int in value.iter() { - seq.serialize_element(&QuotedIntWrapper { int })?; - } - seq.end() - } - - pub fn deserialize<'de, D, T>(deserializer: D) -> Result, D::Error> - where - D: Deserializer<'de>, - T: Unsigned, - { - deserializer - .deserialize_any(QuotedIntVecVisitor) - .and_then(|vec| { - VariableList::new(vec) - .map_err(|e| serde::de::Error::custom(format!("invalid length: {:?}", e))) - }) - } -} - #[cfg(test)] mod tests { use super::*;