diff --git a/cronjobs/blockupdate.php b/cronjobs/blockupdate.php index 67d106b7..e11063bb 100755 --- a/cronjobs/blockupdate.php +++ b/cronjobs/blockupdate.php @@ -41,7 +41,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $log->logInfo($aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['blockhash'] . "\t" . $aBlock['confirmations'] . " -> " . $aBlockInfo['confirmations']); if ($aTxDetails['details'][0]['category'] == 'orphan') { // We have an orphaned block, we need to invalidate all transactions for this one - if ($transaction->setOrphan($aBlock['id']) && $block->setConfirmations($aBlock['id'], -1)) { + if ($block->setConfirmations($aBlock['id'], -1)) { $log->logInfo(" Block marked as orphan"); } else { $log->logError(" Block became orphaned but unable to update database entries"); diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 2d65657b..d01a6d18 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -48,35 +48,6 @@ class Transaction { return false; } - /** - * Sometimes transactions become orphans when a block associated to them is orphaned - * Updates the transaction types to Orphan_ - * @param block_id int Orphaned block ID - * @return bool - **/ - public function setOrphan($block_id) { - $this->debug->append("STA " . __METHOD__, 4); - $aOrphans = array( - 'Credit' => 'Orphan_Credit', - 'Fee' => 'Orphan_Fee', - 'Donation' => 'Orphan_Donation', - 'Bonus' => 'Orphan_Bonus' - ); - foreach ($aOrphans as $from => $to) { - $stmt = $this->mysqli->prepare(" - UPDATE $this->table - SET type = '$to' - WHERE type = '$from' - AND block_id = ? - "); - if (!($this->checkStmt($stmt) && $stmt->bind_param('i', $block_id) && $stmt->execute())) { - $this->debug->append("Failed to set orphan $from => $to transactions for $block_id"); - return false; - } - } - return true; - } - /** * Get all transactions from start for account_id * @param account_id int Account ID @@ -227,7 +198,8 @@ class Transaction { $stmt = $this->mysqli->prepare(" SELECT ROUND(IFNULL(t1.credit, 0) - IFNULL(t2.debit, 0) - IFNULL(t3.other, 0), 8) AS confirmed, - ROUND(IFNULL(t4.credit, 0) - IFNULL(t5.other, 0), 8) AS unconfirmed + ROUND(IFNULL(t4.credit, 0) - IFNULL(t5.other, 0), 8) AS unconfirmed, + ROUND(IFNULL(t6.credit, 0) - IFNULL(t7.other, 0), 8) AS orphaned FROM ( SELECT sum(t.amount) AS credit @@ -274,10 +246,28 @@ class Transaction { t.type IN ('Donation','Fee') AND b.confirmations < ? ) AND t.account_id = ? - ) AS t5 + ) AS t5, + ( + SELECT sum(t.amount) AS credit + FROM $this->table AS t + LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id + WHERE + t.type IN ('Credit','Bonus') AND b.confirmations = -1 + AND t.account_id = ? + ) AS t6, + ( + SELECT sum(t.amount) AS other + FROM $this->table AS t + LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id + WHERE + ( + t.type IN ('Donation','Fee') AND b.confirmations = -1 + ) + AND t.account_id = ? + ) AS t7 "); if ($this->checkStmt($stmt)) { - $stmt->bind_param("iiiiiiiii", $this->config['confirmations'], $account_id, $account_id, $this->config['confirmations'], $account_id, $this->config['confirmations'], $account_id, $this->config['confirmations'], $account_id); + $stmt->bind_param("iiiiiiiiiii", $this->config['confirmations'], $account_id, $account_id, $this->config['confirmations'], $account_id, $this->config['confirmations'], $account_id, $this->config['confirmations'], $account_id, $account_id, $account_id); if (!$stmt->execute()) { $this->debug->append("Unable to execute statement: " . $stmt->error); $this->setErrorMessage("Fetching balance failed"); diff --git a/public/templates/mmcFE/account/transactions/default.tpl b/public/templates/mmcFE/account/transactions/default.tpl index 160b12e4..4bbe7b4b 100644 --- a/public/templates/mmcFE/account/transactions/default.tpl +++ b/public/templates/mmcFE/account/transactions/default.tpl @@ -17,15 +17,9 @@ {assign var=has_confirmed value=false} {section transaction $TRANSACTIONS} {if ( - (($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus')and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) - or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) - or ($TRANSACTIONS[transaction].type == 'Fee' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) - or $TRANSACTIONS[transaction].type == 'Credit_PPS' - or $TRANSACTIONS[transaction].type == 'Fee_PPS' - or $TRANSACTIONS[transaction].type == 'Donation_PPS' - or $TRANSACTIONS[transaction].type == 'Debit_AP' - or $TRANSACTIONS[transaction].type == 'Debit_MP' - or $TRANSACTIONS[transaction].type == 'TXFee' + ( ( $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus' or $TRANSACTIONS[transaction].type == 'Donation' or $TRANSACTIONS[transaction].type == 'Fee' ) and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations ) + or $TRANSACTIONS[transaction].type == 'Credit_PPS' or $TRANSACTIONS[transaction].type == 'Fee_PPS' or $TRANSACTIONS[transaction].type == 'Donation_PPS' + or $TRANSACTIONS[transaction].type == 'Debit_AP' or $TRANSACTIONS[transaction].type == 'Debit_MP' or $TRANSACTIONS[transaction].type == 'TXFee' )} {assign var=has_credits value=true} @@ -67,11 +61,9 @@ {assign var=has_unconfirmed value=false} {section transaction $TRANSACTIONS} - {if ( - ($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus') and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations - or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) - or ($TRANSACTIONS[transaction].type == 'Fee' and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) - )} + {if + (($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus' or $TRANSACTIONS[transaction].type == 'Donation' or $TRANSACTIONS[transaction].type == 'Fee') and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) + } {assign var=has_unconfirmed value=true} {$TRANSACTIONS[transaction].id} @@ -117,12 +109,7 @@ {assign var=has_orphaned value=false} {section transaction $TRANSACTIONS} - {if ( - $TRANSACTIONS[transaction].type == 'Orphan_Credit' - or $TRANSACTIONS[transaction].type == 'Orphan_Donation' - or $TRANSACTIONS[transaction].type == 'Orphan_Fee' - or $TRANSACTIONS[transaction].type == 'Orphan_Bonus' - )} + {if ($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Fee' or $TRANSACTIONS[transaction].type == 'Donation' or $TRANSACTIONS[transaction].type == 'Bonus') and $TRANSACTIONS[transaction].confirmations == -1} {$TRANSACTIONS[transaction].id} {$TRANSACTIONS[transaction].timestamp} @@ -131,7 +118,7 @@ {if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if} {$TRANSACTIONS[transaction].amount|number_format:"8"} - {if $TRANSACTIONS[transaction].type == 'Orphan_Credit' or $TRANSACTIONS[transaction].type == 'Orphan_Bonus'} + {if $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus'} {assign var="orphan_credits" value="`$orphan_credits|default:"0"+$TRANSACTIONS[transaction].amount`"} {else} {assign var="orphan_debits" value="`$orphan_debits|default:"0"+$TRANSACTIONS[transaction].amount`"} diff --git a/public/templates/mmcFE/admin/transactions/default.tpl b/public/templates/mmcFE/admin/transactions/default.tpl index d611f6d6..aba15f12 100644 --- a/public/templates/mmcFE/admin/transactions/default.tpl +++ b/public/templates/mmcFE/admin/transactions/default.tpl @@ -21,15 +21,9 @@ {assign var=confirmed value=0} {section transaction $TRANSACTIONS} {if ( - (($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus')and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) - or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) - or ($TRANSACTIONS[transaction].type == 'Fee' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) - or $TRANSACTIONS[transaction].type == 'Credit_PPS' - or $TRANSACTIONS[transaction].type == 'Fee_PPS' - or $TRANSACTIONS[transaction].type == 'Donation_PPS' - or $TRANSACTIONS[transaction].type == 'Debit_AP' - or $TRANSACTIONS[transaction].type == 'Debit_MP' - or $TRANSACTIONS[transaction].type == 'TXFee' + ( ( $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus' or $TRANSACTIONS[transaction].type == 'Donation' or $TRANSACTIONS[transaction].type == 'Fee' ) and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations ) + or $TRANSACTIONS[transaction].type == 'Credit_PPS' or $TRANSACTIONS[transaction].type == 'Fee_PPS' or $TRANSACTIONS[transaction].type == 'Donation_PPS' + or $TRANSACTIONS[transaction].type == 'Debit_AP' or $TRANSACTIONS[transaction].type == 'Debit_MP' or $TRANSACTIONS[transaction].type == 'TXFee' )} {assign var=confirmed value=1} @@ -74,11 +68,7 @@ {assign var=unconfirmed value=0} {section transaction $TRANSACTIONS} - {if ( - ($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus') and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations - or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) - or ($TRANSACTIONS[transaction].type == 'Fee' and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) - )} + {if ($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus' or $TRANSACTIONS[transaction].type == 'Donation' or $TRANSACTIONS[transaction].type == 'Fee') and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations} {assign var=unconfirmed value=1} {$TRANSACTIONS[transaction].id} @@ -118,12 +108,7 @@ {assign var=orphaned value=0} {section transaction $TRANSACTIONS} - {if ( - $TRANSACTIONS[transaction].type == 'Orphan_Credit' - or $TRANSACTIONS[transaction].type == 'Orphan_Donation' - or $TRANSACTIONS[transaction].type == 'Orphan_Fee' - or $TRANSACTIONS[transaction].type == 'Orphan_Bonus' - )} + {if ($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Fee' or $TRANSACTIONS[transaction].type == 'Donation' or $TRANSACTIONS[transaction].type == 'Bonus') and $TRANSACTIONS[transaction].confirmations == -1} {assign var=orphaned value=1} {$TRANSACTIONS[transaction].id} diff --git a/public/templates/mmcFE/global/sidebar_pplns.tpl b/public/templates/mmcFE/global/sidebar_pplns.tpl index deb0c1cc..79ffec8a 100644 --- a/public/templates/mmcFE/global/sidebar_pplns.tpl +++ b/public/templates/mmcFE/global/sidebar_pplns.tpl @@ -67,6 +67,7 @@ {$GLOBAL.config.currency} Account Balance Confirmed{$GLOBAL.userdata.balance.confirmed|default:"0"} Unconfirmed{$GLOBAL.userdata.balance.unconfirmed|default:"0"} + Orphaned{$GLOBAL.userdata.balance.orphaned|default:"0"}
diff --git a/public/templates/mmcFE/global/sidebar_prop.tpl b/public/templates/mmcFE/global/sidebar_prop.tpl index 09159318..c19c429d 100644 --- a/public/templates/mmcFE/global/sidebar_prop.tpl +++ b/public/templates/mmcFE/global/sidebar_prop.tpl @@ -62,6 +62,7 @@ {$GLOBAL.config.currency} Account Balance Confirmed{$GLOBAL.userdata.balance.confirmed|default:"0"} Unconfirmed{$GLOBAL.userdata.balance.unconfirmed|default:"0"} + Orphaned{$GLOBAL.userdata.balance.orphaned|default:"0"}