/**
  * @param Version $version
  * @return \BitWasp\Buffertools\Buffer
  */
 public function serialize(Version $version)
 {
     return $this->getTemplate()->write([$version->getVersion(), $version->getServices(), $version->getTimestamp(), $version->getRecipientAddress()->getBuffer(), $version->getSenderAddress()->getBuffer(), $version->getNonce(), $version->getUserAgent(), $version->getStartHeight(), $version->getRelay()]);
 }
Exemplo n.º 2
0
 public function testNetworkSerializer()
 {
     $v = '60002';
     $services = Buffer::hex('0000000000000001');
     $time = (string) time();
     $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);
     $net = Bitcoin::getDefaultNetwork();
     $serializer = new NetworkMessageSerializer($net);
     $serialized = $version->getNetworkMessage()->getBuffer();
     $parsed = $serializer->parse($serialized)->getPayload();
     $this->assertEquals($version, $parsed);
 }
Exemplo n.º 3
0
 /**
  * @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);
 }
 /**
  * @param OutputInterface $output
  * @param $userHost
  * @param Version $version
  */
 private function renderVersion(OutputInterface $output, $userHost, Version $version)
 {
     $output->writeln(' <info>Results of connection to ' . $userHost . "</info>:");
     $output->writeln('   Protocol Version:    ' . $version->getVersion() . "");
     $output->writeln('   User agent:          ' . $version->getUserAgent()->getBinary() . "");
     $services = $version->getServices()->getInt();
     $hasServices = implode(" ", array_map(function ($value) use($services) {
         return $services == constant('\\BitWasp\\Bitcoin\\Networking\\Messages\\Version::' . $value) ? $value : '';
     }, ['NODE_NETWORK', 'NODE_GETUTXOS']));
     $output->writeln('   Services:            ' . $version->getServices()->getInt() . " " . $hasServices);
     $output->writeln('   Requesting relay:    ' . ($version->getRelay() ? 'true' : 'false') . "");
     $output->writeln('   Timestamp:           ' . $version->getTimestamp() . "");
     $output->writeln('   Nonce:               ' . $version->getNonce() . "");
     $output->writeln('   Chain height:        ' . $version->getStartHeight() . "");
     $output->writeln('   Their address:       ' . $version->getSenderAddress()->getIp() . "");
     $output->writeln('   Their port:          ' . $version->getSenderAddress()->getPort() . "");
     $output->writeln('   Our address:         ' . $version->getRecipientAddress()->getIp() . "");
     $output->writeln('   Our port:            ' . $version->getRecipientAddress()->getPort() . "");
 }
Exemplo n.º 5
0
 /**
  * @param BlockLocator $locator
  */
 public function getheaders(BlockLocator $locator)
 {
     $this->send($this->msgs->getheaders($this->localVersion->getVersion(), $locator));
 }