mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 05:18:30 +00:00
Standard beacon api updates (#1831)
## Issue Addressed Resolves #1809 Resolves #1824 Resolves #1818 Resolves #1828 (hopefully) ## Proposed Changes - add `validator_index` to the proposer duties endpoint - add the ability to query for historical proposer duties - `StateId` deserialization now fails with a 400 warp rejection - add the `validator_balances` endpoint - update the `aggregate_and_proofs` endpoint to accept an array - updates the attester duties endpoint from a `GET` to a `POST` - reduces the number of times we query for proposer duties from once per slot per validator to only once per slot Co-authored-by: realbigsean <seananderson33@gmail.com> Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use eth2::types::ErrorMessage;
|
||||
use eth2::types::{ErrorMessage, Failure, IndexedErrorMessage};
|
||||
use std::convert::Infallible;
|
||||
use warp::{http::StatusCode, reject::Reject};
|
||||
|
||||
@@ -110,12 +110,37 @@ pub fn invalid_auth(msg: String) -> warp::reject::Rejection {
|
||||
warp::reject::custom(InvalidAuthorization(msg))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IndexedBadRequestErrors {
|
||||
pub message: String,
|
||||
pub failures: Vec<Failure>,
|
||||
}
|
||||
|
||||
impl Reject for IndexedBadRequestErrors {}
|
||||
|
||||
pub fn indexed_bad_request(message: String, failures: Vec<Failure>) -> warp::reject::Rejection {
|
||||
warp::reject::custom(IndexedBadRequestErrors { message, failures })
|
||||
}
|
||||
|
||||
/// This function receives a `Rejection` and tries to return a custom
|
||||
/// value, otherwise simply passes the rejection along.
|
||||
pub async fn handle_rejection(err: warp::Rejection) -> Result<impl warp::Reply, Infallible> {
|
||||
let code;
|
||||
let message;
|
||||
|
||||
if let Some(e) = err.find::<crate::reject::IndexedBadRequestErrors>() {
|
||||
message = format!("BAD_REQUEST: {}", e.message);
|
||||
code = StatusCode::BAD_REQUEST;
|
||||
|
||||
let json = warp::reply::json(&IndexedErrorMessage {
|
||||
code: code.as_u16(),
|
||||
message,
|
||||
failures: e.failures.clone(),
|
||||
});
|
||||
|
||||
return Ok(warp::reply::with_status(json, code));
|
||||
}
|
||||
|
||||
if err.is_not_found() {
|
||||
code = StatusCode::NOT_FOUND;
|
||||
message = "NOT_FOUND".to_string();
|
||||
|
||||
Reference in New Issue
Block a user