mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
feat: implement new beacon APIs(accessors for pending_deposits/pending_partial_withdrawals) (#7006)
Resolves #7003 Added two endpoints as https://github.com/ethereum/beacon-APIs/pull/500 proposed: - `/eth/v1/beacon/states/{state_id}/pending_deposits` - `/eth/v1/beacon/states/{state_id}/pending_partial_withdrawals`
This commit is contained in:
@@ -1119,6 +1119,72 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
},
|
||||
);
|
||||
|
||||
// GET beacon/states/{state_id}/pending_deposits
|
||||
let get_beacon_state_pending_deposits = beacon_states_path
|
||||
.clone()
|
||||
.and(warp::path("pending_deposits"))
|
||||
.and(warp::path::end())
|
||||
.then(
|
||||
|state_id: StateId,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>| {
|
||||
task_spawner.blocking_json_task(Priority::P1, move || {
|
||||
let (data, execution_optimistic, finalized) = state_id
|
||||
.map_state_and_execution_optimistic_and_finalized(
|
||||
&chain,
|
||||
|state, execution_optimistic, finalized| {
|
||||
let Ok(deposits) = state.pending_deposits() else {
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"Pending deposits not found".to_string(),
|
||||
));
|
||||
};
|
||||
|
||||
Ok((deposits.clone(), execution_optimistic, finalized))
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(api_types::ExecutionOptimisticFinalizedResponse {
|
||||
data,
|
||||
execution_optimistic: Some(execution_optimistic),
|
||||
finalized: Some(finalized),
|
||||
})
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
// GET beacon/states/{state_id}/pending_partial_withdrawals
|
||||
let get_beacon_state_pending_partial_withdrawals = beacon_states_path
|
||||
.clone()
|
||||
.and(warp::path("pending_partial_withdrawals"))
|
||||
.and(warp::path::end())
|
||||
.then(
|
||||
|state_id: StateId,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>| {
|
||||
task_spawner.blocking_json_task(Priority::P1, move || {
|
||||
let (data, execution_optimistic, finalized) = state_id
|
||||
.map_state_and_execution_optimistic_and_finalized(
|
||||
&chain,
|
||||
|state, execution_optimistic, finalized| {
|
||||
let Ok(withdrawals) = state.pending_partial_withdrawals() else {
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"Pending withdrawals not found".to_string(),
|
||||
));
|
||||
};
|
||||
|
||||
Ok((withdrawals.clone(), execution_optimistic, finalized))
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(api_types::ExecutionOptimisticFinalizedResponse {
|
||||
data,
|
||||
execution_optimistic: Some(execution_optimistic),
|
||||
finalized: Some(finalized),
|
||||
})
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
// GET beacon/headers
|
||||
//
|
||||
// Note: this endpoint only returns information about blocks in the canonical chain. Given that
|
||||
@@ -4667,6 +4733,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.uor(get_beacon_state_committees)
|
||||
.uor(get_beacon_state_sync_committees)
|
||||
.uor(get_beacon_state_randao)
|
||||
.uor(get_beacon_state_pending_deposits)
|
||||
.uor(get_beacon_state_pending_partial_withdrawals)
|
||||
.uor(get_beacon_headers)
|
||||
.uor(get_beacon_headers_block_id)
|
||||
.uor(get_beacon_block)
|
||||
|
||||
Reference in New Issue
Block a user