Merge pull request #893 from TheSerapher/issue-872

Issue 872
This commit is contained in:
Sebastian Grewe 2013-12-03 01:10:35 -08:00
commit 288c2dd866
7 changed files with 32 additions and 24 deletions

View File

@ -66,14 +66,14 @@ if (! empty($users)) {
// Send balance, fees are reduced later by RPC Server
try {
$bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance - $config['txfee']);
$txid = $bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance - $config['txfee']);
} catch (BitcoinClientException $e) {
$log->logError('Failed to send requested balance to coin address, please check payout process');
continue;
}
// Create transaction record
if ($transaction->addTransaction($aUserData['id'], $dBalance - $config['txfee'], 'Debit_AP', NULL, $aUserData['coin_address']) && $transaction->addTransaction($aUserData['id'], $config['txfee'], 'TXFee', NULL, $aUserData['coin_address'])) {
if ($transaction->addTransaction($aUserData['id'], $dBalance - $config['txfee'], 'Debit_AP', NULL, $aUserData['coin_address'], $txid) && $transaction->addTransaction($aUserData['id'], $config['txfee'], 'TXFee', NULL, $aUserData['coin_address'])) {
// Mark all older transactions as archived
if (!$transaction->setArchived($aUserData['id'], $transaction->insert_id))
$log->logError('Failed to mark transactions for user #' . $aUserData['id'] . ' prior to #' . $transaction->insert_id . ' as archived');

View File

@ -64,13 +64,13 @@ if (count($aPayouts) > 0) {
continue;
}
try {
$bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee']);
$txid = $bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee']);
} catch (BitcoinClientException $e) {
$log->logError('Failed to send requested balance to coin address, please check payout process');
continue;
}
if ($transaction->addTransaction($aData['account_id'], $dBalance - $config['txfee'], 'Debit_MP', NULL, $aData['coin_address']) && $transaction->addTransaction($aData['account_id'], $config['txfee'], 'TXFee', NULL, $aData['coin_address'])) {
if ($transaction->addTransaction($aData['account_id'], $dBalance - $config['txfee'], 'Debit_MP', NULL, $aData['coin_address'], $txid) && $transaction->addTransaction($aData['account_id'], $config['txfee'], 'TXFee', NULL, $aData['coin_address'])) {
// Mark all older transactions as archived
if (!$transaction->setArchived($aData['account_id'], $transaction->insert_id))
$log->logError('Failed to mark transactions for #' . $aData['account_id'] . ' prior to #' . $transaction->insert_id . ' as archived');
@ -82,7 +82,8 @@ if (count($aPayouts) > 0) {
if (!$notification->sendNotification($aData['account_id'], 'manual_payout', $aMailData))
$log->logError('Failed to send notification email to users address: ' . $aMailData['email']);
} else {
$log->logError('Failed to add new Debit_MP transaction in database for user ' . $user->getUserName($aData['account_id']));
$log->logFatal('Failed to add new Debit_MP transaction in database for user ' . $user->getUserName($aData['account_id']));
$monitoring->endCronjob($cron_name, 'E0064', 1, true);
}
}

View File

@ -18,9 +18,9 @@ class Transaction extends Base {
* @param coin_address string Coin address for this transaction [optional]
* @return bool
**/
public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL) {
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address) VALUES (?, ?, ?, ?, ?)");
if ($this->checkStmt($stmt) && $stmt->bind_param("idiss", $account_id, $amount, $block_id, $type, $coin_address) && $stmt->execute()) {
public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL, $txid=NULL) {
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address, txid) VALUES (?, ?, ?, ?, ?, ?)");
if ($this->checkStmt($stmt) && $stmt->bind_param("idisss", $account_id, $amount, $block_id, $type, $coin_address, $txid) && $stmt->execute()) {
$this->insert_id = $stmt->insert_id;
return true;
}
@ -109,6 +109,7 @@ class Transaction extends Base {
t.amount AS amount,
t.coin_address AS coin_address,
t.timestamp AS timestamp,
t.txid AS txid,
b.height AS height,
b.blockhash AS blockhash,
b.confirmations AS confirmations

View File

@ -67,4 +67,5 @@ $aErrorCodes['E0060'] = 'Failed to add new worker';
$aErrorCodes['E0061'] = 'Failed to delete worker';
$aErrorCodes['E0062'] = 'Block has no share_id, not running payouts';
$aErrorCodes['E0063'] = 'Upstream share already assigned to previous block';
$aErrorCodes['E0064'] = 'Failed to create transaction record';
?>

View File

@ -68,14 +68,15 @@
<table cellspacing="0" class="tablesorter" width="100%">
<thead>
<tr>
<th align="center">TX #</th>
<th >Account</th>
<th >Date</th>
<th >TX Type</th>
<th align="center">ID</th>
<th>Account</th>
<th>Date</th>
<th>TX Type</th>
<th align="center">Status</th>
<th >Payment Address</th>
<th >Block #</th>
<th >Amount</th>
<th>Payment Address</th>
<th>TX #</th>
<th>Block #</th>
<th>Amount</th>
</tr>
</thead>
<tbody style="font-size:12px;">
@ -97,7 +98,8 @@
{else if $TRANSACTIONS[transaction].confirmations == -1}<span class="orphan">Orphaned</span>
{else}<span class="unconfirmed">Unconfirmed</span>{/if}
</td>
<td>{$TRANSACTIONS[transaction].coin_address}</td>
<td>{$TRANSACTIONS[transaction].coin_address|truncate:20:"...":true:true}</td>
<td>{$TRANSACTIONS[transaction].txid|truncate:20:"...":true:true}</td>
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}<a href="{$smarty.server.PHP_SELF}?page=statistics&action=round&height={$TRANSACTIONS[transaction].height}">{$TRANSACTIONS[transaction].height}</a>{/if}</td>
<td><font color="{if $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Credit_PPS' or $TRANSACTIONS[transaction].type == 'Bonus'}green{else}red{/if}">{$TRANSACTIONS[transaction].amount|number_format:"8"}</td>
</tr>

View File

@ -75,14 +75,15 @@
<table cellspacing="0" class="tablesorter" width="100%">
<thead>
<tr>
<th align="center">TX #</th>
<th >Account</th>
<th >Date</th>
<th >TX Type</th>
<th align="center">ID</th>
<th>Account</th>
<th>Date</th>
<th>TX Type</th>
<th align="center">Status</th>
<th >Payment Address</th>
<th >Block #</th>
<th >Amount</th>
<th>Payment Address</th>
<th>TX #</th>
<th>Block #</th>
<th>Amount</th>
</tr>
</thead>
<tbody style="font-size:12px;">
@ -104,7 +105,8 @@
{else if $TRANSACTIONS[transaction].confirmations == -1}<span class="orphan">Orphaned</span>
{else}<span class="unconfirmed">Unconfirmed</span>{/if}
</td>
<td>{$TRANSACTIONS[transaction].coin_address}</td>
<td>{$TRANSACTIONS[transaction].coin_address|truncate:20:"...":true:true}</td>
<td>{$TRANSACTIONS[transaction].txid|truncate:20:"...":true:true}</td>
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}<a href="{$smarty.server.PHP_SELF}?page=statistics&action=round&height={$TRANSACTIONS[transaction].height}">{/if}{$TRANSACTIONS[transaction].height}</a></td>
<td><font color="{if $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Credit_PPS' or $TRANSACTIONS[transaction].type == 'Bonus'}green{else}red{/if}">{$TRANSACTIONS[transaction].amount|number_format:"8"}</td>
</tr>

View File

@ -0,0 +1 @@
ALTER TABLE `transactions` ADD `txid` VARCHAR( 256 ) NULL DEFAULT NULL AFTER `timestamp` ;