Exemple #1
0
function BackendBlockFind2()
{
    $coins = getdbolist('db_coins', "enable");
    foreach ($coins as $coin) {
        if ($coin->symbol == 'BTC') {
            continue;
        }
        $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
        $mostrecent = 0;
        if ($coin->lastblock == null) {
            $coin->lastblock = '';
        }
        $list = $remote->listsinceblock($coin->lastblock);
        if (!$list) {
            continue;
        }
        //		debuglog("find2 $coin->symbol");
        foreach ($list['transactions'] as $transaction) {
            if ($transaction['time'] > time() - 5 * 60) {
                continue;
            }
            if (!isset($transaction['blockhash'])) {
                continue;
            }
            if ($transaction['time'] > $mostrecent) {
                $coin->lastblock = $transaction['blockhash'];
                $mostrecent = $transaction['time'];
            }
            if ($transaction['time'] < time() - 60 * 60) {
                continue;
            }
            if ($transaction['category'] != 'generate' && $transaction['category'] != 'immature') {
                continue;
            }
            $blockext = $remote->getblock($transaction['blockhash']);
            $db_block = getdbosql('db_blocks', "blockhash='{$transaction['blockhash']}' or height={$blockext['height']}");
            if ($db_block) {
                continue;
            }
            //			debuglog("adding lost block $coin->name {$blockext['height']}");
            $db_block = new db_blocks();
            $db_block->blockhash = $transaction['blockhash'];
            $db_block->coin_id = $coin->id;
            $db_block->category = 'immature';
            //$transaction['category'];
            $db_block->time = $transaction['time'];
            $db_block->amount = $transaction['amount'];
            $db_block->confirmations = $transaction['confirmations'];
            $db_block->height = $blockext['height'];
            $db_block->difficulty = $blockext['difficulty'];
            $db_block->price = $coin->price;
            $db_block->algo = $coin->algo;
            $db_block->save();
            BackendBlockNew($coin, $db_block);
        }
        $coin->save();
    }
}
Exemple #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");
    }
}