Ejemplo n.º 1
0
 public function testMethods()
 {
     $loop = new \React\EventLoop\StreamSelectLoop();
     $dns = (new \BitWasp\Bitcoin\Networking\Dns\Factory())->create('8.8.8.8', $loop);
     $network = Bitcoin::getDefaultNetwork();
     $random = new Random();
     $messages = new \BitWasp\Bitcoin\Networking\Messages\Factory($network, $random);
     $factory = new Factory($dns, $messages, $loop);
     $this->assertInstanceOf($this->peerType, $factory->getPeer());
     $services = Buffer::hex('00', 8);
     $address = $factory->getAddress('127.0.0.1', 8332, $services);
     $this->assertInstanceOf($this->addrType, $address);
     $connector = $factory->getConnector();
     $this->assertInstanceOf($this->connType, $connector);
     $server = $factory->getServer();
     $this->assertInstanceOf($this->serverType, $server);
     $locator = $factory->getLocator();
     $this->assertInstanceOf($this->locatorType, $locator);
     $listener = $factory->getListener($server);
     $this->assertInstanceOf($this->listenerType, $listener);
     $handler = $factory->getPacketHandler();
     $this->assertInstanceOf($this->handlerType, $handler);
     $manager = $factory->getManager();
     $this->assertInstanceOf($this->managerType, $manager);
 }
Ejemplo n.º 2
0
 /**
  * @param NetworkAddressInterface $address
  * @return \React\Promise\Promise|\React\Promise\PromiseInterface
  * @throws \Exception
  */
 public function connect(NetworkAddressInterface $address)
 {
     $peer = $this->peerFactory->getPeer();
     if ($this->requestRelay) {
         $peer->requestRelay();
     }
     $deferred = new Deferred();
     $peer->connect($this->peerFactory->getConnector(), $address)->then(function ($peer) use($deferred) {
         $deferred->resolve($peer);
     }, function () use($deferred) {
         $deferred->reject();
     });
     return $deferred->promise();
 }