/**
  * @param BlockHeaderInterface $header
  * @return \BitWasp\Buffertools\Buffer
  */
 public function serialize(BlockHeaderInterface $header)
 {
     return $this->getTemplate()->write([$header->getVersion(), Buffer::hex($header->getPrevBlock()), Buffer::hex($header->getMerkleRoot()), $header->getTimestamp(), $header->getBits(), $header->getNonce()]);
 }
Esempio n. 2
0
 /**
  * Creates the Genesis block index
  * @param BlockHeaderInterface $header
  * @return bool
  */
 public function createIndexGenesis(BlockHeaderInterface $header)
 {
     $stmtHeader = $this->dbh->prepare('INSERT INTO headerIndex (
         hash, segment, height, work, version, prevBlock, merkleRoot, nBits, nTimestamp, nNonce
       ) VALUES (
         :hash, :segment, :height, :work, :version, :prevBlock, :merkleRoot, :nBits, :nTimestamp, :nNonce
       )
     ');
     if ($stmtHeader->execute(array('hash' => $header->getHash()->getBinary(), 'segment' => 0, 'height' => 0, 'work' => 0, 'version' => $header->getVersion(), 'prevBlock' => $header->getPrevBlock()->getBinary(), 'merkleRoot' => $header->getMerkleRoot()->getBinary(), 'nBits' => $header->getBits(), 'nTimestamp' => $header->getTimestamp(), 'nNonce' => $header->getNonce()))) {
         return true;
     }
     throw new \RuntimeException('Failed to update insert Genesis block index!');
 }