public function testHashIsSerializedInReverseOrder() { $buffer = Buffer::hex('0001020300010203000102030001020300010203000102030001020300010203'); $inv = Inventory::block($buffer); $results = unpack("Vtype/H64hash", $inv->getBinary()); $parsedBuffer = Buffer::hex($results['hash']); $this->assertEquals($buffer->getHex(), Buffertools::flipBytes($parsedBuffer)->getHex()); }
/** * @param ChainViewInterface $headerChain * @param BufferInterface $startHash * @throws \RuntimeException * @throws \Exception * @return Inventory[] */ private function relativeNextInventory(ChainViewInterface $headerChain, BufferInterface $startHash) { if (!$headerChain->containsHash($startHash)) { throw new \RuntimeException('Hash not found in this chain'); } $startHeight = $headerChain->getHeightFromHash($startHash) + 1; $stopHeight = min($startHeight + self::DOWNLOAD_AMOUNT, $headerChain->getIndex()->getHeight()); $nInFlight = count($this->inFlight); $request = []; for ($i = $startHeight; $i < $stopHeight && $nInFlight < self::MAX_IN_FLIGHT; $i++) { $request[] = Inventory::block($headerChain->getHashFromHeight($i)); $nInFlight++; } return $request; }