function BackendBlockNew($coin, $db_block) { // debuglog("NEW BLOCK $coin->name $db_block->height"); $reward = $db_block->amount; $total_hash_power = dboscalar("select sum(difficulty) from shares where valid and algo='{$coin->algo}'"); if (!$total_hash_power) { return; } $list = dbolist("SELECT userid, sum(difficulty) as total from shares where valid and algo='{$coin->algo}' group by userid"); foreach ($list as $item) { $hash_power = $item['total']; if (!$hash_power) { continue; } $user = getdbo('db_accounts', $item['userid']); if (!$user) { continue; } $amount = $reward * $hash_power / $total_hash_power; if (!$user->no_fees) { $amount = take_yaamp_fee($amount, $coin->algo); } $earning = new db_earnings(); $earning->userid = $user->id; $earning->coinid = $coin->id; $earning->blockid = $db_block->id; $earning->create_time = $db_block->time; $earning->amount = $amount; $earning->price = $coin->price; if ($db_block->category == 'generate') { $earning->mature_time = time(); $earning->status = 1; } else { // immature $earning->status = 0; } $earning->save(); $user->last_login = time(); $user->save(); } $delay = time() - 5 * 60; dborun("delete from shares where algo='{$coin->algo}' and time<{$delay}"); }
function BackendProcessList() { $list = dbolist("show processlist"); foreach ($list as $item) { $conn = getdbo('db_connections', $item['Id']); if (!$conn) { $conn = new db_connections(); $conn->id = $item['Id']; $conn->user = $item['User']; $conn->host = $item['Host']; $conn->db = $item['db']; $conn->created = time(); } $conn->idle = $item['Time']; $conn->last = time(); $conn->save(); } $delay = time() - 5 * 60; dborun("delete from connections where last<{$delay}"); }
echo "<th align=right>Last Hour</th>"; echo "<th align=right>Last 24 Hours</th>"; echo "<th align=right>Last 7 Days</th>"; echo "<th align=right>Last 30 Days</th>"; echo "</tr>"; echo "</thead>"; $t1 = time() - 60 * 60; $t2 = time() - 24 * 60 * 60; $t3 = time() - 7 * 24 * 60 * 60; $t4 = time() - 30 * 24 * 60 * 60; $total1 = 0; $total2 = 0; $total3 = 0; $total4 = 0; $algo = user()->getState('yaamp-algo'); $list = dbolist("SELECT coin_id FROM blocks where category!='orphan' and time>{$t4} and coin_id in (select id from coins where algo=:algo) group by coin_id order by id desc", array(':algo' => $algo)); foreach ($list as $item) { $coin = getdbo('db_coins', $item['coin_id']); if ($coin->symbol == 'BTC') { continue; } $res1 = controller()->memcache->get_database_row("history_item1-{$coin->id}-{$algo}", "select count(*) as a, sum(amount*price) as b from blocks where category!='orphan' and time>{$t1} and coin_id={$coin->id} and algo=:algo", array(':algo' => $algo)); $res2 = controller()->memcache->get_database_row("history_item2-{$coin->id}-{$algo}", "select count(*) as a, sum(amount*price) as b from blocks where category!='orphan' and time>{$t2} and coin_id={$coin->id} and algo=:algo", array(':algo' => $algo)); $res3 = controller()->memcache->get_database_row("history_item3-{$coin->id}-{$algo}", "select count(*) as a, sum(amount*price) as b from blocks where category!='orphan' and time>{$t3} and coin_id={$coin->id} and algo=:algo", array(':algo' => $algo)); $res4 = controller()->memcache->get_database_row("history_item4-{$coin->id}-{$algo}", "select count(*) as a, sum(amount*price) as b from blocks where category!='orphan' and time>{$t4} and coin_id={$coin->id} and algo=:algo", array(':algo' => $algo)); $total1 += $res1['b']; $total2 += $res2['b']; $total3 += $res3['b']; $total4 += $res4['b']; $name = substr($coin->name, 0, 12); echo "<tr class='ssrow'>";
$total_invalid = dboscalar("select sum(difficulty) * {$target} / {$interval} / 1000 from shares where not valid and time>{$delay} and algo=:algo", array(':algo' => $algo)); WriteBoxHeader("Miners Version ({$algo})"); //echo "<br><table class='dataGrid2'>"; showTableSorter('maintable2'); echo "<thead>"; echo "<tr>"; echo "<th>Version</th>"; echo "<th align=right>Count</th>"; echo "<th align=right>Extranonce</th>"; echo "<th align=right>Percent</th>"; echo "<th align=right>Hashrate*</th>"; echo "<th align=right>Reject</th>"; echo "</tr>"; echo "</thead><tbody>"; $error_tab = array(20 => 'Invalid nonce size', 21 => 'Invalid job id', 22 => 'Duplicate share', 23 => 'Invalid time rolling', 24 => 'Invalid extranonce2 size', 25 => 'Invalid share', 26 => 'Low difficulty share'); $versions = dbolist("select version, count(*) as c, sum(subscribe) as s from workers where algo=:algo group by version order by c desc", array(':algo' => $algo)); foreach ($versions as $item) { $version = $item['version']; $count = $item['c']; $extranonce = $item['s']; $hashrate = dboscalar("select sum(difficulty) * {$target} / {$interval} / 1000 from shares where valid and time>{$delay} and\n\t\tworkerid in (select id from workers where algo=:algo and version='{$version}')", array(':algo' => $algo)); $invalid = dboscalar("select sum(difficulty) * {$target} / {$interval} / 1000 from shares where not valid and time>{$delay} and\n\t\tworkerid in (select id from workers where algo=:algo and version='{$version}')", array(':algo' => $algo)); $title = ''; foreach ($error_tab as $i => $s) { $invalid2 = dboscalar("select sum(difficulty) * {$target} / {$interval} / 1000 from shares where error={$i} and time>{$delay} and\n\t\t\tworkerid in (select id from workers where algo=:algo and version='{$version}')", array(':algo' => $algo)); if ($invalid2) { $bad2 = round($invalid2 * 100 / ($hashrate + $invalid2), 2) . '%'; $title .= "{$bad2} - {$s}\n"; } } $percent = $total_hashrate && $hashrate ? round($hashrate * 100 / $total_hashrate, 2) . '%' : '';
} echo "<table class='dataGrid2'>"; echo "<thead>"; echo "<tr>"; echo "<th></th>"; echo "<th>Name</th>"; echo "<th align=right>Immature</th>"; echo "<th align=right>Confirmed</th>"; echo "<th align=right>Total</th>"; echo "<th align=right>Value*</th>"; echo "</tr>"; echo "</thead>"; $total_pending = 0; if ($show_details) { $t1 = microtime(true); $list = dbolist("select coinid from earnings where userid={$user->id} group by coinid"); if (!count($list)) { echo "<tr><td></td><td colspan=5><i>-none-</i></td></tr>"; } else { // sort by value foreach ($list as $item) { $coin = getdbo('db_coins', $item['coinid']); if (!$coin) { continue; } $name = substr($coin->name, 0, 12); $confirmed = controller()->memcache->get_database_scalar("wallet_confirmed-{$user->id}-{$coin->id}", "select sum(amount) from earnings where status=1 and userid={$user->id} and coinid={$coin->id}"); $unconfirmed = controller()->memcache->get_database_scalar("wallet_unconfirmed-{$user->id}-{$coin->id}", "select sum(amount) from earnings where status=0 and userid={$user->id} and coinid={$coin->id}"); $total = $confirmed + $unconfirmed; // $value = bitcoinvaluetoa($total * $coin->price / $refcoin->price); $value = bitcoinvaluetoa(yaamp_convert_amount_user($coin, $total, $user));
<?php echo "<br><table class='dataGrid'>"; echo "<thead>"; echo "<tr>"; echo "<th>Coin</th>"; echo "<th>Market</th>"; echo "<th>Price</th>"; echo "<th>Message</th>"; echo "<th>Deposit</th>"; echo "</tr>"; echo "</thead><tbody>"; $list = dbolist("SELECT coins.id as coinid, markets.id as marketid FROM coins, markets WHERE coins.installed AND \r\n\tcoins.id=markets.coinid AND (markets.deposit_address IS NULL or (message is not null and message!='')) order by markets.id desc"); foreach ($list as $item) { $coin = getdbo('db_coins', $item['coinid']); $market = getdbo('db_markets', $item['marketid']); echo "<tr class='ssrow'>"; echo "<td><a href='/site/coin?id={$coin->id}'>{$coin->name}</a></td>"; echo "<td>{$market->name}</td>"; echo "<td>{$market->price}</td>"; echo "<td>{$market->message}</td>"; echo "<td>{$market->deposit_address}</td>"; echo "</tr>"; } echo "</tbody></table>"; echo '<br><br><br><br><br><br><br><br><br><br>'; echo '<br><br><br><br><br><br><br><br><br><br>';
function BackendStatsUpdate2() { // debuglog('----------------------------------'); // debuglog(__FUNCTION__); //////////////////////////////////////////////////////////////////////////////////////////////////// $step = 15; $t = floor(time() / $step / 60) * $step * 60; $list = dbolist("select userid, algo from shares where time>{$t} group by userid, algo"); foreach ($list as $item) { $stats = getdbosql('db_hashuser', "time={$t} and algo=:algo and userid=:userid", array(':algo' => $item['algo'], ':userid' => $item['userid'])); if (!$stats) { $stats = new db_hashuser(); $stats->userid = $item['userid']; $stats->time = $t; $stats->hashrate = dboscalar("select hashrate from hashuser where algo=:algo and userid=:userid order by time desc limit 1", array(':algo' => $item['algo'], ':userid' => $item['userid'])); $stats->hashrate_bad = 0; $stats->algo = $item['algo']; } $percent = 20; $user_rate = yaamp_user_rate($item['userid'], $item['algo']); $stats->hashrate = round(($stats->hashrate * (100 - $percent) + $user_rate * $percent) / 100); if ($stats->hashrate < 1000) { $stats->hashrate = 0; } $user_rate_bad = yaamp_user_rate_bad($item['userid'], $item['algo']); $stats->hashrate_bad = round(($stats->hashrate_bad * (100 - $percent) + $user_rate_bad * $percent) / 100); if ($stats->hashrate_bad < 1000) { $stats->hashrate_bad = 0; } $stats->save(); } //////////////////////////////////////////////////////////////////////////////////////////////////// $step = 15; $t = floor(time() / $step / 60) * $step * 60; $list = dbolist("select distinct jobid from jobsubmits where time>{$t}"); foreach ($list as $item) { $jobid = $item['jobid']; $stats = getdbosql('db_hashrenter', "time={$t} and jobid={$jobid}"); if (!$stats) { $stats = new db_hashrenter(); // $stats->renterid = ; $stats->jobid = $item['jobid']; $stats->time = $t; $stats->hashrate = dboscalar("select hashrate from hashrenter where jobid=:jobid order by time desc limit 1", array(':jobid' => $jobid)); $stats->hashrate_bad = 0; //dboscalar("select hashrate_bad from hashrenter where jobid=$jobid order by time desc limit 1"); } $percent = 20; $job_rate = yaamp_job_rate($jobid); $stats->hashrate = round(($stats->hashrate * (100 - $percent) + $job_rate * $percent) / 100); if ($stats->hashrate < 1000) { $stats->hashrate = 0; } $job_rate_bad = yaamp_job_rate_bad($jobid); $stats->hashrate_bad = round(($stats->hashrate_bad * (100 - $percent) + $job_rate_bad * $percent) / 100); if ($stats->hashrate_bad < 1000) { $stats->hashrate_bad = 0; } $stats->save(); } //////////////////////////////////////////////////////////////////////////////////////////////////// $t = floor(time() / $step / 60) * $step * 60; $d = time() - 24 * 60 * 60; $list = getdbolist('db_accounts', "balance>0 or last_login>{$d}"); foreach ($list as $user) { $stats = getdbosql('db_balanceuser', "time={$t} and userid={$user->id}"); if (!$stats) { $stats = new db_balanceuser(); $stats->userid = $user->id; $stats->time = $t; } // $refcoin = getdbo('db_coins', $user->coinid); // if(!$refcoin) $refcoin = getdbosql('db_coins', "symbol='BTC'"); // if(!$refcoin->price || !$refcoin->price2) continue; // $pending1 = dboscalar("select sum(amount*price) from earnings where coinid=$refcoin->id and status!=2 and userid=$user->id"); // $pending2 = dboscalar("select sum(amount*price) from earnings where coinid!=$refcoin->id and status!=2 and userid=$user->id"); $stats->pending = yaamp_convert_earnings_user($user, "status!=2"); $stats->pending = bitcoinvaluetoa($stats->pending); $stats->balance = $user->balance; $stats->save(); $id = dboscalar("select id from earnings where userid={$user->id} order by id desc limit 100, 1"); if ($id) { dborun("delete from earnings where status=2 and userid={$user->id} and id<{$id}"); } } }
function BackendRentingPayout() { // debuglog(__FUNCTION__); $total_cleared = 0; foreach (yaamp_get_algos() as $algo) { $delay = time() - 5 * 60; dborun("delete from jobsubmits where status=2 and algo=:algo and time<{$delay}", array(':algo' => $algo)); $amount = dboscalar("select sum(amount) from jobsubmits where status=1 and algo=:algo", array(':algo' => $algo)); if ($amount < 2.0E-5) { continue; } dborun("update jobsubmits set status=2 where status=1 and algo=:algo", array(':algo' => $algo)); $total_cleared += $amount; $block = new db_blocks(); $block->coin_id = 0; $block->time = time(); $block->amount = $amount; $block->price = 1; $block->algo = $algo; $block->category = 'generate'; $block->save(); $total_hash_power = dboscalar("SELECT sum(difficulty) FROM shares where valid and algo=:algo", array(':algo' => $algo)); if (!$total_hash_power) { continue; } $list = dbolist("SELECT userid, sum(difficulty) as total FROM shares where valid and algo=:algo GROUP BY userid", array(':algo' => $algo)); foreach ($list as $item) { $hash_power = $item['total']; if (!$hash_power) { continue; } $user = getdbo('db_accounts', $item['userid']); if (!$user) { continue; } $earning = new db_earnings(); $earning->userid = $user->id; $earning->coinid = 0; $earning->blockid = $block->id; $earning->create_time = time(); $earning->price = 1; $earning->status = 2; // cleared $earning->amount = $amount * $hash_power / $total_hash_power; if (!$user->no_fees) { $earning->amount = take_yaamp_fee($earning->amount, $algo); } $earning->save(); $refcoin = getdbo('db_coins', $user->coinid); $value = $earning->amount / ($refcoin && $refcoin->price2 ? $refcoin->price2 : 1); // $value = yaamp_convert_amount_user($coin, $earning->amount, $user); $user->last_login = time(); $user->balance += $value; $user->save(); } $delay = time() - 5 * 60; dborun("delete from shares where algo=:algo and time<{$delay}", array(':algo' => $algo)); } if ($total_cleared > 0) { debuglog("total cleared from rental {$total_cleared} BTC"); } }
$algo = user()->getState('yaamp-algo'); $target = yaamp_hashrate_constant($algo); $interval = yaamp_hashrate_step(); $delay = time() - $interval; echo "<br><table class='dataGrid'>"; echo "<thead>"; echo "<tr>"; echo "<th>Version</th>"; echo "<th>Workers</th>"; echo "<th>Hashrate</th>"; echo "<th>Bad</th>"; echo "<th></th>"; echo "</tr>"; echo "</thead><tbody>"; $versions = dbolist("select version, count(*) as c from workers where algo=:algo group by version", array(':algo' => $algo)); foreach ($versions as $item) { $version = $item['version']; $count = $item['c']; $hashrate = dboscalar("select sum(difficulty) * {$target} / {$interval} / 1000 from shares where valid and time>{$delay} and \r\n\t\tworkerid in (select id from workers where algo=:algo and version=:version)", array(':algo' => $algo, ':version' => $version)); $invalid = dboscalar("select sum(difficulty) * {$target} / {$interval} / 1000 from shares where not valid and time>{$delay} and \r\n\t\tworkerid in (select id from workers where algo=:algo and version=:version)", array(':algo' => $algo, ':version' => $version)); $percent = $hashrate ? round($invalid * 100 / $hashrate, 3) : 0; $hashrate = Itoa2($hashrate) . 'h/s'; $invalid = Itoa2($invalid) . 'h/s'; echo "<tr class='ssrow'>"; echo "<td><b>{$version}</b></td>"; echo "<td>{$count}</td>"; echo "<td>{$hashrate}</td>"; echo "<td>{$invalid}</td>"; echo "<td align=right>{$percent}%</td>"; echo "</tr>";
echo "<td></td>"; echo "<td><a href='/site/blockuser?wallet={$user->username}'>block</a></td>"; } echo "</tr>"; } $t = time() - 24 * 60 * 60; $list = dbolist("select userid from shares where pid is null or pid not in (select pid from stratums) group by userid"); foreach ($list as $item) { showUser($item['userid'], 'pid'); } $list = dbolist("select id from accounts where balance>0.001 and id not in (select distinct userid from blocks where userid is not null and time>{$t})"); foreach ($list as $item) { showUser($item['id'], 'blocks'); } $monsters = dbolist("SELECT COUNT(*) AS total, userid FROM workers GROUP BY userid ORDER BY total DESC LIMIT 5"); foreach ($monsters as $item) { showUser($item['userid'], 'miners'); } $monsters = dbolist("SELECT COUNT(*) AS total, workerid FROM shares GROUP BY workerid ORDER BY total DESC LIMIT 5"); foreach ($monsters as $item) { $worker = getdbo('db_workers', $item['workerid']); if (!$worker) { continue; } showUser($worker->userid, 'shares'); } $list = getdbolist('db_accounts', "is_locked"); foreach ($list as $user) { showUser($user->id, 'locked'); } echo "</tbody></table>";