/** * @param $coinSymbol * @return \BitWasp\Bitcoin\Network\Network * @throws \Exception */ public static function getNetwork($coinSymbol) { CoinSymbolValidator::validate($coinSymbol, 'coinSymbol'); $network = null; switch ($coinSymbol) { case 'btc': $network = NetworkFactory::bitcoin(); break; case 'btc-testnet': $network = NetworkFactory::bitcoinTestnet(); break; case 'ltc': $network = NetworkFactory::litecoin(); break; case 'doge': $network = NetworkFactory::create('1e', '16', '9e')->setHDPubByte('02fd3929')->setHDPrivByte('02fd3955')->setNetMagicBytes('c0c0c0c0'); break; case 'uro': // NetMagicBytes: https://github.com/urocoin/uro/blob/319de97bbd56a10a3b2dca5b36be0c7a9c6603ae/src/main.cpp#L3233 throw new \Exception("Unsupported coin symbol: {$coinSymbol}"); break; case 'bcy': // TODO: check ef, 043587cf, 04358394, d9b4bef9 values // not used for the time being $network = NetworkFactory::create('1b', '1f', 'ef', true)->setHDPubByte('043587cf')->setHDPrivByte('04358394')->setNetMagicBytes('d9b4bef9'); break; default: throw new \Exception("Unsupported coin symbol: {$coinSymbol} by php-client"); } return $network; }
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); }
public static function getDefaultNetwork() { return NetworkFactory::bitcoin(); }
/** * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure * @expectedException \RuntimeException * @expectedExceptionMessage */ public function testInvalidBytes() { $v = '60002'; $services = Buffer::hex('0000000000000001'); $time = '123456789'; $recipient = new NetworkAddress(Buffer::hex('0000000000000001'), '10.0.0.1', '8332'); $sender = new NetworkAddress(Buffer::hex('0000000000000001'), '10.0.0.2', '8332'); $userAgent = new Buffer("/Satoshi:0.7.2/"); $lastBlock = '212672'; $random = new Random(); $nonce = $random->bytes(8)->getInt(); $version = new Version($v, $services, $time, $recipient, $sender, $nonce, $userAgent, $lastBlock, true); $bitcoin = new NetworkMessageSerializer(NetworkFactory::bitcoin()); $serialized = $version->getNetworkMessage(NetworkFactory::viacoinTestnet())->getBuffer(); $bitcoin->parse($serialized); }