コード例 #1
0
ファイル: ChainState.php プロジェクト: sbwdlihao/node-php
 /**
  * @param Buffer|null $hashStop
  * @return BlockLocator
  */
 public function getHeadersLocator(Buffer $hashStop = null)
 {
     echo 'Produce Headers locator (' . $this->chain->getIndex()->getHeight() . ') ' . PHP_EOL;
     $height = $this->chain->getIndex()->getHeight();
     return $this->getLocator($height, $hashStop);
 }
コード例 #2
0
ファイル: Db.php プロジェクト: sbwdlihao/node-php
 /**
  * We use this to help other nodes sync headers. Identify last common
  * hash in our chain
  *
  * @param Chain $activeChain
  * @param BlockLocator $locator
  * @return false|string
  */
 public function findFork(Chain $activeChain, BlockLocator $locator)
 {
     if ($this->debug) {
         echo "db: called findFork\n";
     }
     $hashes = [$activeChain->getIndex()->getHash()];
     foreach ($locator->getHashes() as $hash) {
         $hashes[] = $hash->getHex();
     }
     $placeholders = rtrim(str_repeat('?, ', count($hashes) - 1), ', ');
     $stmt = $this->dbh->prepare("\n            SELECT    node.hash\n            FROM      headerIndex AS node,\n                      headerIndex AS parent\n            WHERE     parent.hash = ? AND node.hash in ({$placeholders})\n            ORDER BY  node.rgt LIMIT 1\n        ");
     if ($stmt->execute($hashes)) {
         $column = $stmt->fetch();
         $stmt->closeCursor();
         return $column['hash'];
     }
     throw new \RuntimeException('Failed to execute findFork');
 }