added some more debug output for profiling
This commit is contained in:
parent
27ea17166e
commit
1bdf5e3156
@ -62,6 +62,7 @@ class Statistics {
|
||||
* @return array
|
||||
**/
|
||||
public function getBlocksFound($limit=10) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__ . $limit)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT b.*, a.username as finder
|
||||
@ -84,6 +85,7 @@ class Statistics {
|
||||
* @return bool
|
||||
**/
|
||||
public function updateShareStatistics($aStats, $iBlockId) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?)");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true;
|
||||
// Catchall
|
||||
@ -98,6 +100,7 @@ class Statistics {
|
||||
* @return data object Return our hashrateas an object
|
||||
**/
|
||||
public function getCurrentHashrate() {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT SUM(hashrate) AS hashrate FROM
|
||||
@ -118,6 +121,7 @@ class Statistics {
|
||||
* @return data object Our share rate in shares per second
|
||||
**/
|
||||
public function getCurrentShareRate() {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM
|
||||
@ -138,6 +142,7 @@ class Statistics {
|
||||
* @return data array invalid and valid shares
|
||||
**/
|
||||
public function getRoundShares() {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
@ -162,6 +167,7 @@ class Statistics {
|
||||
* @return data array invalid and valid share counts
|
||||
**/
|
||||
public function getUserShares($account_id) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
@ -217,6 +223,7 @@ class Statistics {
|
||||
* @return data int Current hashrate in khash/s
|
||||
**/
|
||||
public function getWorkerHashrate($worker_id) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT ROUND(COUNT(s.id) * POW(2,21)/600/1000) AS hashrate
|
||||
@ -239,6 +246,7 @@ class Statistics {
|
||||
* @return data array Users with shares, account or hashrate, account
|
||||
**/
|
||||
public function getTopContributors($type='shares', $limit=15) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__ . $type . $limit)) return $data;
|
||||
switch ($type) {
|
||||
case 'shares':
|
||||
@ -280,6 +288,7 @@ class Statistics {
|
||||
* @return data array NOT FINISHED YET
|
||||
**/
|
||||
public function getHourlyHashrateByAccount($account_id) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
|
||||
@ -38,10 +38,8 @@ class Transaction {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addDebit($account_id, $amount, $type='AP') {
|
||||
}
|
||||
|
||||
public function getTransactions($account_id, $start=0) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
t.id AS id,
|
||||
@ -75,6 +73,7 @@ class Transaction {
|
||||
}
|
||||
|
||||
public function getBalance($account_id) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT ROUND(IFNULL(t1.credit, 0) - IFNULL(t2.debit, 0) - IFNULL(t3.other, 0), 8) AS balance
|
||||
FROM
|
||||
|
||||
@ -41,6 +41,7 @@ class User {
|
||||
* @return bool
|
||||
**/
|
||||
public function checkLogin($username, $password) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$this->debug->append("Checking login for $username with password $password", 2);
|
||||
if ( $this->checkUserPassword($username, $password) ) {
|
||||
$this->createSession($username);
|
||||
@ -56,6 +57,7 @@ class User {
|
||||
* @return bool
|
||||
**/
|
||||
public function checkPin($userId, $pin=false) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$this->debug->append("Confirming PIN for $userId and pin $pin", 2);
|
||||
$stmt = $this->mysqli->prepare("SELECT pin FROM $this->table WHERE id=? AND pin=? LIMIT 1");
|
||||
$pin_hash = hash('sha256', $pin.$this->salt);
|
||||
@ -76,6 +78,7 @@ class User {
|
||||
* @return array Return result
|
||||
**/
|
||||
private function getSingle($value, $search='id', $field='id', $type="i") {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("SELECT $search FROM $this->table WHERE $field = ? LIMIT 1");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param($type, $value);
|
||||
@ -94,6 +97,7 @@ class User {
|
||||
* @return data array All users with payout setup
|
||||
**/
|
||||
public function getAllAutoPayout() {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
id, username, coin_address, ap_threshold
|
||||
@ -115,6 +119,7 @@ class User {
|
||||
* @return data string Coin Address
|
||||
**/
|
||||
public function getCoinAddress($userID) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
return $this->getSingle($userID, 'coin_address', 'id');
|
||||
}
|
||||
|
||||
@ -124,6 +129,7 @@ class User {
|
||||
* @return data string Coin Address
|
||||
**/
|
||||
public function getDonatePercent($userID) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$dPercent = $this->getSingle($userID, 'donate_percent', 'id');
|
||||
if ($dPercent > 100) $dPercent = 100;
|
||||
if ($dPercent < 0) $dPercent = 0;
|
||||
@ -137,6 +143,7 @@ class User {
|
||||
* @return bool
|
||||
**/
|
||||
private function updateSingle($userID, $field) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET " . $field['name'] . " = ? WHERE userId = ? LIMIT 1");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param($field['type'].'i', $field['value'], $userID);
|
||||
@ -148,6 +155,7 @@ class User {
|
||||
}
|
||||
|
||||
private function checkStmt($bState) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($bState ===! true) {
|
||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||
$this->setErrorMessage('Internal application Error');
|
||||
@ -157,6 +165,7 @@ class User {
|
||||
}
|
||||
|
||||
public function updatePassword($userID, $current, $new1, $new2) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($new1 !== $new2) {
|
||||
$this->setErrorMessage( 'New passwords do not match' );
|
||||
return false;
|
||||
@ -181,6 +190,7 @@ class User {
|
||||
}
|
||||
|
||||
public function updateAccount($userID, $address, $threshold, $donate) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$bUser = false;
|
||||
$threshold = min(250, max(0, floatval($threshold)));
|
||||
if ($threshold < 1) $threshold = 0.0;
|
||||
@ -197,6 +207,7 @@ class User {
|
||||
}
|
||||
|
||||
private function checkUserPassword($username, $password) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$user = array();
|
||||
$stmt = $this->mysqli->prepare("SELECT username, id FROM $this->table WHERE username=? AND pass=? LIMIT 1");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
@ -213,6 +224,7 @@ class User {
|
||||
}
|
||||
|
||||
private function createSession($username) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$this->debug->append("Log in user to _SESSION", 2);
|
||||
session_regenerate_id(true);
|
||||
$_SESSION['AUTHENTICATED'] = '1';
|
||||
@ -221,16 +233,19 @@ class User {
|
||||
}
|
||||
|
||||
public function logoutUser() {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
session_destroy();
|
||||
session_regenerate_id(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getTableName() {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
public function getUserData($userID) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$this->debug->append("Fetching user information for user id: $userID");
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
@ -238,7 +253,6 @@ class User {
|
||||
IFNULL(donate_percent, '0') as donate_percent, coin_address, ap_threshold
|
||||
FROM $this->table
|
||||
WHERE id = ? LIMIT 0,1");
|
||||
echo $this->mysqli->error;
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('i', $userID);
|
||||
if (!$stmt->execute()) {
|
||||
@ -254,6 +268,7 @@ class User {
|
||||
}
|
||||
|
||||
public function register($username, $password1, $password2, $pin, $email1='', $email2='') {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if (strlen($password1) < 8) {
|
||||
$this->setErrorMessage( 'Password is too short, minimum of 8 characters required' );
|
||||
return false;
|
||||
|
||||
@ -41,6 +41,7 @@ class Worker {
|
||||
* @return bool
|
||||
**/
|
||||
public function updateWorkers($account_id, $data) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$username = $this->user->getUserName($account_id);
|
||||
foreach ($data as $key => $value) {
|
||||
// Prefix the WebUser to Worker name
|
||||
@ -61,6 +62,7 @@ class Worker {
|
||||
* @return mixed array Workers and their settings or false
|
||||
**/
|
||||
public function getWorkers($account_id) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT id, username, password,
|
||||
( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active,
|
||||
@ -81,6 +83,7 @@ class Worker {
|
||||
* @return data mixed int count if any workers are active, false otherwise
|
||||
**/
|
||||
public function getCountAllActiveWorkers() {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("SELECT COUNT(DISTINCT username) AS total FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
if (!$stmt->execute()) {
|
||||
@ -103,6 +106,7 @@ class Worker {
|
||||
* @return bool
|
||||
**/
|
||||
public function addWorker($account_id, $workerName, $workerPassword) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$username = $this->user->getUserName($account_id);
|
||||
$workerName = "$username.$workerName";
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, username, password) VALUES(?, ?, ?)");
|
||||
@ -125,6 +129,7 @@ class Worker {
|
||||
* @return bool
|
||||
**/
|
||||
public function deleteWorker($account_id, $id) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE account_id = ? AND id = ?");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('ii', $account_id, $id);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user