From 72d923737f23750b30a4967fc62b78ed1e0d8e16 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 27 Jan 2014 09:25:59 +0100 Subject: [PATCH] [WORKAROUND] Fully debit user before RPC call * First debit the user fully for this transaction * Try the payout RPC call * Fail this so admins can first confirm it worked, then force payouts * Added comment what line to remove if this happens a lot This will further address #1586 --- cronjobs/payouts.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/cronjobs/payouts.php b/cronjobs/payouts.php index cc93eaf9..d44a0461 100755 --- a/cronjobs/payouts.php +++ b/cronjobs/payouts.php @@ -63,16 +63,19 @@ if ($setting->getValue('disable_manual_payouts') != 1) { $monitoring->endCronjob($cron_name, 'E0010', 1, true); } $log->logInfo("\t" . $aData['account_id'] . "\t\t" . $aData['username'] . "\t" . $dBalance . "\t\t" . $aData['coin_address']); - try { - $txid = $bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee_manual']); - } catch (Exception $e) { - $log->logError('E0078: RPC method did not return 200 OK: Address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage()); - $monitoring->endCronjob($cron_name, 'E0078', 1, true); - } if ($transaction->addTransaction($aData['account_id'], $dBalance - $config['txfee_manual'], 'Debit_MP', NULL, $aData['coin_address'], $txid) && $transaction->addTransaction($aData['account_id'], $config['txfee_manual'], '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. ERROR: ' . $transaction->getCronError()); + // Run the payouts from RPC now that the user is fully debited + try { + $txid = $bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee_manual']); + } catch (Exception $e) { + $log->logError('E0078: RPC method did not return 200 OK: Address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage()); + // Remove this line below if RPC calls are failing but transactions are still added to it + // Don't blame MPOS if you run into issues after commenting this out! + $monitoring->endCronjob($cron_name, 'E0078', 1, true); + } // Notify user via mail $aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id'])); $aMailData['subject'] = 'Manual Payout Completed'; @@ -131,18 +134,20 @@ if ($setting->getValue('disable_auto_payouts') != 1) { $log->logInfo("\t" . $aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address']); // Only run if balance meets threshold and can pay the potential transaction fee if ($dBalance > $aUserData['ap_threshold'] && $dBalance > $config['txfee_auto']) { - // Send balance, fees are reduced later by RPC Server - try { - $txid = $bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance - $config['txfee_auto']); - } catch (Exception $e) { - $log->logError('E0078: RPC method did not return 200 OK: Address: ' . $aUserData['coin_address'] . ' ERROR: ' . $e->getMessage()); - $monitoring->endCronjob($cron_name, 'E0078', 1, true); - } // Create transaction record if ($transaction->addTransaction($aUserData['id'], $dBalance - $config['txfee_auto'], 'Debit_AP', NULL, $aUserData['coin_address'], $txid) && $transaction->addTransaction($aUserData['id'], $config['txfee_auto'], '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. ERROR: ' . $transaction->getCronError()); + // Run the payouts from RPC now that the user is fully debited + try { + $txid = $bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance - $config['txfee_auto']); + } catch (Exception $e) { + $log->logError('E0078: RPC method did not return 200 OK: Address: ' . $aUserData['coin_address'] . ' ERROR: ' . $e->getMessage()); + // Remove this line below if RPC calls are failing but transactions are still added to it + // Don't blame MPOS if you run into issues after commenting this out! + $monitoring->endCronjob($cron_name, 'E0078', 1, true); + } // Notify user via mail $aMailData['email'] = $user->getUserEmail($user->getUserName($aUserData['id'])); $aMailData['subject'] = 'Auto Payout Completed';