#!/usr/bin/php can_connect() === true ){ $dDifficulty = $bitcoin->getdifficulty(); } else { verbose("Aborted: " . $bitcoin->can_connect() . "\n"); exit(1); } // Value per share calculation $pps_value = number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); // Find our last share accounted and last inserted share for PPS calculations $iPreviousShareId = $setting->getValue('pps_last_share_id'); $iLastShareId = $share->getLastInsertedShareId(); // Check for all new shares, we start one higher as our last accounted share to avoid duplicates $aAccountShares = $share->getSharesForAccounts($iPreviousShareId + 1, $iLastShareId); verbose("ID\tUsername\tInvalid\tValid\t\tPPS Value\t\tPayout\t\tDonation\tFee\t\tStatus\n"); foreach ($aAccountShares as $aData) { // Take our valid shares and multiply by per share value $aData['payout'] = number_format(round($aData['valid'] * $pps_value, 8), 8); // Defaults $aData['fee' ] = 0; $aData['donation'] = 0; // Calculate block fees if ($config['fees'] > 0) $aData['fee'] = number_format(round($config['fees'] / 100 * $aData['payout'], 8), 8); // Calculate donation amount $aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8), 8); verbose($aData['id'] . "\t" . $aData['username'] . "\t" . $aData['invalid'] . "\t" . $aData['valid'] . "\t*\t" . $pps_value . "\t=\t" . $aData['payout'] . "\t" . $aData['donation'] . "\t" . $aData['fee'] . "\t"); $strStatus = "OK"; // Add new credit transaction if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit_PPS')) $strStatus = "Transaction Failed"; // Add new fee debit for this block if ($aData['fee'] > 0 && $config['fees'] > 0) if (!$transaction->addTransaction($aData['id'], $aData['fee'], 'Fee_PPS')) $strStatus = "Fee Failed"; // Add new donation debit if ($aData['donation'] > 0) if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation_PPS')) $strStatus = "Donation Failed"; verbose($strStatus . "\n"); } // Store our last inserted ID for the next run $setting->setValue('pps_last_share_id', $iLastShareId); verbose("\n\n------------------------------------------------------------------------------------\n\n"); // Fetch all unaccounted blocks $aAllBlocks = $block->getAllUnaccounted('ASC'); if (empty($aAllBlocks)) { verbose("No new unaccounted blocks found\n"); } // 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 $iLastBlockShare = @$aAllBlocks[$iIndex - 1]['share_id'] ? @$aAllBlocks[$iIndex - 1]['share_id'] : 0; // Per account statistics $aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id']); foreach ($aAccountShares as $key => $aData) { if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) verbose("Failed to update stats for this block on : " . $aData['username'] . "\n"); } // Move shares to archive if ($config['archive_shares'] && $aBlock['share_id'] < $iLastShareId) { if (!$share->moveArchive($aBlock['share_id'], $aBlock['id'], @$iLastBlockShare)) verbose("Archving failed\n"); } // Delete shares if ($aBlock['share_id'] < $iLastShareId && !$share->deleteAccountedShares($aBlock['share_id'], $iLastBlockShare)) { verbose("\nERROR : Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting!\n"); exit(1); } // Mark this block as accounted for if (!$block->setAccounted($aBlock['id'])) { verbose("\nERROR : Failed to mark block as accounted! Aborting!\n"); exit(1); } } ?>