mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-28 23:07:17 +00:00
Add bls serde_vistors file
This commit is contained in:
parent
ec9e0bbddf
commit
5c1458ba46
20
eth2/utils/bls/src/serde_vistors.rs
Normal file
20
eth2/utils/bls/src/serde_vistors.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use hex;
|
||||
use serde::de::{self, Visitor};
|
||||
use std::fmt;
|
||||
|
||||
pub struct HexVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for HexVisitor {
|
||||
type Value = Vec<u8>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a hex string (without 0x prefix)")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(hex::decode(value).map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))?)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user