예제 #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 Parser $parser
  * @return TransactionInput
  * @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange
  */
 public function fromParser(Parser $parser)
 {
     $outpoint = $this->outpointSerializer->fromParser($parser);
     /**
      * @var Buffer $scriptBuf
      * @var int|string $sequence
      */
     list($scriptBuf, $sequence) = $this->getInputTemplate()->parse($parser);
     return new TransactionInput($outpoint, new Script($scriptBuf), $sequence);
 }
 /**
  * @param Parser $parser
  * @return array|OutPointInterface
  */
 public function fromParser(Parser $parser)
 {
     $buffer = $parser->getBuffer();
     if ($buffer->getSize() > 36) {
         $buffer = $buffer->slice(0, 36);
         if (isset($this->cachedStr[$buffer->getBinary()])) {
             $this->cached++;
             return $this->cachedStr[$buffer->getBinary()];
         }
     }
     $parsed = $this->serializer->fromParser($parser);
     $this->parse++;
     return $parsed;
 }