public function testGetValueIn() { $utxo1 = new Utxo(new OutPoint(new Buffer('a', 32), 0), new TransactionOutput(2, new Script())); $utxo2 = new Utxo(new OutPoint(new Buffer('a', 32), 1), new TransactionOutput(4, new Script())); $utxo3 = new Utxo(new OutPoint(new Buffer('b', 32), 0), new TransactionOutput(1, new Script())); $view = new UtxoView([$utxo1, $utxo2, $utxo3]); $transaction = TransactionFactory::build()->spendOutPoint($utxo1->getOutPoint())->spendOutPoint($utxo2->getOutPoint())->spendOutPoint($utxo3->getOutPoint())->output(5, new Script())->get(); $this->assertEquals(7, $view->getValueIn(Bitcoin::getMath(), $transaction)); $this->assertEquals(2, $view->getFeePaid(Bitcoin::getMath(), $transaction)); }
/** * @param Utxo $utxo */ private function addUtxo(Utxo $utxo) { if (!isset($this->utxo[$utxo->getTransactionId()])) { $this->utxo[$utxo->getTransactionId()] = [$utxo->getVout() => $utxo]; } else { $this->utxo[$utxo->getTransactionId()][$utxo->getVout()] = $utxo; } }
/** * @param Utxo $utxo */ public function cache(Utxo $utxo) { $index = $this->getInternalIndex($utxo->getTransactionId(), $utxo->getVout()); $this->cache->save($index, $utxo, 5 * 60); }
/** * DbUtxo constructor. * @param int $id * @param OutPointInterface $outPoint * @param TransactionOutputInterface $prevOut */ public function __construct($id, OutPointInterface $outPoint, TransactionOutputInterface $prevOut) { $this->id = $id; parent::__construct($outPoint, $prevOut); }
/** * @param Utxo $utxo * @return $this */ public function spendUtxo(Utxo $utxo) { $this->addInput(new TransactionInput($utxo->getTransactionId(), $utxo->getVout())); return $this; }
/** * @param Utxo $utxo */ private function addUtxo(Utxo $utxo) { $this->utxo[$utxo->getOutPoint()->getTxId()->getBinary() . $utxo->getOutPoint()->getVout()] = $utxo; }