From 8d369d5ba4eef7a38894b70811aa8b9e83eeb218 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 27 Feb 2014 15:16:28 +0100 Subject: [PATCH] [IMPROVED] Deduct TXFEE in Transaction CreateDebit No need to deduct the fees on our cronjob, do it automatically in our transaction class when creating a Debit record. --- cronjobs/payouts.php | 4 ++-- public/include/classes/transaction.class.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cronjobs/payouts.php b/cronjobs/payouts.php index e38754a9..23730052 100755 --- a/cronjobs/payouts.php +++ b/cronjobs/payouts.php @@ -85,7 +85,7 @@ if ($setting->getValue('disable_manual_payouts') != 1 && $aManualPayouts) { $monitoring->endCronjob($cron_name, 'E0010', 1, true); } if ($bitcoin->validateaddress($aUserData['coin_address'])) { - if (!$transaction_id = $transaction->createDebitMPRecord($aUserData['id'], $aUserData['coin_address'], $aUserData['confirmed'] - $config['txfee_manual'])) { + if (!$transaction_id = $transaction->createDebitMPRecord($aUserData['id'], $aUserData['coin_address'], $aUserData['confirmed'])) { $log->logFatal(' failed to fullt debit user ' . $aUserData['username'] . ': ' . $transaction->getCronError()); $monitoring->endCronjob($cron_name, 'E0064', 1, true); } else if (!$config['sendmany']['enabled'] || !$sendmanyAvailable) { @@ -168,7 +168,7 @@ if ($setting->getValue('disable_auto_payouts') != 1 && $aAutoPayouts) { $rpc_txid = NULL; $log->logInfo(sprintf($mask, $aUserData['id'], $aUserData['username'], $aUserData['confirmed'], $aUserData['coin_address'], $aUserData['ap_threshold'])); if ($bitcoin->validateaddress($aUserData['coin_address'])) { - if (!$transaction_id = $transaction->createDebitAPRecord($aUserData['id'], $aUserData['coin_address'], $aUserData['confirmed'] - $config['txfee_auto'])) { + if (!$transaction_id = $transaction->createDebitAPRecord($aUserData['id'], $aUserData['coin_address'], $aUserData['confirmed'])) { $log->logFatal(' failed to fully debit user ' . $aUserData['username'] . ': ' . $transaction->getCronError()); $monitoring->endCronjob($cron_name, 'E0064', 1, true); } else if (!$config['sendmany']['enabled'] || !$sendmanyAvailable) { diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index a7f48be2..fab7cf57 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -334,7 +334,9 @@ class Transaction extends Base { return $this->createDebitRecord($account_id, $coin_address, $amount, 'Debit_AP'); } private function createDebitRecord($account_id, $coin_address, $amount, $type) { + // Calculate and deduct txfee from amount $type == 'Debit_MP' ? $txfee = $this->config['txfee_manual'] : $txfee = $this->config['txfee_auto']; + $amount = $amount - $txfee; // Add Debit record if (!$this->addTransaction($account_id, $amount, $type, NULL, $coin_address, NULL)) { $this->setErrorMessage('Failed to create ' . $type . ' transaction record in database'); @@ -366,7 +368,7 @@ class Transaction extends Base { // Notify user via mail $aMailData['email'] = $this->user->getUserEmailById($account_id); $aMailData['subject'] = $type . ' Completed'; - $aMailData['amount'] = $amount - $txfee; + $aMailData['amount'] = $amount; if (!$this->notification->sendNotification($account_id, 'payout', $aMailData)) { $this->setErrorMessage('Failed to send notification email to users address: ' . $aMailData['email'] . 'ERROR: ' . $this->notification->getCronError()); }