Ejemplo n.º 1
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}");
}
Ejemplo n.º 2
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");
    }
}