Ejemplo n.º 1
0
 public function testFetchByInput()
 {
     $utxo = new Utxo(new OutPoint(new Buffer('a', 32), 0), new TransactionOutput(1, new Script()));
     $wantOutpoint = $utxo->getOutPoint();
     $input = new TransactionInput($wantOutpoint, new Script(), 0);
     $view = new UtxoView([$utxo]);
     $result = $view->fetchByInput($input);
     $this->assertSame($utxo, $result);
 }
Ejemplo n.º 2
0
 /**
  * @param UtxoView $utxoView
  * @param TransactionInterface $tx
  * @return ScriptValidationInterface
  */
 public function queue(UtxoView $utxoView, TransactionInterface $tx)
 {
     for ($i = 0, $c = count($tx->getInputs()); $i < $c; $i++) {
         $output = $utxoView->fetchByInput($tx->getInput($i))->getOutput();
         $witness = isset($tx->getWitnesses()[$i]) ? $tx->getWitness($i) : null;
         $this->results[] = $this->consensus->verify($tx, $output->getScript(), $i, $output->getValue(), $witness);
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * @param UtxoView $utxoView
  * @param TransactionInterface $tx
  * @return ScriptValidationInterface
  */
 public function queue(UtxoView $utxoView, TransactionInterface $tx)
 {
     $hex = $tx->getHex();
     $t = ['txid' => spl_object_hash($tx), 'tx' => $hex, 'scripts' => []];
     for ($i = 0, $c = count($tx->getInputs()); $i < $c; $i++) {
         $output = $utxoView->fetchByInput($tx->getInput($i))->getOutput();
         $witness = isset($tx->getWitnesses()[$i]) ? $tx->getWitness($i) : null;
         $t['scripts'][] = $output->getScript()->getHex();
     }
     $this->results[] = $t;
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * @param UtxoView $view
  * @param TransactionInterface $tx
  * @param int $spendHeight
  * @return $this
  */
 public function checkContextualInputs(UtxoView $view, TransactionInterface $tx, $spendHeight)
 {
     $valueIn = gmp_init(0);
     for ($i = 0, $nInputs = count($tx->getInputs()); $i < $nInputs; $i++) {
         /*if ($out->isCoinbase()) {
               // todo: cb / height
               if ($spendHeight - $out->getHeight() < $this->params->coinbaseMaturityAge()) {
                   return false;
               }
           }*/
         $value = gmp_init($view->fetchByInput($tx->getInput($i))->getOutput()->getValue(), 10);
         $valueIn = $this->math->add($valueIn, $value);
         $this->consensus->checkAmount($valueIn);
     }
     $valueOut = gmp_init(0);
     foreach ($tx->getOutputs() as $output) {
         $valueOut = $this->math->add($valueOut, gmp_init($output->getValue(), 10));
         $this->consensus->checkAmount($valueOut);
     }
     if ($this->math->cmp($valueIn, $valueOut) < 0) {
         throw new \RuntimeException('Value-in is less than value-out');
     }
     $fee = $this->math->sub($valueIn, $valueOut);
     $this->consensus->checkAmount($fee);
     return $this;
 }