/** * Create an input for this transaction spending $tx's output, $outputToSpend. * * @param TransactionInterface $tx * @param $outputToSpend * @return $this */ public function spendOutput(TransactionInterface $tx, $outputToSpend) { // Check TransactionOutput exists in $tx $tx->getOutputs()->getOutput($outputToSpend); $this->addInput(new TransactionInput($tx->getTransactionId(), $outputToSpend)); return $this; }
/** * @param TransactionInterface $tx */ private function saveOutputs(TransactionInterface $tx) { $txid = $tx->getTransactionId(); $vout = 0; foreach ($tx->getOutputs()->getOutputs() as $output) { $this->contents->save($this->cacheIndex($txid, $vout), new Utxo($txid, $vout++, $output)); } $this->size += $vout; }
/** * @param Peer $sender * @param TransactionInterface $current */ public function handleTransaction(Peer $sender, TransactionInterface $current) { $hash = $current->getTransactionId(); //echo "TX: $hash\n"; if (!$this->Have($hash)) { $wasMalleated = false; $transaction = $this->fixTransaction($sender, $current, $wasMalleated); $newHash = $transaction->getTransactionId(); if ($wasMalleated) { $this->haveTx[pack("H*", $newHash)] = $transaction; echo "Was malleated: {$hash} - sending to " . (count($this->peers) - 1) . "\n"; foreach ($this->peers as $peer) { if ($sender !== $peer) { $peer->inv([Inventory::tx(Buffer::hex($newHash))]); } } } } else { echo "Already processed? {$hash} \n"; } }