Exemplo n.º 1
0
 /**
  * @param ChainState $state
  * @param ChainCache $chainView
  * @param Peer $peer
  * @param Inventory[] $items
  */
 public function advertised(ChainState $state, ChainCache $chainView, Peer $peer, array $items)
 {
     $chain = $state->getChain();
     $fetch = [];
     $lastUnknown = null;
     foreach ($items as $inv) {
         $hash = $inv->getHash();
         if ($chain->containsHash($hash)) {
             if (!$chainView->containsHash($hash)) {
                 $fetch[] = $inv;
             }
         } else {
             $lastUnknown = $hash;
         }
     }
     if (null !== $lastUnknown) {
         echo "send headers\n";
         $peer->getheaders($state->getHeadersLocator($lastUnknown));
         $this->peerState->fetch($peer)->updateBlockAvailability($state, $lastUnknown);
     }
     if (count($fetch) > 0) {
         echo 'SEND GETDATA:' . count($fetch) . '\\n';
         $peer->getdata($fetch);
     }
 }
Exemplo n.º 2
0
 /**
  * @param Buffer $hash
  * @return BlockIndex
  */
 public function fetchIndex(Buffer $hash)
 {
     if (!$this->chainCache->containsHash($hash)) {
         throw new \RuntimeException('Index by this hash not known');
     }
     return $this->headers->fetch($hash);
 }