Beispiel #1
1
function BackendUpdateDeposit()
{
    //	debuglog(__FUNCTION__);
    $btc = getdbosql('db_coins', "symbol='BTC'");
    if (!$btc) {
        return;
    }
    $remote = new Bitcoin($btc->rpcuser, $btc->rpcpasswd, $btc->rpchost, $btc->rpcport);
    $info = $remote->getinfo();
    if (!$info) {
        return;
    }
    if (!isset($info['blocks'])) {
        return;
    }
    $hash = $remote->getblockhash(intval($info['blocks']));
    if (!$hash) {
        return;
    }
    $block = $remote->getblock($hash);
    if (!$block) {
        return;
    }
    if (!isset($block['time'])) {
        return;
    }
    if ($block['time'] + 30 * 60 < time()) {
        return;
    }
    $list = $remote->listaccounts(1);
    foreach ($list as $r => $a) {
        if ($a == 0) {
            continue;
        }
        $b = preg_match('/renter-prod-([0-9]+)/', $r, $m);
        if (!$b) {
            continue;
        }
        $renter = getdbo('db_renters', $m[1]);
        if (!$renter) {
            continue;
        }
        $ts = $remote->listtransactions(yaamp_renter_account($renter), 1);
        if (!$ts || !isset($ts[0])) {
            continue;
        }
        $moved = $remote->move(yaamp_renter_account($renter), '', $a);
        if (!$moved) {
            continue;
        }
        debuglog("deposit {$renter->id} {$renter->address}, {$a}");
        $rentertx = new db_rentertxs();
        $rentertx->renterid = $renter->id;
        $rentertx->time = time();
        $rentertx->amount = $a;
        $rentertx->type = 'deposit';
        $rentertx->tx = isset($ts[0]['txid']) ? $ts[0]['txid'] : '';
        $rentertx->save();
        $renter->unconfirmed = 0;
        $renter->balance += $a;
        $renter->updated = time();
        $renter->save();
    }
    $list = $remote->listaccounts(0);
    foreach ($list as $r => $a) {
        if ($a == 0) {
            continue;
        }
        $b = preg_match('/renter-prod-([0-9]+)/', $r, $m);
        if (!$b) {
            continue;
        }
        $renter = getdbo('db_renters', $m[1]);
        if (!$renter) {
            continue;
        }
        debuglog("unconfirmed {$renter->id} {$renter->address}, {$a}");
        $renter->unconfirmed = $a;
        $renter->updated = time();
        $renter->save();
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////
    $received1 = $remote->getbalance('bittrex', 1);
    //nicehash payments
    if ($received1 > 0) {
        $moved = $remote->move('bittrex', '', $received1);
        debuglog("moved from bittrex {$received1}");
        dborun("update renters set balance=balance+{$received1} where id=7");
        dborun("update renters set custom_start=custom_start+{$received1} where id=7");
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////
    $fees = 0.0001;
    $list = getdbolist('db_rentertxs', "type='withdraw' and tx='scheduled'");
    foreach ($list as $tx) {
        $renter = getdbo('db_renters', $tx->renterid);
        if (!$renter) {
            continue;
        }
        //		debuglog("$renter->balance < $tx->amount + $fees");
        $tx->amount = bitcoinvaluetoa(min($tx->amount, $renter->balance - $fees));
        if ($tx->amount < $fees * 2) {
            $tx->tx = 'failed';
            $tx->save();
            continue;
        }
        debuglog("withdraw send {$renter->id} {$renter->address} sendtoaddress({$tx->address}, {$tx->amount})");
        $tx->tx = $remote->sendtoaddress($tx->address, round($tx->amount, 8));
        if (!$tx->tx) {
            $tx->tx = 'failed';
            $tx->save();
            continue;
        }
        $renter->balance -= $tx->amount + $fees;
        $renter->balance = max($renter->balance, 0);
        dborun("update renters set balance={$renter->balance} where id={$renter->id}");
        $tx->save();
        if ($renter->balance <= 0.0001) {
            dborun("update jobs set active=false, ready=false where id={$renter->id}");
        }
    }
}
Beispiel #2
0
echo "<div class='main-left-inner'>";
echo "<table class='dataGrid2'>";
echo "<thead class=''>";
echo "<tr>";
echo "<th>Time</th>";
echo "<th>Amount</th>";
echo "<th>Confirmations</th>";
echo "<th>Tx</th>";
echo "</tr>";
echo "</thead><tbody>";
$btc = getdbosql('db_coins', "symbol='BTC'");
if (!$btc) {
    return;
}
$remote = new Bitcoin($btc->rpcuser, $btc->rpcpasswd, $btc->rpchost, $btc->rpcport);
$ts = $remote->listtransactions(yaamp_renter_account($renter), 10);
$res_array = array();
foreach ($ts as $val) {
    $t = $val['time'];
    if ($t < $renter->created) {
        continue;
    }
    $res_array[$t] = $val;
}
krsort($res_array);
$total = 0;
foreach ($res_array as $transaction) {
    if ($transaction['category'] != 'receive') {
        continue;
    }
    $d = datetoa2($transaction['time']);
Beispiel #3
0
$b = $captcha->validate($code, false);
if (!$b) {
    controller()->redirect('/renting');
    return;
}
// get a new btc address
$btc = getdbosql('db_coins', "symbol='BTC'");
if (!$btc) {
    return;
}
$remote = new Bitcoin($btc->rpcuser, $btc->rpcpasswd, $btc->rpchost, $btc->rpcport);
$renter = new db_renters();
$renter->created = time();
$renter->updated = time();
$renter->balance = 0;
$renter->unconfirmed = 0;
$renter->save();
$renter = getdbo('db_renters', $renter->id);
$renter->address = $remote->getaccountaddress(yaamp_renter_account($renter));
$renter->apikey = hash("sha256", $renter->address . time() . rand());
$renter->save();
$received1 = $remote->getbalance(yaamp_renter_account($renter), 1);
if ($received1 > 0) {
    $moved = $remote->move(yaamp_renter_account($renter), '', $received1);
    debuglog("create new renter, moving initial {$received1}");
}
$recents = isset($_COOKIE['deposits']) ? unserialize($_COOKIE['deposits']) : array();
$recents[$renter->address] = $renter->address;
setcookie('deposits', serialize($recents), time() + 60 * 60 * 24 * 30, '/');
user()->setState('yaamp-deposit', $renter->address);
controller()->redirect('settings');