/**
  * @param TransactionOutputInterface $txOutput
  * @return OutputBuf
  */
 private function outputToBuf(TransactionOutputInterface $txOutput)
 {
     $output = new OutputBuf();
     $output->setScript($txOutput->getScript()->getBuffer()->getBinary());
     $output->setAmount($txOutput->getValue());
     return $output;
 }
Example #2
0
 /**
  * @return SigValues
  */
 public function serializeSignatures()
 {
     static $emptyScript = null;
     static $emptyWitness = null;
     if (is_null($emptyScript) || is_null($emptyWitness)) {
         $emptyScript = new Script();
         $emptyWitness = new ScriptWitness([]);
     }
     /** @var BufferInterface[] $return */
     $outputType = (new OutputClassifier($this->txOut->getScript()))->classify();
     /** @var SigValues $answer */
     $answer = new SigValues($emptyScript, $emptyWitness);
     $serialized = $this->serializeSimpleSig($outputType, $answer);
     $p2sh = false;
     if (!$serialized && $outputType === OutputClassifier::PAYTOSCRIPTHASH) {
         $p2sh = true;
         $outputType = (new OutputClassifier($this->redeemScript))->classify();
         $serialized = $this->serializeSimpleSig($outputType, $answer);
     }
     if (!$serialized && $outputType === OutputClassifier::WITNESS_V0_KEYHASH) {
         $answer = new SigValues($emptyScript, new ScriptWitness([$this->signatures[0]->getBuffer(), $this->publicKeys[0]->getBuffer()]));
     } else {
         if (!$serialized && $outputType === OutputClassifier::WITNESS_V0_SCRIPTHASH) {
             $outputType = (new OutputClassifier($this->witnessScript))->classify();
             $serialized = $this->serializeSimpleSig($outputType, $answer);
             if ($serialized) {
                 $data = [];
                 foreach ($answer->getScriptSig()->getScriptParser()->decode() as $o) {
                     $data[] = $o->getData();
                 }
                 $data[] = $this->witnessScript->getBuffer();
                 $answer = new SigValues($emptyScript, new ScriptWitness($data));
             }
         }
     }
     if ($p2sh) {
         $answer = new SigValues(ScriptFactory::create($answer->getScriptSig()->getBuffer())->push($this->redeemScript->getBuffer())->getScript(), $answer->getScriptWitness());
     }
     return $answer;
 }
 /**
  * @param TransactionOutputInterface $output
  * @return BufferInterface
  */
 public function serialize(TransactionOutputInterface $output)
 {
     return $this->getTemplate()->write([$output->getValue(), $output->getScript()->getBuffer()]);
 }
Example #4
0
 /**
  * @param ConsensusInterface $consensus
  * @param int $nInput
  * @param TransactionOutputInterface $output
  * @return bool
  */
 public function checkSignature(ConsensusInterface $consensus, $nInput, TransactionOutputInterface $output)
 {
     $witnesses = $this->transaction->getWitnesses();
     $witness = isset($witnesses[$nInput]) ? $witnesses[$nInput] : null;
     return $consensus->verify($this->transaction, $output->getScript(), $nInput, $output->getValue(), $witness);
 }
Example #5
0
 /**
  * @param TransactionOutputInterface $output
  * @return array
  */
 public function convertTxoutToArray(TransactionOutputInterface $output)
 {
     return ['value' => $output->getValue(), 'scriptPubKey' => $output->getScript()->getHex()];
 }
Example #6
0
 /**
  * @param array $array
  * @return $this
  */
 private function replace(array $array)
 {
     $this->output = new TransactionOutput(array_key_exists('value', $array) ? $array['value'] : $this->output->getValue(), array_key_exists('script', $array) ? $array['script'] : $this->output->getScript());
     return $this;
 }