/** * @param PeerState $state * @param Peer $peer * @param GetHeaders $getHeaders */ public function onGetHeaders(PeerState $state, Peer $peer, GetHeaders $getHeaders) { return; $chain = $this->node->chain(); if ($chain->getIndex()->getHeader()->getTimestamp() >= time() - 60 * 60 * 24) { $locator = $getHeaders->getLocator(); if (count($locator->getHashes()) === 0) { $start = $locator->getHashStop(); } else { $start = $this->db->findFork($chain, $locator); } $headers = $this->db->fetchNextHeaders($start); $peer->headers($headers); $this->debug->log('peer.sentheaders', ['count' => count($headers), 'start' => $start->getHex()]); } }
/** * @param PeerState $state * @param Peer $peer * @param Block $blockMsg */ public function onBlock(PeerState $state, Peer $peer, Block $blockMsg) { $best = $this->node->chain(); $headerIdx = $this->node->headers(); $blockIndex = $this->node->blocks(); $checkSignatures = (bool) $this->config->getItem('config', 'check_signatures', true); $checkSize = (bool) $this->config->getItem('config', 'check_block_size', true); $checkMerkleRoot = (bool) $this->config->getItem('config', 'check_merkle_root', true); try { $index = $blockIndex->accept($blockMsg->getBlock(), $best, $headerIdx, $checkSignatures, $checkSize, $checkMerkleRoot); $this->blockDownload->received($best, $peer, $index->getHash()); } catch (\Exception $e) { $header = $blockMsg->getBlock()->getHeader(); $this->node->emit('event', ['error.onBlock', ['ip' => $peer->getRemoteAddress()->getIp(), 'hash' => $header->getHash()->getHex(), 'error' => $e->getMessage() . PHP_EOL . $e->getTraceAsString()]]); } }
/** * @param NodeInterface $node * @param array $params * @return array */ public function execute(NodeInterface $node, array $params) { if (strlen($params[self::PARAM_HASH]) !== 64) { throw new \RuntimeException('Invalid hash'); } $index = $node->chain()->fetchIndex(Buffer::hex($params[self::PARAM_HASH])); return ['header' => $this->convertIndexToArray($index)]; }
/** * @param NodeInterface $node * @param array $params * @return array */ public function execute(NodeInterface $node, array $params) { if (!is_int($params[self::PARAM_HEIGHT])) { throw new \RuntimeException('Invalid height'); } $chain = $node->chain(); $hash = $chain->getHashFromHeight($params[self::PARAM_HEIGHT]); return ['hash' => $hash->getHex()]; }
/** * @param NodeInterface $node * @param array $params * @return array */ public function execute(NodeInterface $node, array $params) { if (strlen($params[self::PARAM_TXID]) !== 64) { throw new \RuntimeException('Invalid txid field'); } $txid = Buffer::hex($params[self::PARAM_TXID], 32); $tx = $node->chain()->fetchTransaction($node->transactions(), $txid); return ['tx' => $this->convertTransactionToArray($tx)]; }
/** * @param PeerState $state * @param Peer $peer */ public function onOutboundPeer(PeerState $state, Peer $peer) { $chain = $this->node->chain(); $height = $chain->getIndex()->getHeight(); $peer->getheaders($chain->getLocator($height)); }