Пример #1
0
 /**
  * @param OutPointInterface[] $requiredOutpoints
  * @return UtxoInterface[]
  */
 public function fetchView(array $requiredOutpoints)
 {
     try {
         $utxos = [];
         $required = [];
         $cacheHits = [];
         foreach ($requiredOutpoints as $c => $outpoint) {
             $key = $this->outpointSerializer->serialize($outpoint)->getBinary();
             if ($this->set->contains($key)) {
                 list($value, $scriptPubKey) = $this->set->fetch($key);
                 $cacheHits[] = $key;
                 $utxos[] = new Utxo($outpoint, new TransactionOutput($value, new Script(new Buffer($scriptPubKey))));
             } else {
                 $required[] = $outpoint;
             }
         }
         if (empty($required) === false) {
             $utxos = array_merge($utxos, $this->db->fetchUtxoDbList($this->outpointSerializer, $required));
         }
         if ($this->caching) {
             $this->cacheHits = $cacheHits;
         }
         return $utxos;
     } catch (\Exception $e) {
         echo $e->getMessage() . PHP_EOL;
         throw new \RuntimeException('Failed to find UTXOS in set');
     }
 }
 /**
  * @param OutPointInterface $outpoint
  * @return mixed
  */
 public function serialize(OutPointInterface $outpoint)
 {
     if (isset($this->cachedObj[$outpoint])) {
         $this->cached++;
         return $this->cachedObj[$outpoint];
     }
     $buffer = $this->serializer->serialize($outpoint);
     $this->cachedObj[$outpoint] = $buffer;
     $this->cachedStr[$buffer->getBinary()] = $outpoint;
     $this->serialize++;
     return $buffer;
 }
 /**
  * @param TransactionInputInterface $input
  * @return Buffer
  */
 public function serialize(TransactionInputInterface $input)
 {
     return Buffertools::concat($this->outpointSerializer->serialize($input->getOutPoint()), $this->getInputTemplate()->write([$input->getScript()->getBuffer(), $input->getSequence()]));
 }