fn convert_to_api_response<T: BeaconChainTypes>(
    duties: Vec<Option<AttestationDuty>>,
    indices: &[u64],
    dependent_root: Hash256,
    chain: &BeaconChain<T>,
) -> Result<ApiDuties, warp::reject::Rejection> {
    // Protect against an inconsistent slot clock.
    if duties.len() != indices.len() {
        return Err(warp_utils::reject::custom_server_error(format!(
            "duties length {} does not match indices length {}",
            duties.len(),
            indices.len()
        )));
    }

    let usize_indices = indices.iter().map(|i| *i as usize).collect::<Vec<_>>();
    let index_to_pubkey_map = chain
        .validator_pubkey_bytes_many(&usize_indices)
        .map_err(warp_utils::reject::beacon_chain_error)?;

    let data = duties
        .into_iter()
        .zip(indices)
        .filter_map(|(duty_opt, &validator_index)| {
            let duty = duty_opt?;
            Some(api_types::AttesterData {
                pubkey: *index_to_pubkey_map.get(&(validator_index as usize))?,
                validator_index,
                committees_at_slot: duty.committees_at_slot,
                committee_index: duty.index,
                committee_length: duty.committee_len as u64,
                validator_committee_index: duty.committee_position as u64,
                slot: duty.slot,
            })
        })
        .collect::<Vec<_>>();

    Ok(api_types::DutiesResponse {
        dependent_root,
        data,
    })
}
/// Convert the internal representation of attester duties into the format returned to the HTTP
/// client.
Convert the internal representation of attester duties into the format returned to the HTTP
client.
Convert the internal representation of attester duties into the format returned to the HTTP client .
fn convert_to_api_response<T: BeaconChainTypes>(
    duties: Vec<Option<AttestationDuty>>,
    indices: &[u64],
    dependent_root: Hash256,
    chain: &BeaconChain<T>,
) -> Result<ApiDuties, warp::reject::Rejection> {
    // Protect against an inconsistent slot clock.
    if duties.len() != indices.len() {
        return Err(warp_utils::reject::custom_server_error(format!(
            "duties length {} does not match indices length {}",
            duties.len(),
            indices.len()
        )));
    }
    let usize_indices = indices.iter().map(|i| *i as usize).collect::<Vec<_>>();
    let index_to_pubkey_map = chain
        .validator_pubkey_bytes_many(&usize_indices)
        .map_err(warp_utils::reject::beacon_chain_error)?;
    let data = duties
        .into_iter()
        .zip(indices)
        .filter_map(|(duty_opt, &validator_index)| {
            let duty = duty_opt?;
            Some(api_types::AttesterData {
                pubkey: *index_to_pubkey_map.get(&(validator_index as usize))?,
                validator_index,
                committees_at_slot: duty.committees_at_slot,
                committee_index: duty.index,
                committee_length: duty.committee_len as u64,
                validator_committee_index: duty.committee_position as u64,
                slot: duty.slot,
            })
        })
        .collect::<Vec<_>>();
    Ok(api_types::DutiesResponse {
        dependent_root,
        data,
    })
}
fn convert_to_api_response < T : BeaconChainTypes > ( duties : Vec < Option < AttestationDuty > > , indices : & [ u64 ] , dependent_root : Hash256 , chain : & BeaconChain < T > , ) -> Result < ApiDuties , warp :: reject :: Rejection > { // Protect against an inconsistent slot clock. if duties . len ( ) != indices . len ( ) { return Err ( warp_utils :: reject :: custom_server_error ( format ! ( " " duties len ( ) indices len ( ) ) ) ) ; } let usize_indices = indices . iter ( ) . map ( | i | * i as usize ) . collect :: < Vec < _ > > ( ) ; let index_to_pubkey_map = chain . validator_pubkey_bytes_many ( & usize_indices ) . map_err ( warp_utils :: reject :: beacon_chain_error ) ? ; let data = duties . into_iter ( ) . zip ( indices ) . filter_map ( | ( duty_opt , & validator_index ) | { let duty = duty_opt ? ; Some ( api_types :: AttesterData { pubkey : * index_to_pubkey_map . get ( & ( validator_index as usize ) ) ? , validator_index , committees_at_slot : duty . committees_at_slot , committee_index : duty . index , committee_length : duty . committee_len as u64 , validator_committee_index : duty . committee_position as u64 , slot : duty . slot , } ) } ) . collect :: < Vec < _ > > ( ) ; Ok ( api_types :: DutiesResponse { dependent_root , data , } ) }
Convert the internal representation of attester duties into the format returned to the HTTP
client.
Convert the internal representation of attester duties into the format returned to the HTTP client .
duties
Vec<Option<AttestationDuty>>
indices
&[u64]
dependent_root
Hash256
chain
&BeaconChain<T>