fn insert_to_block_header_indices(
    block_height_index: &mut BTreeMap<u64, BlockHash>,
    switch_block_era_id_index: &mut BTreeMap<EraId, BlockHash>,
    block_header: &BlockHeader,
) -> Result<(), Error> {
    let block_hash = block_header.hash();
    if let Some(first) = block_height_index.get(&block_header.height()) {
        if *first != block_hash {
            return Err(Error::DuplicateBlockIndex {
                height: block_header.height(),
                first: *first,
                second: block_hash,
            });
        }
    }

    if block_header.is_switch_block() {
        match switch_block_era_id_index.entry(block_header.era_id()) {
            Entry::Vacant(entry) => {
                let _ = entry.insert(block_hash);
            }
            Entry::Occupied(entry) => {
                if *entry.get() != block_hash {
                    return Err(Error::DuplicateEraIdIndex {
                        era_id: block_header.era_id(),
                        first: *entry.get(),
                        second: block_hash,
                    });
                }
            }
        }
    }

    let _ = block_height_index.insert(block_header.height(), block_hash);
    Ok(())
}
/// Inserts the relevant entries to the two indices.
///
/// If a duplicate entry is encountered, neither index is updated and an error is returned.
Inserts the relevant entries to the two indices.
If a duplicate entry is encountered, neither index is updated and an error is returned.
Inserts the relevant entries to the two indices . If a duplicate entry is encountered neither index is updated and an error is returned .
fn insert_to_block_header_indices(
    block_height_index: &mut BTreeMap<u64, BlockHash>,
    switch_block_era_id_index: &mut BTreeMap<EraId, BlockHash>,
    block_header: &BlockHeader,
) -> Result<(), Error> {
    let block_hash = block_header.hash();
    if let Some(first) = block_height_index.get(&block_header.height()) {
        if *first != block_hash {
            return Err(Error::DuplicateBlockIndex {
                height: block_header.height(),
                first: *first,
                second: block_hash,
            });
        }
    }
    if block_header.is_switch_block() {
        match switch_block_era_id_index.entry(block_header.era_id()) {
            Entry::Vacant(entry) => {
                let _ = entry.insert(block_hash);
            }
            Entry::Occupied(entry) => {
                if *entry.get() != block_hash {
                    return Err(Error::DuplicateEraIdIndex {
                        era_id: block_header.era_id(),
                        first: *entry.get(),
                        second: block_hash,
                    });
                }
            }
        }
    }
    let _ = block_height_index.insert(block_header.height(), block_hash);
    Ok(())
}
fn insert_to_block_header_indices ( block_height_index : & mut BTreeMap < u64 , BlockHash > , switch_block_era_id_index : & mut BTreeMap < EraId , BlockHash > , block_header : & BlockHeader , ) -> Result < ( ) , Error > { let block_hash = block_header . hash ( ) ; if let Some ( first ) = block_height_index . get ( & block_header . height ( ) ) { if * first != block_hash { return Err ( Error :: DuplicateBlockIndex { height : block_header . height ( ) , first : * first , second : block_hash , } ) ; } } if block_header . is_switch_block ( ) { match switch_block_era_id_index . entry ( block_header . era_id ( ) ) { Entry :: Vacant ( entry ) => { let _ = entry . insert ( block_hash ) ; } Entry :: Occupied ( entry ) => { if * entry . get ( ) != block_hash { return Err ( Error :: DuplicateEraIdIndex { era_id : block_header . era_id ( ) , first : * entry . get ( ) , second : block_hash , } ) ; } } } } let _ = block_height_index . insert ( block_header . height ( ) , block_hash ) ; Ok ( ( ) ) }
Inserts the relevant entries to the two indices.
Inserts the relevant entries to the two indices .
block_height_index
&mut BTreeMap<u64, BlockHash>
switch_block_era_id_index
&mut BTreeMap<EraId, BlockHash>
block_header
&BlockHeader
block_height_index
&mut BTreeMap<u64, BlockHash>
switch_block_era_id_index
&mut BTreeMap<EraId, BlockHash>
block_header
&BlockHeader