コード例 #1
0
ファイル: ZmqScriptCheck.php プロジェクト: sbwdlihao/node-php
 /**
  * @param UtxoView $utxoView
  * @param TransactionInterface $tx
  * @param Flags $flags
  * @return bool
  */
 public function check(UtxoView $utxoView, TransactionInterface $tx, Flags $flags)
 {
     $scripts = [];
     foreach ($tx->getInputs() as $input) {
         $scripts[] = $utxoView->fetchByInput($input)->getOutput()->getScript()->getHex();
     }
     return $this->dispatch($tx, $flags, $scripts);
 }
コード例 #2
0
ファイル: ScriptCheck.php プロジェクト: sbwdlihao/node-php
 /**
  * @param UtxoView $utxoView
  * @param TransactionInterface $tx
  * @param Flags $flags
  * @return bool
  */
 public function check(UtxoView $utxoView, TransactionInterface $tx, Flags $flags)
 {
     $result = true;
     $consensus = $this->consensus->getConsensus($flags);
     for ($i = 0, $c = count($tx->getInputs()); $i < $c; $i++) {
         $result &= $consensus->verify($tx, $utxoView->fetchByInput($tx->getInput($i))->getOutput()->getScript(), $i);
     }
     return $result;
 }
コード例 #3
0
ファイル: BlockCheck.php プロジェクト: sbwdlihao/node-php
 /**
  * @param UtxoView $view
  * @param TransactionInterface $tx
  * @param $spendHeight
  * @return bool
  */
 public function checkContextualInputs(UtxoView $view, TransactionInterface $tx, $spendHeight)
 {
     $valueIn = 0;
     for ($i = 0; $i < count($tx->getInputs()); $i++) {
         $utxo = $view->fetchByInput($tx->getInput($i));
         /*if ($out->isCoinbase()) {
               // todo: cb / height
               if ($spendHeight - $out->getHeight() < $this->params->coinbaseMaturityAge()) {
                   return false;
               }
           }*/
         $value = $utxo->getOutput()->getValue();
         $valueIn = $this->math->add($value, $valueIn);
         if (!$this->consensus->checkAmount($valueIn) || !$this->consensus->checkAmount($value)) {
             throw new \RuntimeException('CheckAmount failed for inputs value');
         }
     }
     $valueOut = 0;
     foreach ($tx->getOutputs() as $output) {
         $valueOut = $this->math->add($output->getValue(), $valueOut);
         if (!$this->consensus->checkAmount($valueOut) || !$this->consensus->checkAmount($output->getValue())) {
             throw new \RuntimeException('CheckAmount failed for outputs value');
         }
     }
     if ($this->math->cmp($valueIn, $valueOut) < 0) {
         throw new \RuntimeException('Value-in is less than value out');
     }
     $fee = $this->math->sub($valueIn, $valueOut);
     if ($this->math->cmp($fee, 0) < 0) {
         throw new \RuntimeException('Fee is less than zero');
     }
     if (!$this->consensus->checkAmount($fee)) {
         throw new \RuntimeException('CheckAmount failed for fee');
     }
     return true;
 }