Skip to content

Commit 86df6d1

Browse files
committed
Merge pull request #2274 from MPOS/development
UPDATE : Development to Master
2 parents 670b3b3 + d85743f commit 86df6d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+653
-392
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
/include/config/global.inc.scrypt.php
1919
/include/config/global.inc.sha.php
2020

21+
# Test files
22+
/scripts/test.php
23+
/cronjobs/test.php
24+
2125
# IDE Settings
2226
/.idea/*
2327
.buildpath

cronjobs/findblock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
$config['reward_type'] == 'block' ? $aData['amount'] = $aData['amount'] : $aData['amount'] = $config['reward'];
6060
$aData['height'] = $aBlockRPCInfo['height'];
6161
$aTxDetails = $bitcoin->gettransaction($aBlockRPCInfo['tx'][0]);
62-
if (!isset($aBlockRPCInfo['confirmations'])) {
62+
if (isset($aBlockRPCInfo['confirmations'])) {
6363
$aData['confirmations'] = $aBlockRPCInfo['confirmations'];
6464
} else if (isset($aTxDetails['confirmations'])) {
6565
$aData['confirmations'] = $aTxDetails['confirmations'];

cronjobs/statistics.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
// Header
2929
$log->logInfo('Running statistical queries, errors may just mean no shares were available');
30-
$strLogMask = "| %-26.26s | %8.8s | %-6.6s |";
30+
$strLogMask = "| %-33.33s | %8.8s | %-6.6s |";
3131
$log->logInfo(sprintf($strLogMask, 'Method', 'Runtime', 'Status'));
3232

3333
// Per user share statistics based on all shares submitted
@@ -37,9 +37,15 @@
3737

3838
// Get all user hashrate statistics for caching
3939
$start = microtime(true);
40-
$statistics->getAllUserMiningStats() ? $status = 'OK' : $status = 'ERROR';
41-
$log->logInfo(sprintf($strLogMask, 'getAllUserMiningStats', number_format(microtime(true) - $start, 3), $status));
40+
$statistics->fetchAllUserMiningStats() ? $status = 'OK' : $status = 'ERROR';
41+
$log->logInfo(sprintf($strLogMask, 'fetchAllUserMiningStats', number_format(microtime(true) - $start, 3), $status));
4242

43+
// Store our statistical data into our `statistics_users` table
44+
$start = microtime(true);
45+
$statistics->storeAllUserMiningStatsSnapshot($statistics->getAllUserMiningStats()) ? $status = 'OK' : $status = 'ERROR';
46+
$log->logInfo(sprintf($strLogMask, 'storeAllUserMiningStatsSnapshot', number_format(microtime(true) - $start, 3), $status));
47+
48+
// Get stats for pool overview
4349
$start = microtime(true);
4450
$statistics->getTopContributors('hashes') ? $status = 'OK' : $status = 'ERROR';
4551
$log->logInfo(sprintf($strLogMask, 'getTopContributors(hashes)', number_format(microtime(true) - $start, 3), $status));

cronjobs/tables_cleanup.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,27 @@
6565
$message = '';
6666
$affected = $share->purgeArchive();
6767
if ($affected === false) {
68-
$message = 'Failed to delete notifications: ' . $oToken->getCronError();
68+
$message = 'Failed to delete shares: ' . $share->getCronError();
6969
$status = 'ERROR';
7070
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
7171
} else {
7272
$affected == 0 ? $message = 'No shares deleted' : $message = 'Deleted old shares';
7373
}
7474
$log->logInfo(sprintf($strLogMask, 'purgeArchive', $affected, number_format(microtime(true) - $start, 3), $status, $message));
7575

76+
// Clenaup shares archive
77+
$start = microtime(true);
78+
$status = 'OK';
79+
$message = '';
80+
$affected = $statistics->purgeUserStats($setting->getValue('statistics_graphing_days', 1));
81+
if ($affected === false) {
82+
$message = 'Failed to delete entries: ' . $statistics->getCronError();
83+
$status = 'ERROR';
84+
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
85+
} else {
86+
$affected == 0 ? $message = 'No entries deleted' : $message = 'Deleted old entries';
87+
}
88+
$log->logInfo(sprintf($strLogMask, 'purgeUserStats', $affected, number_format(microtime(true) - $start, 3), $status, $message));
7689

7790
// Cron cleanup and monitoring
7891
require_once('cron_end.inc.php');

include/autoloader.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// We need to load these first
1717
require_once(CLASS_DIR . '/base.class.php');
1818
require_once(CLASS_DIR . '/coins/coin_base.class.php');
19+
require_once(CLASS_DIR . '/coin_address.class.php');
1920
require_once(CLASS_DIR . '/setting.class.php');
2021
require_once(INCLUDE_DIR . '/version.inc.php');
2122
if (PHP_OS == 'WINNT') require_once(CLASS_DIR . '/memcached.class.php');

include/classes/base.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public function setDebug($debug) {
2222
public function setCoin($coin) {
2323
$this->coin = $coin;
2424
}
25+
public function setCoinAddress($coin_address) {
26+
$this->coin_address = $coin_address;
27+
}
2528
public function setLog($log) {
2629
$this->log = $log;
2730
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3+
4+
class CoinAddress extends Base {
5+
protected $table = 'coin_addresses';
6+
private $cache = array();
7+
8+
/**
9+
* Fetch users coin address for a currency
10+
* @param userID int UserID
11+
* @return data string Coin Address
12+
**/
13+
public function getCoinAddress($userID, $currency=NULL) {
14+
if ($currency === NULL) $currency = $this->config['currency'];
15+
$this->debug->append("STA " . __METHOD__, 4);
16+
$stmt = $this->mysqli->prepare("
17+
SELECT coin_address
18+
FROM " . $this->getTableName() . "
19+
WHERE account_id = ? AND currency = ?
20+
");
21+
if ( $this->checkStmt($stmt) && $stmt->bind_param('is', $userID, $currency) && $stmt->execute() && $result = $stmt->get_result()) {
22+
if ($result->num_rows == 1) {
23+
return $result->fetch_object()->coin_address;
24+
}
25+
}
26+
$this->debug->append("Unable to fetch users coin address for " . $currency);
27+
return $this->sqlError();
28+
}
29+
30+
/**
31+
* Check if a coin address is already set
32+
* @param address string Coin Address to check for
33+
* @return bool true or false
34+
**/
35+
public function existsCoinAddress($address) {
36+
$this->debug->append("STA " . __METHOD__, 4);
37+
return $this->getSingle($address, 'coin_address', 'coin_address', 's') === $address;
38+
}
39+
40+
/**
41+
* Add a new coin address record for a user
42+
* @param userID int Account ID
43+
* @param address string Coin Address
44+
* @param currency string Currency short handle, defaults to config option
45+
* @return bool true or false
46+
**/
47+
public function add($userID, $address, $currency=NULL) {
48+
if ($currency === NULL) $currency = $this->config['currency'];
49+
if ($address != $this->getCoinAddress($userID) && $this->existsCoinAddress($address)) {
50+
$this->setErrorMessage('Unable to update coin address, address already exists');
51+
return false;
52+
}
53+
$stmt = $this->mysqli->prepare("INSERT INTO " . $this->getTableName() . " (account_id, currency, coin_address) VALUES (?, ?, ?)");
54+
if ( $this->checkStmt($stmt) && $stmt->bind_param('iss', $userID, $currency, $address) && $stmt->execute()) {
55+
return true;
56+
}
57+
return $this->sqlError();
58+
}
59+
60+
/**
61+
* Remove a coin address record for a user
62+
* @param userID int Account ID
63+
* @param currency string Currency short handle, defaults to config option
64+
* @return bool true or false
65+
**/
66+
public function remove ($userID, $currency=NULL) {
67+
if ($currency === NULL) $currency = $this->config['currency'];
68+
$stmt = $this->mysqli->prepare("DELETE FROM " . $this->getTableName() . " WHERE account_id = ? AND currency = ?");
69+
if ( $this->checkStmt($stmt) && $stmt->bind_param('is', $userID, $currency) && $stmt->execute()) {
70+
return true;
71+
}
72+
return $this->sqlError();
73+
}
74+
75+
/**
76+
* Update a coin address record for a user and a currency
77+
* @param userID int Account ID
78+
* @param address string Coin Address
79+
* @param currency string Currency short handle, defaults to config option
80+
* @return bool true or false
81+
**/
82+
public function update($userID, $address, $currency=NULL) {
83+
if ($currency === NULL) $currency = $this->config['currency'];
84+
if ($address != $this->getCoinAddress($userID) && $this->existsCoinAddress($address)) {
85+
$this->setErrorMessage('Unable to update coin address, address already exists');
86+
return false;
87+
}
88+
if ($this->getCoinAddress($userID) != NULL) {
89+
$stmt = $this->mysqli->prepare("UPDATE " . $this->getTableName() . " SET coin_address = ? WHERE account_id = ? AND currency = ?");
90+
if ( $this->checkStmt($stmt) && $stmt->bind_param('sis', $address, $userID, $currency) && $stmt->execute()) {
91+
return true;
92+
}
93+
} else {
94+
$stmt = $this->mysqli->prepare("INSERT INTO " . $this->getTableName() . " (coin_address, account_id, currency) VALUES (?, ?, ?)");
95+
if ( $this->checkStmt($stmt) && $stmt->bind_param('sis', $address, $userID, $currency) && $stmt->execute()) {
96+
return true;
97+
}
98+
}
99+
return $this->sqlError();
100+
}
101+
}
102+
103+
$coin_address = new CoinAddress();
104+
$coin_address->setDebug($debug);
105+
$coin_address->setConfig($config);
106+
$coin_address->setMysql($mysqli);
107+
$coin_address->setErrorCodes($aErrorCodes);

include/classes/coins/coin_base.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@ class CoinBase extends Base {
1212
// Our coins target bits
1313
protected $target_bits = NULL;
1414

15+
// Our coins share difficulty precision
16+
protected $share_difficulty_precision = 0;
17+
1518
/**
1619
* Read our target bits
1720
**/
1821
public function getTargetBits() {
1922
return $this->target_bits;
2023
}
2124

25+
/**
26+
* Read our share difficulty precision
27+
**/
28+
public function getShareDifficultyPrecision() {
29+
return $this->share_difficulty_precision;
30+
}
31+
2232
/**
2333
* Calculate the PPS value for this coin
2434
* WARNING: Get this wrong and you will over- or underpay your miners!

include/classes/coins/coin_x11.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
**/
99
class Coin extends CoinBase {
1010
protected $target_bits = 24;
11+
protected $share_difficulty_precision = 4;
1112
}
1213

1314
?>

0 commit comments

Comments
 (0)