tweak confirmation calculation

This commit is contained in:
Akinwale Ariwodola 2018-07-26 12:14:48 +01:00
parent 190d998e4c
commit b91b3681d3

View file

@ -464,7 +464,7 @@ class MainController extends AppController {
$maxBlock = $this->Blocks->find()->select(['Height'])->order(['Height' => 'desc'])->first(); $maxBlock = $this->Blocks->find()->select(['Height'])->order(['Height' => 'desc'])->first();
$block = $this->Blocks->find()->select(['Confirmations', 'Height'])->where(['Hash' => $tx->BlockHash])->first(); $block = $this->Blocks->find()->select(['Confirmations', 'Height'])->where(['Hash' => $tx->BlockHash])->first();
$confirmations = $block ? max(1, $maxBlock->Height - $block->Height) : '0'; $confirmations = $block ? (($maxBlock->Height - $block->Height) + 1) : '0';
$inputs = $this->Inputs->find()->contain(['InputAddresses'])->where(['TransactionId' => $tx->Id])->order(['PrevoutN' => 'asc'])->toArray(); $inputs = $this->Inputs->find()->contain(['InputAddresses'])->where(['TransactionId' => $tx->Id])->order(['PrevoutN' => 'asc'])->toArray();
$outputs = $this->Outputs->find()->contain(['OutputAddresses', 'SpendInput' => ['fields' => ['Id', 'TransactionHash', 'PrevoutN', 'PrevoutHash']]])->where(['Outputs.TransactionId' => $tx->Id])->order(['Vout' => 'asc'])->toArray(); $outputs = $this->Outputs->find()->contain(['OutputAddresses', 'SpendInput' => ['fields' => ['Id', 'TransactionHash', 'PrevoutN', 'PrevoutHash']]])->where(['Outputs.TransactionId' => $tx->Id])->order(['Vout' => 'asc'])->toArray();
for ($i = 0; $i < count($outputs); $i++) { for ($i = 0; $i < count($outputs); $i++) {
@ -601,7 +601,7 @@ class MainController extends AppController {
$stmt = $conn->execute(sprintf( $stmt = $conn->execute(sprintf(
'SELECT T.Id, T.Hash, T.InputCount, T.OutputCount, T.Value, ' . 'SELECT T.Id, T.Hash, T.InputCount, T.OutputCount, T.Value, ' .
' TA.DebitAmount, TA.CreditAmount, ' . ' TA.DebitAmount, TA.CreditAmount, ' .
' B.Height, (CASE WHEN B.Height IS NOT NULL THEN GREATEST(1, ' . $currentHeight . ' - B.Height) ELSE NULL END) AS Confirmations, ' . ' B.Height, (CASE WHEN B.Height IS NOT NULL THEN ((' . $currentHeight . ' - B.Height) + 1) ELSE NULL END) AS Confirmations, ' .
' IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' . ' IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' .
'FROM Transactions T ' . 'FROM Transactions T ' .
'LEFT JOIN Blocks B ON T.BlockHash = B.Hash ' . 'LEFT JOIN Blocks B ON T.BlockHash = B.Hash ' .