Add Changes to BlobSidecars Endpoint (#4455)
* changed name * Fix sidecars * Added query type and parrameter * added query struct and function * added method * improved filtering method * added blob_sidecar_list_indexed to block_id * minor blobqueryindex fix * function and formatting fix * minor function and naming fix * minor changes
This commit is contained in:
parent
f98671f5ab
commit
f1f04bc68a
@ -1,5 +1,6 @@
|
||||
use crate::{state_id::checkpoint_slot_and_execution_optimistic, ExecutionOptimistic};
|
||||
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes, WhenSlotSkipped};
|
||||
use eth2::types::BlobIndicesQuery;
|
||||
use eth2::types::BlockId as CoreBlockId;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
@ -266,6 +267,26 @@ impl BlockId {
|
||||
Err(e) => Err(warp_utils::reject::beacon_chain_error(e)),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn blob_sidecar_list_filtered<T: BeaconChainTypes>(
|
||||
&self,
|
||||
indices: BlobIndicesQuery,
|
||||
chain: &BeaconChain<T>,
|
||||
) -> Result<BlobSidecarList<T::EthSpec>, warp::Rejection> {
|
||||
let blob_sidecar_list = self.blob_sidecar_list(&chain).await?;
|
||||
let blob_sidecar_list_filtered = match indices.indices {
|
||||
Some(vec) => {
|
||||
let list = blob_sidecar_list
|
||||
.into_iter()
|
||||
.filter(|blob_sidecar| vec.contains(&blob_sidecar.index))
|
||||
.collect();
|
||||
BlobSidecarList::new(list)
|
||||
.map_err(|e| warp_utils::reject::custom_server_error(format!("{:?}", e)))?
|
||||
}
|
||||
None => blob_sidecar_list,
|
||||
};
|
||||
Ok(blob_sidecar_list_filtered)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for BlockId {
|
||||
|
@ -1487,21 +1487,23 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(warp::path("beacon"))
|
||||
.and(warp::path("blob_sidecars"))
|
||||
.and(block_id_or_err)
|
||||
.and(warp::query::<api_types::BlobIndicesQuery>())
|
||||
.and(warp::path::end())
|
||||
.and(chain_filter.clone())
|
||||
.and(warp::header::optional::<api_types::Accept>("accept"))
|
||||
.and_then(
|
||||
|block_id: BlockId,
|
||||
indices: api_types::BlobIndicesQuery,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
accept_header: Option<api_types::Accept>| {
|
||||
async move {
|
||||
let blob_sidecar_list = block_id.blob_sidecar_list(&chain).await?;
|
||||
|
||||
let blob_sidecar_list_filtered =
|
||||
block_id.blob_sidecar_list_filtered(indices, &chain).await?;
|
||||
match accept_header {
|
||||
Some(api_types::Accept::Ssz) => Response::builder()
|
||||
.status(200)
|
||||
.header("Content-Type", "application/octet-stream")
|
||||
.body(blob_sidecar_list.as_ssz_bytes().into())
|
||||
.body(blob_sidecar_list_filtered.as_ssz_bytes().into())
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_server_error(format!(
|
||||
"failed to create response: {}",
|
||||
@ -1509,7 +1511,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
))
|
||||
}),
|
||||
_ => Ok(warp::reply::json(&api_types::GenericResponse::from(
|
||||
blob_sidecar_list,
|
||||
blob_sidecar_list_filtered,
|
||||
))
|
||||
.into_response()),
|
||||
}
|
||||
|
@ -648,6 +648,13 @@ pub struct ValidatorBalancesQuery {
|
||||
pub id: Option<Vec<ValidatorId>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct BlobIndicesQuery {
|
||||
#[serde(default, deserialize_with = "option_query_vec")]
|
||||
pub indices: Option<Vec<u64>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct ValidatorIndexData(#[serde(with = "serde_utils::quoted_u64_vec")] pub Vec<u64>);
|
||||
|
Loading…
Reference in New Issue
Block a user