Skip to content

Commit 86fa858

Browse files
committed
Swapped to LH's ForkName enum
1 parent 50fccb5 commit 86fa858

2 files changed

Lines changed: 15 additions & 23 deletions

File tree

crates/common/src/utils.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use axum::{
1515
};
1616
use bytes::Bytes;
1717
use futures::StreamExt;
18+
pub use lh_types::ForkName;
1819
use lh_types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
1920
use mediatype::{MediaType, MediaTypeList, names};
2021
use rand::{Rng, distr::Alphanumeric};
@@ -450,29 +451,6 @@ pub fn get_consensus_version_header(req_headers: &HeaderMap) -> Option<ForkName>
450451
.ok()
451452
}
452453

453-
#[derive(Debug, Clone, Copy, PartialEq)]
454-
pub enum ForkName {
455-
Electra,
456-
}
457-
458-
impl std::fmt::Display for ForkName {
459-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
460-
match self {
461-
ForkName::Electra => write!(f, "electra"),
462-
}
463-
}
464-
}
465-
466-
impl FromStr for ForkName {
467-
type Err = String;
468-
fn from_str(value: &str) -> Result<Self, Self::Err> {
469-
match value {
470-
"electra" => Ok(ForkName::Electra),
471-
_ => Err(format!("Invalid fork name {value}")),
472-
}
473-
}
474-
}
475-
476454
#[derive(Debug, Clone, Copy, PartialEq)]
477455
pub enum ContentType {
478456
Json,

tests/src/mock_relay.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ async fn handle_get_header(
148148
Accept::Ssz => response.as_ssz_bytes(),
149149
}
150150
}
151+
_ => {
152+
return (
153+
StatusCode::BAD_REQUEST,
154+
format!("Unsupported fork {consensus_version_header}"),
155+
)
156+
.into_response();
157+
}
151158
};
152159

153160
let mut response = (StatusCode::OK, data).into_response();
@@ -209,6 +216,13 @@ async fn handle_submit_block_v1(
209216
Accept::Ssz => match consensus_version_header {
210217
// Response isn't versioned for SSZ
211218
ForkName::Electra => response.as_ssz_bytes(),
219+
_ => {
220+
return (
221+
StatusCode::BAD_REQUEST,
222+
format!("Unsupported fork {consensus_version_header}"),
223+
)
224+
.into_response();
225+
}
212226
},
213227
}
214228
};

0 commit comments

Comments
 (0)