Skip to content

Commit

Permalink
Minro Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
startailcoon committed Jun 8, 2024
1 parent 2d2154e commit 213e701
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Models/Chain/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ function getInputValue(array $inputs):Coin {
$coin = new Coin();

foreach($this->vin as $vin) {
if(!isset($inputs[$vin->txid])) {
$array_key = array_search($vin->txid, array_column($inputs, 'txid'));

if($array_key === false) {
throw new \Exception("Input transaction '{$vin->txid}' not found!");
}

$coin->add($inputs[$vin->txid]->vout[$vin->vout]->value);
$coin->add($inputs[$array_key]->vout[$vin->vout]->value);
}

return $coin;
Expand All @@ -125,11 +127,14 @@ function getInputAddresses(array $inputs):array {
$addresses = array();

foreach($this->vin as $vin) {
if(!isset($inputs[$vin->txid])) {

$array_key = array_search($vin->txid, array_column($inputs, 'txid'));

if($array_key === false) {
throw new \Exception("Input transaction '{$vin->txid}' not found!");
}

$addresses[$inputs[$vin->txid]->vout[$vin->vout]->scriptPubKey->addresses[0]] = $inputs[$vin->txid]->vout[$vin->vout]->scriptPubKey->addresses[0];
$addresses[$inputs[$array_key]->vout[$vin->vout]->scriptPubKey->addresses[0]] = $inputs[$vin->txid]->vout[$vin->vout]->scriptPubKey->addresses[0];
}

return $addresses;
Expand Down

0 comments on commit 213e701

Please sign in to comment.