From df8025fbe59b2d116fe6ea50658813381d7bfc42 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Wed, 3 Jan 2024 15:21:43 +0100 Subject: [PATCH] Remove dead code --- crates/relayer/src/config.rs | 1 - crates/relayer/src/config/trust_threshold.rs | 72 -------------------- 2 files changed, 73 deletions(-) delete mode 100644 crates/relayer/src/config/trust_threshold.rs diff --git a/crates/relayer/src/config.rs b/crates/relayer/src/config.rs index a3e94e814f..f1bb4e7517 100644 --- a/crates/relayer/src/config.rs +++ b/crates/relayer/src/config.rs @@ -6,7 +6,6 @@ pub mod filter; pub mod gas_multiplier; pub mod proof_specs; pub mod refresh_rate; -pub mod trust_threshold; pub mod types; use alloc::collections::BTreeMap; diff --git a/crates/relayer/src/config/trust_threshold.rs b/crates/relayer/src/config/trust_threshold.rs deleted file mode 100644 index 12dd151a86..0000000000 --- a/crates/relayer/src/config/trust_threshold.rs +++ /dev/null @@ -1,72 +0,0 @@ -use std::{fmt, marker::PhantomData}; - -use serde::{ - de::{self, MapAccess, Visitor}, - Deserialize, Deserializer, Serialize, Serializer, -}; - -use tendermint_light_client::verifier::types::TrustThreshold; - -pub fn serialize( - trust_threshold: &TrustThreshold, - serializer: S, -) -> Result { - TrustThreshold::serialize(trust_threshold, serializer) -} - -pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result { - deserializer.deserialize_any(StringOrStruct(PhantomData)) -} - -// This is a Visitor that forwards string types to T's `FromStr` impl and -// forwards map types to T's `Deserialize` impl. The `PhantomData` is to -// keep the compiler from complaining about T being an unused generic type -// parameter. We need T in order to know the Value type for the Visitor -// impl. -struct StringOrStruct(PhantomData T>); - -impl<'de> Visitor<'de> for StringOrStruct { - type Value = TrustThreshold; - - fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_str("string (eg. '1/3') or { numerator = , denominator = }") - } - - fn visit_str(self, value: &str) -> Result - where - E: de::Error, - { - let parts: Vec<&str> = value.split('/').collect(); - - if parts.len() != 2 { - return Err(serde::de::Error::custom(format!( - "invalid trust threshold, must be a fraction: {value}", - ))); - } - - let (num, denom) = (parts[0].parse(), parts[1].parse()); - - match (num, denom) { - (Ok(num), Ok(denom)) => TrustThreshold::new(num, denom).map_err(|e| { - serde::de::Error::custom(format!( - "invalid trust threshold, must be a fraction: {e}" - )) - }), - - _ => Err(serde::de::Error::custom(format!( - "invalid trust threshold, must be a fraction: {value}", - ))), - } - } - - fn visit_map(self, map: M) -> Result - where - M: MapAccess<'de>, - { - // `MapAccessDeserializer` is a wrapper that turns a `MapAccess` - // into a `Deserializer`, allowing it to be used as the input to T's - // `Deserialize` implementation. T then deserializes itself using - // the entries from the map visitor. - TrustThreshold::deserialize(de::value::MapAccessDeserializer::new(map)) - } -}