Example #1
0
 public function actionStatus()
 {
     if (!LimitRequest('api-status', 10)) {
         return;
     }
     echo "{";
     foreach (yaamp_get_algos() as $i => $algo) {
         if ($i) {
             echo ", ";
         }
         $coins = controller()->memcache->get_database_count_ex("api_status_coins-{$algo}", 'db_coins', "enable and visible and auto_ready and algo=:algo", array(':algo' => $algo));
         $hashrate = controller()->memcache->get_database_scalar("api_status_hashrate-{$algo}", "select hashrate from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
         $price = controller()->memcache->get_database_scalar("api_status_price-{$algo}", "select price from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
         $price = bitcoinvaluetoa(take_yaamp_fee($price / 1000, $algo));
         $rental = controller()->memcache->get_database_scalar("api_status_price-{$algo}", "select rent from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
         $rental = bitcoinvaluetoa($rental);
         $t = time() - 24 * 60 * 60;
         $avgprice = controller()->memcache->get_database_scalar("api_status_avgprice-{$algo}", "select avg(price) from hashrate where algo=:algo and time>{$t}", array(':algo' => $algo));
         $avgprice = bitcoinvaluetoa(take_yaamp_fee($avgprice / 1000, $algo));
         $total1 = controller()->memcache->get_database_scalar("api_status_total-{$algo}", "select sum(amount*price) from blocks where category!='orphan' and time>{$t} and algo=:algo", array(':algo' => $algo));
         $hashrate1 = controller()->memcache->get_database_scalar("api_status_avghashrate-{$algo}", "select avg(hashrate) from hashrate where time>{$t} and algo=:algo", array(':algo' => $algo));
         //			$btcmhday1 = $hashrate1 != 0? bitcoinvaluetoa($total1 / $hashrate1 * 1000000): '0.00000000';
         if ($algo == 'sha256') {
             $btcmhday1 = $hashrate1 != 0 ? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000000) : '0';
         } else {
             $btcmhday1 = $hashrate1 != 0 ? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000) : '0';
         }
         $fees = yaamp_fee($algo);
         $port = getAlgoPort($algo);
         if ($port == '-') {
             $port = 0;
         }
         echo "\"{$algo}\": ";
         echo "{";
         echo "\"name\": \"{$algo}\", ";
         echo "\"port\": {$port}, ";
         echo "\"coins\": {$coins}, ";
         echo "\"fees\": {$fees}, ";
         echo "\"hashrate\": {$hashrate}, ";
         echo "\"estimate_current\": {$price}, ";
         echo "\"estimate_last24h\": {$avgprice}, ";
         echo "\"actual_last24h\": {$btcmhday1}, ";
         echo "\"rental_current\": {$rental}";
         echo "}";
     }
     echo "}";
 }
Example #2
0
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}");
}
Example #3
0
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");
    }
}
Example #4
0
echo "<th align=right>Jobs</th>";
echo "<th align=right>Total</th>";
//echo "<th>For Rent**</th>";
echo "<th align=right>Rented</th>";
echo "<th></th>";
echo "<th align=right>Available</th>";
//echo "<th>Paying</th>";
echo "<th align=right>Current Price</th>";
echo "</tr>";
echo "</thead>";
$algos = array();
foreach (yaamp_get_algos() as $algo) {
    $algo_norm = yaamp_get_algo_norm($algo);
    $price = controller()->memcache->get_database_scalar("current_price-{$algo}", "select price from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
    $norm = $price * $algo_norm;
    $norm = take_yaamp_fee($norm, $algo);
    $algos[] = array($norm, $algo);
}
function cmp($a, $b)
{
    return $a[0] < $b[0];
}
usort($algos, 'cmp');
foreach ($algos as $item) {
    $norm = $item[0];
    $algo = $item[1];
    $count1 = getdbocount('db_jobs', "algo=:algo and ready and active", array(':algo' => $algo));
    $count2 = getdbocount('db_jobs', "algo=:algo and ready", array(':algo' => $algo));
    $total = yaamp_pool_rate($algo);
    $hashrate = yaamp_pool_rate_rentable($algo);
    $hashrate_jobs = yaamp_rented_rate($algo);
Example #5
0
 $hashrate_bad = dboscalar("select hashrate_bad from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
 $bad = $hashrate + $hashrate_bad ? round($hashrate_bad * 100 / ($hashrate + $hashrate_bad), 1) : '';
 $total_hashrate += $hashrate;
 $total_hashrate_bad += $hashrate_bad;
 $hashrate = $hashrate ? Itoa2($hashrate) . 'h/s' : '-';
 $hashrate_bad = $hashrate_bad ? Itoa2($hashrate_bad) . 'h/s' : '-';
 $hashrate_jobs = yaamp_rented_rate($algo);
 $hashrate_jobs = $hashrate_jobs > 0 ? Itoa2($hashrate_jobs) . 'h/s' : '';
 $price = dboscalar("select price from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
 $price = $price ? mbitcoinvaluetoa($price) : '-';
 $rent = dboscalar("select rent from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
 $rent = $rent ? mbitcoinvaluetoa($rent) : '-';
 $norm = mbitcoinvaluetoa($norm);
 $t = time() - 24 * 60 * 60;
 $avgprice = dboscalar("select avg(price) from hashrate where algo=:algo and time>{$t}", array(':algo' => $algo));
 $avgprice = $avgprice ? mbitcoinvaluetoa(take_yaamp_fee($avgprice, $algo)) : '-';
 $t1 = time() - 24 * 60 * 60;
 $total1 = dboscalar("select sum(amount*price) from blocks where category!='orphan' and time>{$t1} and algo=:algo", array(':algo' => $algo));
 $hashrate1 = dboscalar("select avg(hashrate) from hashrate where time>{$t1} and algo=:algo", array(':algo' => $algo));
 if ($algo == 'sha256') {
     $btcmhday1 = $hashrate1 != 0 ? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000000) : '';
 } else {
     $btcmhday1 = $hashrate1 != 0 ? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000) : '';
 }
 $fees = yaamp_fee($algo);
 $stratum = getdbosql('db_stratums', "algo=:algo", array(':algo' => $algo));
 $isup = Booltoa($stratum);
 echo "<tr class='ssrow'>";
 echo "<td style='background-color: {$algo_color}'><b><a href='/site/gomining?algo={$algo}'>{$algo}</a></b></td>";
 echo "<td align=right'>{$isup}</td>";
 echo "<td align=right style='font-size: .8em;'>{$coins}</td>";