From 213e70180a0c1c9cec2d5a990f7e94333d9f3c46 Mon Sep 17 00:00:00 2001 From: Startail the 'Coon Date: Sat, 8 Jun 2024 09:24:41 +0200 Subject: [PATCH] Minro Fixes --- src/Models/Chain/Transaction.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Models/Chain/Transaction.php b/src/Models/Chain/Transaction.php index dd9831e..6a5c7a7 100644 --- a/src/Models/Chain/Transaction.php +++ b/src/Models/Chain/Transaction.php @@ -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; @@ -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;