Exemplo n.º 1
0
 /**
  * @param PeerState $state
  * @param Peer $peer
  * @param Headers $headersMsg
  */
 public function onHeaders(PeerState $state, Peer $peer, Headers $headersMsg)
 {
     $headers = $this->node->headers();
     try {
         $vHeaders = $headersMsg->getHeaders();
         $batch = $headers->prepareBatch($vHeaders);
         $count = count($batch->getIndices());
         if ($count > 0) {
             $headers->applyBatch($batch);
             $view = $batch->getTip();
             $indices = $batch->getIndices();
             $indexLast = end($indices);
             $state->updateBlockAvailability($view, $indexLast->getHash());
             if ($count >= 1999) {
                 $peer->getheaders($view->getHeadersLocator());
             }
         }
         $this->emit('headers', [$state, $peer, $batch]);
     } catch (\Exception $e) {
         $this->debug->log('error.onHeaders', ['error' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
     }
 }
Exemplo n.º 2
0
 /**
  * @param Peer $peer
  * @return PeerState
  */
 public function createState(Peer $peer)
 {
     $peerState = PeerState::create();
     $this->storage->attach($peer, $peerState);
     return $peerState;
 }