[CLEANUP] Coding style
This commit is contained in:
parent
b02db092a2
commit
8ca9744ce1
@ -35,130 +35,122 @@ if ($bitcoin->can_connect() !== true) {
|
||||
$monitoring->endCronjob($cron_name, 'E0006', 1, true);
|
||||
}
|
||||
if ($setting->getValue('disable_manual_payouts') != 1) {
|
||||
// Fetch outstanding payout requests
|
||||
if ($aPayouts = $oPayout->getUnprocessedPayouts()) {
|
||||
if (count($aPayouts) > 0) {
|
||||
$log->logInfo("\tStarting Manual Payments...");
|
||||
$log->logInfo("\tAccount ID\tUsername\tBalance\t\tCoin Address");
|
||||
foreach ($aPayouts as $aData) {
|
||||
$aBalance = $transaction->getBalance($aData['account_id']);
|
||||
$dBalance = $aBalance['confirmed'];
|
||||
$aData['coin_address'] = $user->getCoinAddress($aData['account_id']);
|
||||
$aData['username'] = $user->getUserName($aData['account_id']);
|
||||
if ($dBalance > $config['txfee_manual']) {
|
||||
// To ensure we don't run this transaction again, lets mark it completed
|
||||
if (!$oPayout->setProcessed($aData['id'])) {
|
||||
$log->logFatal('unable to mark transactions ' . $aData['id'] . ' as processed. ERROR: ' . $oPayout->getCronError());
|
||||
$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('Skipping payment. Failed to send balance to coin address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
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());
|
||||
// Notify user via mail
|
||||
$aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id']));
|
||||
$aMailData['subject'] = 'Manual Payout Completed';
|
||||
$aMailData['amount'] = $dBalance - $config['txfee_manual'];
|
||||
$aMailData['payout_id'] = $aData['id'];
|
||||
if (!$notification->sendNotification($aData['account_id'], 'manual_payout', $aMailData))
|
||||
$log->logError('Failed to send notification email to users address: ' . $aMailData['email'] . 'ERROR: ' . $notification->getCronError());
|
||||
// Recheck the users balance to make sure it is now 0
|
||||
if (!$aBalance = $transaction->getBalance($aData['account_id'])) {
|
||||
$log->logFatal('Failed to fetch balance for account ' . $aData['account_id'] . '. ERROR: ' . $transaction->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0065', 1, true);
|
||||
}
|
||||
if ($aBalance['confirmed'] > 0) {
|
||||
$log->logFatal('User has a remaining balance of ' . $aBalance['confirmed'] . ' after a successful payout!');
|
||||
$monitoring->endCronjob($cron_name, 'E0065', 1, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$log->logFatal('Failed to add new Debit_MP transaction in database for user ' . $user->getUserName($aData['account_id']) . ' ERROR: ' . $transaction->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0064', 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch outstanding payout requests
|
||||
if ($aPayouts = $oPayout->getUnprocessedPayouts()) {
|
||||
if (count($aPayouts) > 0) {
|
||||
$log->logInfo("\tStarting Manual Payments...");
|
||||
$log->logInfo("\tAccount ID\tUsername\tBalance\t\tCoin Address");
|
||||
foreach ($aPayouts as $aData) {
|
||||
$aBalance = $transaction->getBalance($aData['account_id']);
|
||||
$dBalance = $aBalance['confirmed'];
|
||||
$aData['coin_address'] = $user->getCoinAddress($aData['account_id']);
|
||||
$aData['username'] = $user->getUserName($aData['account_id']);
|
||||
if ($dBalance > $config['txfee_manual']) {
|
||||
// To ensure we don't run this transaction again, lets mark it completed
|
||||
if (!$oPayout->setProcessed($aData['id'])) {
|
||||
$log->logFatal('unable to mark transactions ' . $aData['id'] . ' as processed. ERROR: ' . $oPayout->getCronError());
|
||||
$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('Skipping payment. Failed to send balance to coin address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
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());
|
||||
// Notify user via mail
|
||||
$aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id']));
|
||||
$aMailData['subject'] = 'Manual Payout Completed';
|
||||
$aMailData['amount'] = $dBalance - $config['txfee_manual'];
|
||||
$aMailData['payout_id'] = $aData['id'];
|
||||
if (!$notification->sendNotification($aData['account_id'], 'manual_payout', $aMailData))
|
||||
$log->logError('Failed to send notification email to users address: ' . $aMailData['email'] . 'ERROR: ' . $notification->getCronError());
|
||||
// Recheck the users balance to make sure it is now 0
|
||||
if (!$aBalance = $transaction->getBalance($aData['account_id'])) {
|
||||
$log->logFatal('Failed to fetch balance for account ' . $aData['account_id'] . '. ERROR: ' . $transaction->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0065', 1, true);
|
||||
}
|
||||
}
|
||||
if ($aBalance['confirmed'] > 0) {
|
||||
$log->logFatal('User has a remaining balance of ' . $aBalance['confirmed'] . ' after a successful payout!');
|
||||
$monitoring->endCronjob($cron_name, 'E0065', 1, true);
|
||||
}
|
||||
} else {
|
||||
$log->logFatal('Failed to add new Debit_MP transaction in database for user ' . $user->getUserName($aData['account_id']) . ' ERROR: ' . $transaction->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0064', 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (empty($aPayouts)) {
|
||||
$log->logInfo("\tStopping Payments. No Payout Requests Found.");
|
||||
}
|
||||
else {
|
||||
} else if (empty($aPayouts)) {
|
||||
$log->logInfo("\tStopping Payments. No Payout Requests Found.");
|
||||
} else {
|
||||
$log->logFatal("\tFailed Processing Manual Payment Queue...Aborting...");
|
||||
$monitoring->endCronjob($cron_name, 'E0050', 1, true);
|
||||
}
|
||||
if (count($aPayouts > 0)) $log->logDebug(" found " . count($aPayouts) . " queued manual payout requests");
|
||||
}
|
||||
else {
|
||||
$log->logDebug("Manual payouts are disabled via admin panel");
|
||||
}
|
||||
if (count($aPayouts > 0)) $log->logDebug(" found " . count($aPayouts) . " queued manual payout requests");
|
||||
} else {
|
||||
$log->logDebug("Manual payouts are disabled via admin panel");
|
||||
}
|
||||
if ($setting->getValue('disable_auto_payouts') != 1) {
|
||||
// Fetch all users balances
|
||||
if ($users = $transaction->getAPQueue()) {
|
||||
if (!empty($users)) {
|
||||
if (count($users) > 0) $log->logDebug(" found " . count($users) . " queued payout(s)");
|
||||
// Go through users and run transactions
|
||||
$log->logInfo("Starting Payments...");
|
||||
$log->logInfo("\tUserID\tUsername\tBalance\tThreshold\tAddress");
|
||||
foreach ($users as $aUserData) {
|
||||
$dBalance = $aUserData['confirmed'];
|
||||
$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('Skipping payment. Failed to send balance to coin address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
// 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());
|
||||
// Notify user via mail
|
||||
$aMailData['email'] = $user->getUserEmail($user->getUserName($aUserData['id']));
|
||||
$aMailData['subject'] = 'Auto Payout Completed';
|
||||
$aMailData['amount'] = $dBalance - $config['txfee_auto'];
|
||||
if (!$notification->sendNotification($aUserData['id'], 'auto_payout', $aMailData))
|
||||
$log->logError('Failed to send notification email to users address: ' . $aMailData['email'] . ' ERROR: ' . $notification->getCronError());
|
||||
// Recheck the users balance to make sure it is now 0
|
||||
$aBalance = $transaction->getBalance($aUserData['id']);
|
||||
if ($aBalance['confirmed'] > 0) {
|
||||
$log->logFatal('User has a remaining balance of ' . $aBalance['confirmed'] . ' after a successful payout!');
|
||||
$monitoring->endCronjob($cron_name, 'E0065', 1, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$log->logFatal('Failed to add new Debit_AP transaction in database for user ' . $user->getUserName($aUserData['id']) . ' ERROR: ' . $transaction->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0064', 1, true);
|
||||
}
|
||||
}
|
||||
// Fetch all users balances
|
||||
if ($users = $transaction->getAPQueue()) {
|
||||
if (!empty($users)) {
|
||||
if (count($users) > 0) $log->logDebug(" found " . count($users) . " queued payout(s)");
|
||||
// Go through users and run transactions
|
||||
$log->logInfo("Starting Payments...");
|
||||
$log->logInfo("\tUserID\tUsername\tBalance\tThreshold\tAddress");
|
||||
foreach ($users as $aUserData) {
|
||||
$dBalance = $aUserData['confirmed'];
|
||||
$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('Skipping payment. Failed to send balance to coin address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
// 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());
|
||||
// Notify user via mail
|
||||
$aMailData['email'] = $user->getUserEmail($user->getUserName($aUserData['id']));
|
||||
$aMailData['subject'] = 'Auto Payout Completed';
|
||||
$aMailData['amount'] = $dBalance - $config['txfee_auto'];
|
||||
if (!$notification->sendNotification($aUserData['id'], 'auto_payout', $aMailData))
|
||||
$log->logError('Failed to send notification email to users address: ' . $aMailData['email'] . ' ERROR: ' . $notification->getCronError());
|
||||
// Recheck the users balance to make sure it is now 0
|
||||
$aBalance = $transaction->getBalance($aUserData['id']);
|
||||
if ($aBalance['confirmed'] > 0) {
|
||||
$log->logFatal('User has a remaining balance of ' . $aBalance['confirmed'] . ' after a successful payout!');
|
||||
$monitoring->endCronjob($cron_name, 'E0065', 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(empty($users)) {
|
||||
$log->logInfo("\tSkipping payments. No Auto Payments Eligible.");
|
||||
$log->logDebug("Users have not configured their AP > 0");
|
||||
}
|
||||
else{
|
||||
$log->logFatal("\tFailed Processing Auto Payment Payment Queue. ERROR: " . $transaction->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0050', 1, true);
|
||||
} else {
|
||||
$log->logFatal('Failed to add new Debit_AP transaction in database for user ' . $user->getUserName($aUserData['id']) . ' ERROR: ' . $transaction->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0064', 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(empty($users)) {
|
||||
$log->logInfo("\tSkipping payments. No Auto Payments Eligible.");
|
||||
$log->logDebug("Users have not configured their AP > 0");
|
||||
} else{
|
||||
$log->logFatal("\tFailed Processing Auto Payment Payment Queue. ERROR: " . $transaction->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0050', 1, true);
|
||||
}
|
||||
} else {
|
||||
$log->logDebug("Auto payouts disabled via admin panel");
|
||||
}
|
||||
else {
|
||||
$log->logDebug("Auto payouts disabled via admin panel");
|
||||
}
|
||||
|
||||
$log->logInfo("Completed Payouts");
|
||||
// Cron cleanup and monitoring
|
||||
require_once('cron_end.inc.php');
|
||||
|
||||
@ -49,9 +49,9 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// We support some dynamic share targets but fall back to our fixed value
|
||||
// Re-calculate after each run due to re-targets in this loop
|
||||
if ($config['pplns']['shares']['type'] == 'blockavg' && $block->getBlockCount() > 0) {
|
||||
$pplns_target = round($block->getAvgBlockShares($aBlock['height'], $config['pplns']['blockavg']['blockcount']));
|
||||
$pplns_target = round($block->getAvgBlockShares($aBlock['height'], $config['pplns']['blockavg']['blockcount']));
|
||||
} else if ($config['pplns']['shares']['type'] == 'dynamic' && $block->getBlockCount() > 0) {
|
||||
$pplns_target = round($block->getAvgBlockShares($aBlock['height'], $config['pplns']['blockavg']['blockcount']) * (100 - $config['pplns']['dynamic']['percent'])/100 + $aBlock['shares'] * $config['pplns']['dynamic']['percent']/100);
|
||||
$pplns_target = round($block->getAvgBlockShares($aBlock['height'], $config['pplns']['blockavg']['blockcount']) * (100 - $config['pplns']['dynamic']['percent'])/100 + $aBlock['shares'] * $config['pplns']['dynamic']['percent']/100);
|
||||
} else {
|
||||
$pplns_target = $config['pplns']['shares']['default'];
|
||||
}
|
||||
@ -123,21 +123,21 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
}
|
||||
// reverse payout
|
||||
if ($config['pplns']['reverse_payout']) {
|
||||
$aSharesData = NULL;
|
||||
foreach($aAccountShares as $key => $aData) {
|
||||
$aSharesData[$aData['username']] = $aData;
|
||||
}
|
||||
// Add users from archive not in current round
|
||||
foreach($aArchiveShares as $key => $aArchData) {
|
||||
if (!array_key_exists($aArchData['account'], $aSharesData)) {
|
||||
$log->logDebug('Adding user ' . $aArchData['account'] . ' to round shares');
|
||||
$log->logDebug(' valid : ' . $aArchData['valid']);
|
||||
$log->logDebug(' invalid : ' . $aArchData['invalid']);
|
||||
$aArchData['username'] = $aArchData['account'];
|
||||
$aSharesData[$aArchData['account']] = $aArchData;
|
||||
}
|
||||
}
|
||||
$aAccountShares = $aSharesData;
|
||||
$aSharesData = NULL;
|
||||
foreach($aAccountShares as $key => $aData) {
|
||||
$aSharesData[$aData['username']] = $aData;
|
||||
}
|
||||
// Add users from archive not in current round
|
||||
foreach($aArchiveShares as $key => $aArchData) {
|
||||
if (!array_key_exists($aArchData['account'], $aSharesData)) {
|
||||
$log->logDebug('Adding user ' . $aArchData['account'] . ' to round shares');
|
||||
$log->logDebug(' valid : ' . $aArchData['valid']);
|
||||
$log->logDebug(' invalid : ' . $aArchData['invalid']);
|
||||
$aArchData['username'] = $aArchData['account'];
|
||||
$aSharesData[$aArchData['account']] = $aArchData;
|
||||
}
|
||||
}
|
||||
$aAccountShares = $aSharesData;
|
||||
}
|
||||
}
|
||||
// We tried to fill up to PPLNS target, now we need to check the actual shares to properly payout users
|
||||
|
||||
@ -54,16 +54,16 @@ if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() >
|
||||
$log->logInfo("\tPPS reward using block average, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty);
|
||||
} else {
|
||||
if ($config['pps']['reward']['type'] == 'block') {
|
||||
if ($aLastBlock = $block->getLast()) {
|
||||
$pps_reward = $aLastBlock['amount'];
|
||||
$log->logInfo("\tPPS value (Last Block): " . $pps_reward);
|
||||
} else {
|
||||
$pps_reward = $config['pps']['reward']['default'];
|
||||
$log->logInfo("\tPPS value (Default): " . $pps_reward);
|
||||
}
|
||||
if ($aLastBlock = $block->getLast()) {
|
||||
$pps_reward = $aLastBlock['amount'];
|
||||
$log->logInfo("\tPPS value (Last Block): " . $pps_reward);
|
||||
} else {
|
||||
$pps_reward = $config['pps']['reward']['default'];
|
||||
$log->logInfo("\tPPS value (Default): " . $pps_reward);
|
||||
}
|
||||
} else {
|
||||
$pps_reward = $config['pps']['reward']['default'];
|
||||
$log->logInfo("\tPPS value (Default): " . $pps_reward);
|
||||
$pps_reward = $config['pps']['reward']['default'];
|
||||
$log->logInfo("\tPPS value (Default): " . $pps_reward);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,19 +74,19 @@ $log->logInfo("\tPPS value: " . $pps_value);
|
||||
// Find our last share accounted and last inserted share for PPS calculations
|
||||
|
||||
if (!$iPreviousShareId = $setting->getValue('pps_last_share_id')) {
|
||||
$log->logError("Failed to fetch Previous Share ID. ERROR: " . $setting->getCronError());
|
||||
$log->logError("Failed to fetch Previous Share ID. ERROR: " . $setting->getCronError());
|
||||
}
|
||||
$log->logInfo("\tPPS Last Share ID: " . $iPreviousShareId);
|
||||
|
||||
if (!$iLastShareId = $share->getLastInsertedShareId()) {
|
||||
$log->logError("Failed to fetch Last Inserted PPS Share ID. ERROR: " . $share->getCronError());
|
||||
$log->logError("Failed to fetch Last Inserted PPS Share ID. ERROR: " . $share->getCronError());
|
||||
}
|
||||
$log->logInfo("\tPPS Last Processed Share ID: " . $iLastShareId);
|
||||
|
||||
// Check for all new shares, we start one higher as our last accounted share to avoid duplicates
|
||||
$log->logInfo("\tQuery getSharesForAccounts... starting...");
|
||||
if (!$aAccountShares = $share->getSharesForAccounts($iPreviousShareId + 1, $iLastShareId)) {
|
||||
$log->logError("Failed to fetch Account Shares. ERROR: " . $share->getCronError());
|
||||
$log->logError("Failed to fetch Account Shares. ERROR: " . $share->getCronError());
|
||||
}
|
||||
$log->logInfo("\tQuery Completed...");
|
||||
|
||||
@ -143,65 +143,64 @@ foreach ($aAccountShares as $aData) {
|
||||
// Store our last inserted ID for the next run
|
||||
$log->logInfo("\tFetching Last Share ID...");
|
||||
if (!$setting->setValue('pps_last_share_id', $iLastShareId)) {
|
||||
$log->logError("Failed to fetch Last Share ID. ERROR: " . $setting->getCronError());
|
||||
$log->logError("Failed to fetch Last Share ID. ERROR: " . $setting->getCronError());
|
||||
}
|
||||
|
||||
// Fetch all unaccounted blocks
|
||||
$log->logInfo("\tFetching unaccounted blocks.");
|
||||
if ($aAllBlocks = $block->getAllUnaccounted('ASC')) {
|
||||
// Go through blocks and archive/delete shares that have been accounted for
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// Go through blocks and archive/delete shares that have been accounted for
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// If we are running through more than one block, check for previous share ID
|
||||
$log->logInfo("\tProcess each block for Previous Share ID.");
|
||||
$iLastBlockShare = @$aAllBlocks[$iIndex - 1]['share_id'] ? @$aAllBlocks[$iIndex - 1]['share_id'] : 0;
|
||||
if (!is_numeric($aBlock['share_id'])) {
|
||||
$log->logFatal("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue");
|
||||
$monitoring->setStatus($cron_name . "_active", "yesno", 0);
|
||||
$monitoring->setStatus($cron_name . "_message", "message", "Block " . $aBlock['height'] . " has no share_id associated with it");
|
||||
$monitoring->setStatus($cron_name . "_status", "okerror", 1);
|
||||
exit(1);
|
||||
$log->logFatal("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue");
|
||||
$monitoring->setStatus($cron_name . "_active", "yesno", 0);
|
||||
$monitoring->setStatus($cron_name . "_message", "message", "Block " . $aBlock['height'] . " has no share_id associated with it");
|
||||
$monitoring->setStatus($cron_name . "_status", "okerror", 1);
|
||||
exit(1);
|
||||
}
|
||||
// Per account statistics
|
||||
$log->logInfo("\tRefresh user statistics...");
|
||||
if (!$aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id'])) {
|
||||
$log->logError("Failed to Account Shares. ERROR: " . $share->getCronError());
|
||||
$log->logError("Failed to Account Shares. ERROR: " . $share->getCronError());
|
||||
}
|
||||
foreach ($aAccountShares as $key => $aData) {
|
||||
if (!$statistics->updateShareStatistics($aData, $aBlock['id']))
|
||||
$log->logError("Failed to update statistics for Block " . $aBlock['id'] . "for" . $aData['username'] . ' ERROR: ' . $statistics->getCronError());
|
||||
if (!$statistics->updateShareStatistics($aData, $aBlock['id']))
|
||||
$log->logError("Failed to update statistics for Block " . $aBlock['id'] . "for" . $aData['username'] . ' ERROR: ' . $statistics->getCronError());
|
||||
}
|
||||
$log->logInfo("\tUser Statistics updated.");
|
||||
|
||||
|
||||
// Move shares to archive
|
||||
$log->logInfo("\tBlock: " . $aBlock['id'] . "\t Move shares to archive...");
|
||||
if ($aBlock['share_id'] < $iLastShareId) {
|
||||
if (!$share->moveArchive($aBlock['share_id'], $aBlock['id'], @$iLastBlockShare))
|
||||
$log->logError("Failed to copy shares to from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ' Error: ' . $share->getCronError());
|
||||
if (!$share->moveArchive($aBlock['share_id'], $aBlock['id'], @$iLastBlockShare))
|
||||
$log->logError("Failed to copy shares to from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ' Error: ' . $share->getCronError());
|
||||
}
|
||||
$log->logInfo("\tBlock: " . $aBlock['id'] . "\t Shares moved to archive...");
|
||||
|
||||
|
||||
// Delete shares
|
||||
$log->logInfo("\tBlock: " . $aBlock['id'] . "\t Deleting accounted shares...");
|
||||
if ($aBlock['share_id'] < $iLastShareId && !$share->deleteAccountedShares($aBlock['share_id'], $iLastBlockShare)) {
|
||||
$log->logFatal("Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting! Error: " . $share->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0016', 1, true);
|
||||
$log->logFatal("Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting! Error: " . $share->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0016', 1, true);
|
||||
}
|
||||
$log->logInfo("\tBlock: " . $aBlock['id'] . "\t Deleted accounted shares.");
|
||||
|
||||
|
||||
// Mark this block as accounted for
|
||||
$log->logInfo("\tBlock: " . $aBlock['id'] . "\t Marking Block as accounted...");
|
||||
if (!$block->setAccounted($aBlock['id'])) {
|
||||
$log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0014', 1, true);
|
||||
$log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0014', 1, true);
|
||||
}
|
||||
$log->logInfo("\tBlock: " . $aBlock['id'] . "\t Block paid and accounted for.");
|
||||
}
|
||||
}
|
||||
else if (empty($aAllBlocks)) {
|
||||
$log->logInfo("\tNo new blocks.");
|
||||
// No monitoring event here, not fatal for PPS
|
||||
}
|
||||
} else if (empty($aAllBlocks)) {
|
||||
$log->logInfo("\tNo new blocks.");
|
||||
// No monitoring event here, not fatal for PPS
|
||||
} else {
|
||||
$log->logInfo("Failed to fetch unaccounted Blocks. NOTICE: " . $block->getCronError());
|
||||
$log->logInfo("Failed to fetch unaccounted Blocks. NOTICE: " . $block->getCronError());
|
||||
}
|
||||
$log->logInfo("Completed PPS Payout");
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user