Exemplo n.º 1
0
 /**
  * BetterNode constructor.
  * @param ConfigProviderInterface $config
  * @param ParamsInterface $params
  * @param DbInterface $db
  */
 public function __construct(ConfigProviderInterface $config, ParamsInterface $params, DbInterface $db)
 {
     $math = Bitcoin::getMath();
     $adapter = Bitcoin::getEcAdapter($math);
     $this->chains = new ChainContainer($math, $params);
     $consensus = new Consensus($math, $params);
     $pow = new ProofOfWork($math, $params);
     $this->headers = new Index\Headers($db, $adapter, $this->chains, $consensus, $pow);
     $this->blocks = new Index\Blocks($db, $config, $adapter, $this->chains, $consensus);
     $this->transactions = new Index\Transactions($db);
     $genesis = $params->getGenesisBlock();
     $this->headers->init($genesis->getHeader());
     $this->blocks->init($genesis);
     $this->db = $db;
     $segments = $this->db->fetchChainSegments();
     foreach ($segments as $segment) {
         $this->chains->addSegment($segment);
     }
     $this->chains->initialize($this->db);
 }
Exemplo n.º 2
0
 /**
  * @param ParamsInterface $params
  * @param LoopInterface $loop
  */
 public function __construct(ParamsInterface $params, LoopInterface $loop)
 {
     echo ' [App] start ' . PHP_EOL;
     $start = microtime(true);
     $math = Bitcoin::getMath();
     $adapter = Bitcoin::getEcAdapter($math);
     $zmq = new ZMQContext($loop);
     $this->initControl($zmq)->initConfig();
     $this->loop = $loop;
     $this->params = $params;
     $this->adapter = $adapter;
     $this->chains = new Chains($adapter);
     $this->inventory = new KnownInventory();
     $this->peerState = new PeerStateCollection();
     $this->peersInbound = new Peers();
     $this->peersOutbound = new Peers();
     $this->netFactory = new NetworkingFactory($loop);
     $this->db = new Db($this->config, false);
     $consensus = new Consensus($math, $params);
     $zmqScript = new ZmqScriptCheck(new \ZMQContext());
     $this->headers = new Index\Headers($this->db, $consensus, $math, new HeaderCheck($consensus, $adapter, new ProofOfWork($math, $params)));
     $this->blocks = new Index\Blocks($this->db, $adapter, $consensus, new BlockCheck($consensus, $adapter, $zmqScript));
     $genesis = $params->getGenesisBlock();
     $this->headers->init($genesis->getHeader());
     $this->blocks->init($genesis);
     $this->initChainState();
     $this->utxo = new Index\UtxoIdx($this->chains, $this->db);
     $this->blockDownload = new BlockDownloader($this->chains, $this->peerState, $this->peersOutbound);
     $this->on('blocks.syncing', function () {
         echo ' [App] ... BLOCKS: syncing' . PHP_EOL;
     });
     $this->on('headers.syncing', function () {
         echo ' [App] ... HEADERS: syncing' . PHP_EOL;
     });
     $this->on('headers.synced', function () {
         echo ' [App] ... HEADERS: synced!' . PHP_EOL;
     });
     echo ' [App] Startup took: ' . (microtime(true) - $start) . ' seconds ' . PHP_EOL;
 }