mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 06:44:35 +00:00
* #7286 * BeaconAPI is not returning a versioned response when it should for some V1 endpoints * these [strange functions with vX in the name that still accept `endpoint_version` arguments](https://github.com/sigp/lighthouse/blob/stable/beacon_node/http_api/src/produce_block.rs#L192) This refactor is a prerequisite to get the fulu EF tests running.
46 lines
1.5 KiB
Rust
46 lines
1.5 KiB
Rust
use crate::ContextDeserialize;
|
|
use milhouse::{List, Value, Vector};
|
|
use serde::de::Deserializer;
|
|
use ssz_types::typenum::Unsigned;
|
|
|
|
impl<'de, C, T, N> ContextDeserialize<'de, C> for List<T, N>
|
|
where
|
|
T: ContextDeserialize<'de, C> + Value,
|
|
N: Unsigned,
|
|
C: Clone,
|
|
{
|
|
fn context_deserialize<D>(deserializer: D, context: C) -> Result<Self, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
// First deserialize as a Vec.
|
|
// This is not the most efficient implementation as it allocates a temporary Vec. In future
|
|
// we could write a more performant implementation using `List::builder()`.
|
|
let vec = Vec::<T>::context_deserialize(deserializer, context)?;
|
|
|
|
// Then convert to List, which will check the length.
|
|
List::new(vec)
|
|
.map_err(|e| serde::de::Error::custom(format!("Failed to create List: {:?}", e)))
|
|
}
|
|
}
|
|
|
|
impl<'de, C, T, N> ContextDeserialize<'de, C> for Vector<T, N>
|
|
where
|
|
T: ContextDeserialize<'de, C> + Value,
|
|
N: Unsigned,
|
|
C: Clone,
|
|
{
|
|
fn context_deserialize<D>(deserializer: D, context: C) -> Result<Self, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
// First deserialize as a List
|
|
let list = List::<T, N>::context_deserialize(deserializer, context)?;
|
|
|
|
// Then convert to Vector, which will check the length
|
|
Vector::try_from(list).map_err(|e| {
|
|
serde::de::Error::custom(format!("Failed to convert List to Vector: {:?}", e))
|
|
})
|
|
}
|
|
}
|