예제 #1
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;
 }
예제 #2
0
 public function testGetValueIn()
 {
     $utxo1 = new Utxo(new OutPoint(new Buffer('a', 32), 0), new TransactionOutput(2, new Script()));
     $utxo2 = new Utxo(new OutPoint(new Buffer('a', 32), 1), new TransactionOutput(4, new Script()));
     $utxo3 = new Utxo(new OutPoint(new Buffer('b', 32), 0), new TransactionOutput(1, new Script()));
     $view = new UtxoView([$utxo1, $utxo2, $utxo3]);
     $transaction = TransactionFactory::build()->spendOutPoint($utxo1->getOutPoint())->spendOutPoint($utxo2->getOutPoint())->spendOutPoint($utxo3->getOutPoint())->output(5, new Script())->get();
     $this->assertEquals(7, $view->getValueIn(Bitcoin::getMath(), $transaction));
     $this->assertEquals(2, $view->getFeePaid(Bitcoin::getMath(), $transaction));
 }
예제 #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;
 }
예제 #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;
 }