/**
  * @param $i
  * @return \BitWasp\Bitcoin\Block\Block
  */
 public function getBlock($i)
 {
     $blocks = $this->getBlocks();
     $hex = $blocks[$i];
     $b = BlockFactory::fromHex($hex);
     return $b;
 }
Esempio n. 2
0
 public function testBlockSerializer()
 {
     $parser = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
     $txHex = '01000000' . '01' . '0000000000000000000000000000000000000000000000000000000000000000FFFFFFFF' . '4D' . '04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73' . 'FFFFFFFF' . '01' . '00F2052A01000000' . '43' . '4104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC' . '00000000';
     $blockHex = '01000000' . '0000000000000000000000000000000000000000000000000000000000000000' . '3BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A' . '29AB5F49' . 'FFFF001D' . '1DAC2B7C' . '01' . $txHex;
     $newBlock = BlockFactory::fromHex($blockHex);
     $block = new Block($newBlock);
     $serialized = $block->getNetworkMessage()->getBuffer();
     $parsed = $parser->parse($serialized)->getPayload();
     $this->assertEquals($block, $parsed);
 }
 public function testMerkleBlock()
 {
     $factory = new Factory(NetworkFactory::bitcoin(), new Random());
     $hex = '0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196367291b4d4c86041b8fa45d630101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff08044c86041b020a02ffffffff0100f2052a01000000434104ecd3229b0571c3be876feaac0442a9f13c5a572742927af1dc623353ecf8c202225f64868137a18cdd85cbbb4c74fbccfd4f49639cf1bdc94a5672bb15ad5d4cac00000000';
     $block = BlockFactory::fromHex($hex);
     $math = new Math();
     $filter = BloomFilter::create($math, 10, 1.0E-6, 0, new Flags(BloomFilter::UPDATE_ALL));
     $filter->insertHash('63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5');
     // Check that Merkleblock message is serialized correctly
     $filtered = $block->filter($filter);
     $this->assertEquals($block->getHeader(), $filtered->getHeader());
     $merkle = $factory->merkleblock($filtered);
     $serialized = $merkle->getNetworkMessage()->getBuffer();
     $parsed = $factory->parse(new Parser($serialized))->getPayload();
     $this->assertEquals($merkle, $parsed);
 }
Esempio n. 4
0
 /**
  * @param string $blockhash
  * @return \BitWasp\Bitcoin\Block\Block
  */
 public function getblock($blockhash)
 {
     $blockArray = $this->client->execute('getblock', [$blockhash, false]);
     $this->checkNotNull($blockArray);
     return BlockFactory::fromHex($blockArray);
 }