/** * @param PaymentRequestBuf $request * @return bool */ public function checkAgainstRequest(PaymentRequestBuf $request) { $details = new PaymentDetailsBuf(); $details->parse($request->getSerializedPaymentDetails()); $outputs = $details->getOutputsList(); $requirements = []; foreach ($outputs as $out) { if (array_key_exists($out->getScript(), $requirements)) { $requirements[$out->getScript()] += $out->getAmount(); } else { $requirements[$out->getScript()] = $out->getAmount(); } } $parsed = []; // Check that regardless of the other outputs, that each specific output was paid. foreach ($this->getTransactions() as $tx) { foreach ($tx->getOutputs() as $output) { $scriptBin = $output->getScript()->getBinary(); if (array_key_exists($scriptBin, $parsed)) { $parsed[$scriptBin] += $output->getValue(); } else { $parsed[$scriptBin] = $output->getValue(); } } } foreach ($requirements as $script => $value) { if (!array_key_exists($script, $parsed)) { return false; } if ($parsed[$script] < $value) { return false; } } return true; }
/** * @param PaymentRequestBuf $request * @return bool */ public function checkAgainstRequest(PaymentRequestBuf $request) { $details = new PaymentDetailsBuf(); $details->parse($request->getSerializedPaymentDetails()); $outputs = $details->getOutputsList(); $nOutputs = count($outputs); $found = 0; // Check that regardless of the other outputs, that each specific output was paid. foreach ($this->getTransactions()->getTransactions() as $tx) { foreach ($tx->getOutputs()->getOutputs() as $txOut) { foreach (array_keys($outputs) as $index) { // Check the scripts/amounts match if ($txOut->getScript()->getBinary() == $outputs[$index]->getScript() && $txOut->getValue() == $outputs[$index]->getAmount()) { unset($outputs[$index]); if (++$found == $nOutputs) { return true; } } } } } return false; }
/** * @return TransactionOutputInterface[] */ public function getOutputs() { return array_map(function (OutputBuf $outBuf) { return $this->bufToOutput($outBuf); }, $this->details->getOutputsList()); }