public function testInventoryVector() { $buffer = Buffer::hex('4141414141414141414141414141414141414141414141414141414141414141'); $inv = new Inventory(Inventory::ERROR, $buffer); $this->assertEquals(0, $inv->getType()); $inv = new Inventory(Inventory::MSG_TX, $buffer); $this->assertEquals(1, $inv->getType()); $this->assertTrue($inv->isTx()); $this->assertFalse($inv->isBlock()); $this->assertFalse($inv->isFilteredBlock()); $this->assertFalse($inv->isError()); $inv = new Inventory(Inventory::MSG_BLOCK, $buffer); $this->assertEquals(2, $inv->getType()); $this->assertTrue($inv->isBlock()); $this->assertFalse($inv->isTx()); $this->assertFalse($inv->isError()); $this->assertFalse($inv->isFilteredBlock()); $inv = new Inventory(Inventory::MSG_FILTERED_BLOCK, $buffer); $this->assertEquals(3, $inv->getType()); $this->assertTrue($inv->isFilteredBlock()); $this->assertFalse($inv->isBlock()); $this->assertFalse($inv->isTx()); $this->assertFalse($inv->isError()); $inv = new Inventory(Inventory::ERROR, $buffer); $this->assertTrue($inv->isError()); $this->assertEquals($buffer, $inv->getHash()); }
/** * @param Inventory $inventory * @return bool */ public function checkInventory(Inventory $inventory) { if ($inventory->isBlock()) { //return isset($this->blocks->hashIndex[$inventory->getHash()->getHex()]); } if ($inventory->isTx()) { return $this->db->transactions->fetch($inventory->getHash()->getHex()) !== null; } return true; }
/** * @param Inventory $inv * @return \BitWasp\Buffertools\Buffer */ public function serialize(Inventory $inv) { return $this->getTemplate()->write([$inv->getType(), $inv->getHash()]); }
/** * @param Inventory $inventory * @return bool */ public function check(Inventory $inventory) { return isset($this->storage[$inventory->getHash()->getBinary()]); }