/** * */ private function update() { $header = $this->index->getHeader(); // Check all active features if ($header->getTimestamp() >= $this->params->p2shActivateTime()) { $this->p2sh = true; } $hash = $this->index->getHash()->getBinary(); $this->bip30 = !($this->index->getHeight() == 91842 && $hash == pack("H*", "00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec") || $this->index->getHeight() == 91880 && $hash == pack("H*", "00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")); $highest = $this->majorityVersion(); if ($highest >= 2) { $this->bip34 = true; } if ($highest >= 3) { $this->derSig = true; } if ($highest >= 4) { $this->cltv = true; } // Calculate flags $this->flags = $this->p2sh ? InterpreterInterface::VERIFY_NONE : InterpreterInterface::VERIFY_P2SH; if ($this->derSig) { $this->flags |= InterpreterInterface::VERIFY_DERSIG; } if ($this->cltv) { $this->flags |= InterpreterInterface::VERIFY_CHECKLOCKTIMEVERIFY; } }
/** * @param ChainAccessInterface $chain * @param BlockIndexInterface $index * @param BlockIndexInterface $prevIndex * @param Forks $forks * @return $this */ public function checkContextual(ChainAccessInterface $chain, BlockIndexInterface $index, BlockIndexInterface $prevIndex, Forks $forks) { $work = $this->getWorkRequired($chain, $prevIndex); $header = $index->getHeader(); if ($this->math->cmp(gmp_init($header->getBits(), 10), gmp_init($work, 10)) != 0) { throw new \RuntimeException('Headers::CheckContextual(): invalid proof of work : ' . $header->getBits() . '? ' . $work); } if ($header->getVersion() < $forks->getMajorityVersion()) { echo $index->getHash()->getHex() . PHP_EOL; echo "Heaader: " . $header->getVersion() . "\nMajority: " . $forks->getMajorityVersion() . PHP_EOL; throw new \RuntimeException('Rejected version'); } return $this; }
/** * @param BlockIndexInterface $index * @return array */ public function convertIndexToArray(BlockIndexInterface $index) { $header = $index->getHeader(); return ['height' => $index->getHeight(), 'hash' => $index->getHash()->getHex(), 'work' => $index->getWork(), 'version' => $header->getVersion(), 'prevBlock' => $header->getPrevBlock()->getHex(), 'merkleRoot' => $header->getMerkleRoot()->getHex(), 'nBits' => $header->getBits(), 'nTimestamp' => $header->getTimestamp(), 'nNonce' => $header->getNonce()]; }
/** * @param BlockIndexInterface $index * @param BlockInterface $block * @param BlockData $blockData */ public function logBlock(BlockIndexInterface $index, BlockInterface $block, BlockData $blockData) { echo count($blockData->remainingNew) . "created and " . count($blockData->requiredOutpoints) . " destroyed\n"; $this->log('block', ['hash' => $index->getHash()->getHex(), 'height' => $index->getHeight(), 'txs' => count($block->getTransactions()), 'nFees' => gmp_strval($blockData->nFees, 10), 'nSigOps' => $blockData->nSigOps, 'utxos' => ['created' => count($blockData->remainingNew), 'removed' => count($blockData->requiredOutpoints)]]); }