pub(crate) fn load(&mut self, headers: Vec<BlockHeader>, tip: BlockHash) {
        let genesis_hash = self.headers[0].0;

        let mut header_map: HashMap<BlockHash, BlockHeader> =
            headers.into_iter().map(|h| (h.block_hash(), h)).collect();
        let mut blockhash = tip;
        let mut new_headers = vec![];
        while blockhash != genesis_hash {
            let header = match header_map.remove(&blockhash) {
                Some(header) => header,
                None => panic!("missing header {} while loading from DB", blockhash),
            };
            blockhash = header.prev_blockhash;
            new_headers.push(header);
        }
        info!("loading {} headers, tip={}", new_headers.len(), tip);
        let new_headers = new_headers.into_iter().rev(); // order by height
        self.update(new_headers.zip(1..).map(NewHeader::from).collect())
    }
/// Load the chain from a collecion of headers, up to the given tip
Load the chain from a collecion of headers, up to the given tip
Load the chain from a collecion of headers up to the given tip
pub(crate) fn load(&mut self, headers: Vec<BlockHeader>, tip: BlockHash) {
        let genesis_hash = self.headers[0].0;
        let mut header_map: HashMap<BlockHash, BlockHeader> =
            headers.into_iter().map(|h| (h.block_hash(), h)).collect();
        let mut blockhash = tip;
        let mut new_headers = vec![];
        while blockhash != genesis_hash {
            let header = match header_map.remove(&blockhash) {
                Some(header) => header,
                None => panic!("missing header {} while loading from DB", blockhash),
            };
            blockhash = header.prev_blockhash;
            new_headers.push(header);
        }
        info!("loading {} headers, tip={}", new_headers.len(), tip);
        let new_headers = new_headers.into_iter().rev(); // order by height
        self.update(new_headers.zip(1..).map(NewHeader::from).collect())
    }
pub ( crate ) fn load ( & mut self , headers : Vec < BlockHeader > , tip : BlockHash ) { let genesis_hash = self . headers [ 0 ] . 0 ; let mut header_map : HashMap < BlockHash , BlockHeader > = headers . into_iter ( ) . map ( | h | ( h . block_hash ( ) , h ) ) . collect ( ) ; let mut blockhash = tip ; let mut new_headers = vec ! [ ] ; while blockhash != genesis_hash { let header = match header_map . remove ( & blockhash ) { Some ( header ) => header , None => panic ! ( " " blockhash ) , } ; blockhash = header . prev_blockhash ; new_headers . push ( header ) ; } info ! ( " " new_headers len ( ) tip ) ; let new_headers = new_headers . into_iter ( ) . rev ( ) ; // order by height self . update ( new_headers . zip ( 1 .. ) . map ( NewHeader :: from ) . collect ( ) ) }
Load the chain from a collecion of headers, up to the given tip
Load the chain from a collecion of headers up to the given tip
&mut self
headers
Vec<BlockHeader>
tip
BlockHash
&mut self
headers
Vec<BlockHeader>
tip
BlockHash