/** * @param BlockInterface $block * @param HeaderChainViewInterface $chainView * @param Headers $headers * @param bool $checkSignatures * @param bool $checkSize * @param bool $checkMerkleRoot * @return BlockIndexInterface */ public function accept(BlockInterface $block, HeaderChainViewInterface $chainView, Headers $headers, $checkSignatures = true, $checkSize = true, $checkMerkleRoot = true) { $hash = $block->getHeader()->getHash(); $index = $headers->accept($hash, $block->getHeader(), true); $outpointSerializer = new CachingOutPointSerializer(); $txSerializer = new CachingTransactionSerializer(new TransactionInputSerializer($outpointSerializer)); $blockSerializer = new CachingBlockSerializer($this->math, new BlockHeaderSerializer(), $txSerializer); $utxoSet = new UtxoSet($this->db, $outpointSerializer); $blockData = $this->prepareBatch($block, $txSerializer, $utxoSet); $this->blockCheck->check($block, $txSerializer, $blockSerializer, $checkSize, $checkMerkleRoot)->checkContextual($block, $chainView->getLastBlock()); $forks = $this->prepareForks($chainView, $index); $this->checkBlockData($block, $blockData, $checkSignatures, $forks->getFlags(), $index->getHeight()); $this->db->transaction(function () use($hash, $block, $blockSerializer, $utxoSet, $blockData) { $this->db->insertBlock($hash, $block, $blockSerializer); $utxoSet->applyBlock($blockData); }); $chainView->blocks()->updateTip($index); $forks->next($index); $this->emit('block', [$index, $block, $blockData]); print_r($outpointSerializer->stats()); return $index; }
/** * @param callable $function */ public function transaction(callable $function) { echo __FUNCTION__ . PHP_EOL; $this->db->transaction($function); }