Exemplo n.º 1
0
 /**
  * @param ChainState $state
  * @param BlockHeaderInterface[] $headers
  * @return bool
  * @throws \Exception
  */
 public function acceptBatch(ChainState $state, array $headers)
 {
     $tip = $state->getChain();
     $batch = array();
     $startIndex = $tip->getIndex();
     foreach ($headers as $header) {
         if ($tip->containsHash($header->getHash())) {
             continue;
         }
         $prevIndex = $tip->getIndex();
         if ($prevIndex->getHash() !== $header->getPrevBlock()) {
             throw new \RuntimeException('Header mismatch, header.prevBlock does not refer to tip');
         }
         $index = $this->headerCheck->check($header)->checkContextual($state, $header)->makeIndex($prevIndex, $header);
         $tip->updateTip($index);
         $batch[] = $tip->getIndex();
     }
     // Do a batch update of the chain
     if (count($batch) > 0) {
         $this->db->insertIndexBatch($startIndex, $batch);
         unset($batch);
     }
     return true;
 }