Merge pull request #443 from TheSerapher/issue-432
Get rid of Orphan transaction types
This commit is contained in:
commit
ab620f1fe0
@ -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");
|
||||
|
||||
@ -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_<type>
|
||||
* @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");
|
||||
|
||||
@ -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}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
@ -67,11 +61,9 @@
|
||||
<tbody style="font-size:12px;">
|
||||
{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}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<td>{$TRANSACTIONS[transaction].id}</td>
|
||||
@ -117,12 +109,7 @@
|
||||
<tbody style="font-size:12px;">
|
||||
{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}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<td>{$TRANSACTIONS[transaction].id}</td>
|
||||
<td>{$TRANSACTIONS[transaction].timestamp}</td>
|
||||
@ -131,7 +118,7 @@
|
||||
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}</td>
|
||||
<td><font color="{if $TRANSACTIONS[transaction].type == 'Orphan_Credit' or $TRANSACTIONS[transaction].type == 'Orphan_Bonus'}green{else}red{/if}">{$TRANSACTIONS[transaction].amount|number_format:"8"}</td>
|
||||
</tr>
|
||||
{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`"}
|
||||
|
||||
@ -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}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
@ -74,11 +68,7 @@
|
||||
<tbody style="font-size:12px;">
|
||||
{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}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<td>{$TRANSACTIONS[transaction].id}</td>
|
||||
@ -118,12 +108,7 @@
|
||||
<tbody style="font-size:12px;">
|
||||
{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}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<td>{$TRANSACTIONS[transaction].id}</td>
|
||||
|
||||
@ -67,6 +67,7 @@
|
||||
<tr><td colspan="2"><b><u>{$GLOBAL.config.currency} Account Balance</u></b></td></tr>
|
||||
<tr><td>Confirmed</td><td class="right"><b>{$GLOBAL.userdata.balance.confirmed|default:"0"}</td></tr>
|
||||
<tr><td>Unconfirmed</td><td class="right"><b>{$GLOBAL.userdata.balance.unconfirmed|default:"0"}</td></tr>
|
||||
<tr><td>Orphaned</td><td class="right"><b>{$GLOBAL.userdata.balance.orphaned|default:"0"}</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="bendl"></div>
|
||||
|
||||
@ -62,6 +62,7 @@
|
||||
<tr><td colspan="2"><b><u>{$GLOBAL.config.currency} Account Balance</u></b></td></tr>
|
||||
<tr><td>Confirmed</td><td class="right"><b>{$GLOBAL.userdata.balance.confirmed|default:"0"}</td></tr>
|
||||
<tr><td>Unconfirmed</td><td class="right"><b>{$GLOBAL.userdata.balance.unconfirmed|default:"0"}</td></tr>
|
||||
<tr><td>Orphaned</td><td class="right"><b>{$GLOBAL.userdata.balance.orphaned|default:"0"}</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="bendl"></div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user