/// Validates if a header's timestamp is valid.
/// Bitcoin Protocol Rules wiki https://en.bitcoin.it/wiki/Protocol_rules says,
/// "Reject if timestamp is the median time of the last 11 blocks or before"
Validates if a header's timestamp is valid.
Validates if a header ' s timestamp is valid .
fn is_timestamp_valid(store: &impl HeaderStore, header: &BlockHeader) -> bool {
    let mut times = vec![];
    let mut current_header = header;
    for _ in 0..11 {
        if let Some(StoredHeader {
            header: prev_header,
            ..
        }) = store.get_header(&current_header.prev_blockhash)
        {
            times.push(prev_header.time);
            if prev_header.block_hash() == store.get_initial_hash() {
                break;
            }
            current_header = prev_header;
        }
    }
    times.sort_unstable();
    let median = times[times.len() / 2];
    header.time > median
}
fn is_timestamp_valid ( store : & impl HeaderStore , header : & BlockHeader ) -> bool { let mut times = vec ! [ ] ; let mut current_header = header ; for _ in 0 .. 11 { if let Some ( StoredHeader { header : prev_header , .. } ) = store . get_header ( & current_header . prev_blockhash ) { times . push ( prev_header . time ) ; if prev_header . block_hash ( ) == store . get_initial_hash ( ) { break ; } current_header = prev_header ; } } times . sort_unstable ( ) ; let median = times [ times . len ( ) / 2 ] ; header . time > median }
Validates if a header's timestamp is valid.
Validates if a header ' s timestamp is valid .
store
&impl HeaderStore
header
&BlockHeader