[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.
This commit is contained in:
Sebastian Grewe 2014-02-27 15:16:28 +01:00
parent 15d448e47e
commit 8d369d5ba4
2 changed files with 5 additions and 3 deletions

View File

@ -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) {

View File

@ -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());
}