コード例 #1
0
ファイル: Verification.php プロジェクト: groupcash/php
 private function inputOutputParity(Transaction $transaction)
 {
     $outputSum = new Fraction(0);
     foreach ($transaction->getOutputs() as $output) {
         if ($output->getValue()->isLessThan(new Fraction(0))) {
             $this->errors[] = 'Negative output value';
         } else {
             if ($output->getValue() == new Fraction(0)) {
                 $this->errors[] = 'Zero output value';
             }
         }
         $outputSum = $outputSum->plus($output->getValue());
     }
     $inputSum = array_reduce($transaction->getInputs(), function (Fraction $sum, Input $input) {
         return $sum->plus($input->getOutput()->getValue());
     }, new Fraction(0));
     if ($inputSum < $outputSum) {
         $this->errors[] = 'Output sum greater than input sum';
     } else {
         if ($inputSum > $outputSum) {
             $this->errors[] = 'Output sum less than input sum';
         }
     }
 }