mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 20:22:02 +00:00
Altair validator client and HTTP API (#2404)
## Proposed Changes * Implement the validator client and HTTP API changes necessary to support Altair Co-authored-by: realbigsean <seananderson33@gmail.com> Co-authored-by: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
28
beacon_node/http_api/src/version.rs
Normal file
28
beacon_node/http_api/src/version.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use crate::api_types::{EndpointVersion, ForkVersionedResponse};
|
||||
use serde::Serialize;
|
||||
use types::ForkName;
|
||||
|
||||
pub const V1: EndpointVersion = EndpointVersion(1);
|
||||
pub const V2: EndpointVersion = EndpointVersion(2);
|
||||
|
||||
pub fn fork_versioned_response<T: Serialize>(
|
||||
endpoint_version: EndpointVersion,
|
||||
fork_name: Option<ForkName>,
|
||||
data: T,
|
||||
) -> Result<ForkVersionedResponse<T>, warp::reject::Rejection> {
|
||||
let fork_name = if endpoint_version == V1 {
|
||||
None
|
||||
} else if endpoint_version == V2 {
|
||||
fork_name
|
||||
} else {
|
||||
return Err(unsupported_version_rejection(endpoint_version));
|
||||
};
|
||||
Ok(ForkVersionedResponse {
|
||||
version: fork_name,
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn unsupported_version_rejection(version: EndpointVersion) -> warp::reject::Rejection {
|
||||
warp_utils::reject::custom_bad_request(format!("Unsupported endpoint version: {}", version))
|
||||
}
|
||||
Reference in New Issue
Block a user