Ejemplo n.º 1
0
 /**
  * @param BufferInterface $hash
  * @return int
  */
 public function getHeightFromHash(BufferInterface $hash)
 {
     if (!$this->containsHash($hash)) {
         throw new \RuntimeException('Hash not found');
     }
     return $this->view->getHeightFromHash($hash);
 }
Ejemplo n.º 2
0
 /**
  * @param ChainViewInterface $headerChain
  * @param BufferInterface $startHash
  * @throws \RuntimeException
  * @throws \Exception
  * @return Inventory[]
  */
 private function relativeNextInventory(ChainViewInterface $headerChain, BufferInterface $startHash)
 {
     if (!$headerChain->containsHash($startHash)) {
         throw new \RuntimeException('Hash not found in this chain');
     }
     $startHeight = $headerChain->getHeightFromHash($startHash) + 1;
     $stopHeight = min($startHeight + self::DOWNLOAD_AMOUNT, $headerChain->getIndex()->getHeight());
     $nInFlight = count($this->inFlight);
     $request = [];
     for ($i = $startHeight; $i < $stopHeight && $nInFlight < self::MAX_IN_FLIGHT; $i++) {
         $request[] = Inventory::block($headerChain->getHashFromHeight($i));
         $nInFlight++;
     }
     return $request;
 }