Ejemplo n.º 1
0
 /**
  * @param BlockLocator $blockLocator
  * @return \BitWasp\Buffertools\BufferInterface
  */
 public function serialize(BlockLocator $blockLocator)
 {
     $hashes = [];
     foreach ($blockLocator->getHashes() as $hash) {
         $hashes[] = $hash->flip();
     }
     return $this->getTemplate()->write([$hashes, $blockLocator->getHashStop()]);
 }
Ejemplo n.º 2
0
 /**
  * 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');
 }