Exemplo n.º 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}");
        }
    }
}
Exemplo n.º 2
0
 private static function base()
 {
     $rpc = new Bitcoin(RPCUSER, RPCPASS, RPCHOST, RPCPORT);
     $info = $rpc->getinfo();
     if ($rpc->status !== 200 && $rpc->error !== '') {
         return ['err' => 'failed to connect - node not reachable, or user/pass incorrect'];
     }
     $output['rpcace_version'] = ACEVERSION;
     $output['coin_name'] = COINNAME;
     $output['num_blocks'] = $info['blocks'];
     $output['num_connections'] = $info['connections'];
     $output['version'] = $info['version'];
     $output['protocol'] = $info['protocolversion'];
     $output['moneysupply'] = $info['moneysupply'];
     if (COINPOS === true) {
         $output['current_difficulty_pow'] = $info['difficulty']['proof-of-work'];
         $output['current_difficulty_pos'] = $info['difficulty']['proof-of-stake'];
     } else {
         $output['current_difficulty_pow'] = $info['difficulty'];
     }
     if (!($hashRate = @$rpc->getmininginfo()['netmhashps']) && !($hashRate = @$rpc->getmininginfo()['networkhashps'] / 1000000)) {
         $hashRate = $rpc->getnetworkhashps() / 1000000;
     }
     $output['hashrate_mhps'] = sprintf('%.2f', $hashRate);
     $mining = $rpc->getmininginfo();
     $output['stakeweight'] = $mining['netstakeweight'];
     return ['output' => $output, 'rpc' => $rpc];
 }
Exemplo n.º 3
0
 public function actionSellto()
 {
     if (!$this->admin) {
         return;
     }
     $market = getdbo('db_markets', getiparam('id'));
     $coin = getdbo('db_coins', $market->coinid);
     $amount = getparam('amount');
     $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
     $info = $remote->getinfo();
     if (!$info || !$info['balance']) {
         return false;
     }
     $deposit_info = $remote->validateaddress($market->deposit_address);
     if (!$deposit_info || !isset($deposit_info['isvalid']) || !$deposit_info['isvalid']) {
         user()->setFlash('error', "invalid address {$coin->name}, {$market->deposit_address}");
         $this->redirect(array('site/coin', 'id' => $coin->id));
     }
     $amount = min($amount, $info['balance'] - $info['paytxfee']);
     //		$amount = max($amount, $info['balance'] - $info['paytxfee']);
     $amount = round($amount, 8);
     debuglog("selling ({$market->deposit_address}, {$amount})");
     $tx = $remote->sendtoaddress($market->deposit_address, $amount);
     if (!$tx) {
         user()->setFlash('error', $remote->error);
         $this->redirect(array('site/coin', 'id' => $coin->id));
     }
     $exchange = new db_exchange();
     $exchange->market = $market->name;
     $exchange->coinid = $coin->id;
     $exchange->send_time = time();
     $exchange->quantity = $amount;
     $exchange->price_estimate = $coin->price;
     $exchange->status = 'waiting';
     $exchange->tx = $tx;
     $exchange->save();
     $this->redirect(array('site/coin', 'id' => $coin->id));
 }
Exemplo n.º 4
0
function BackendCoinPayments($coin)
{
    //	debuglog("BackendCoinPayments $coin->symbol");
    $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
    $info = $remote->getinfo();
    if (!$info) {
        debuglog("{$coin->symbol} cant connect to coin");
        return;
    }
    $min = 0.001;
    // 	if(date("w", time()) == 0 && date("H", time()) > 12)		// sunday afternoon
    // 		$min = 0.0001;
    $users = getdbolist('db_accounts', "balance>{$min} and coinid={$coin->id}");
    if ($coin->symbol == 'MUE' || $coin->symbol == 'DIME') {
        foreach ($users as $user) {
            $user = getdbo('db_accounts', $user->id);
            if (!$user) {
                continue;
            }
            $amount = $user->balance;
            while ($user->balance > $min && $amount > $min) {
                debuglog("{$coin->symbol} sendtoaddress {$user->username} {$amount}");
                $tx = $remote->sendtoaddress($user->username, round($amount, 8));
                if (!$tx) {
                    debuglog("error {$remote->error}, {$user->username}, {$amount}");
                    if ($remote->error == 'transaction too large' || $remote->error == 'invalid amount') {
                        $amount /= 2;
                        continue;
                    }
                    break;
                }
                $payout = new db_payouts();
                $payout->account_id = $user->id;
                $payout->time = time();
                $payout->amount = bitcoinvaluetoa($amount);
                $payout->fee = 0;
                $payout->tx = $tx;
                $payout->save();
                $user->balance -= $amount;
                $user->save();
            }
        }
        debuglog("payment done");
        return;
    }
    $total_to_pay = 0;
    $addresses = array();
    foreach ($users as $user) {
        $total_to_pay += round($user->balance, 8);
        $addresses[$user->username] = round($user->balance, 8);
    }
    if (!$total_to_pay) {
        //	debuglog("nothing to pay");
        return;
    }
    if ($info['balance'] - 0.001 < $total_to_pay) {
        debuglog("{$coin->symbol} wallet insufficient funds for payment {$info['balance']} < {$total_to_pay}");
        return;
    }
    if ($coin->symbol == 'BTC') {
        global $cold_wallet_table;
        $balance = $info['balance'];
        $stats = getdbosql('db_stats', "1 order by time desc");
        $renter = dboscalar("select sum(balance) from renters");
        $pie = $balance - $total_to_pay - $renter - 1;
        debuglog("pie to split is {$pie}");
        if ($pie > 0) {
            foreach ($cold_wallet_table as $coldwallet => $percent) {
                $coldamount = round($pie * $percent, 8);
                if ($coldamount < $min) {
                    break;
                }
                debuglog("paying cold wallet {$coldwallet} {$coldamount}");
                $addresses[$coldwallet] = $coldamount;
                $total_to_pay += $coldamount;
            }
        }
    }
    debuglog("paying {$total_to_pay} {$coin->symbol} min is {$min}");
    $tx = $remote->sendmany('', $addresses, 1, '');
    if (!$tx) {
        debuglog($remote->error);
        return;
    }
    foreach ($users as $user) {
        $user = getdbo('db_accounts', $user->id);
        if (!$user) {
            continue;
        }
        $payout = new db_payouts();
        $payout->account_id = $user->id;
        $payout->time = time();
        $payout->amount = bitcoinvaluetoa($user->balance);
        $payout->fee = 0;
        $payout->tx = $tx;
        $payout->save();
        $user->balance = 0;
        $user->save();
    }
    debuglog("payment done");
    sleep(5);
}
Exemplo n.º 5
0
$abort = false;
$numAddresses = 100;
$txBufferSize = 150;
$resume = "{$rpcUser}-{$rpcPort}-tally.dat";
if (!isset($argv[1])) {
    die("Usage: php {$argv[0]} <output filename>\n");
}
function handleInt()
{
    global $abort;
    $abort = true;
}
pcntl_signal(SIGINT, 'handleInt');
require_once 'easybitcoin.php';
$rpc = new Bitcoin($rpcUser, $rpcPass, $rpcHost, $rpcPort);
$numBlocks = $rpc->getinfo()['blocks'];
if ($rpc->status !== 200 && $rpc->error !== '') {
    die("Failed to connect. Check your coin's .conf file and your RPC parameters.\n");
}
$i = $txTotal = 0;
if (file_exists($resume)) {
    $tally = unserialize(file_get_contents($resume));
    if ($tally['tally'] === true) {
        if ($numBlocks > $tally['last']) {
            $i = $tally['last'];
            $txTotal = $tally['txTotal'];
            $addresses = $tally['addresses'];
            $numAddresses = $tally['numAddresses'];
            echo "resuming from block {$i} - ";
        } else {
            $rpc = null;
Exemplo n.º 6
0
/**
 * Connects to Bitcoin daemon and retrieves information, then writes to cache
 *
 * @param string $from_cache Whether to get the data from cache or not
 *
 * @return array
 */
function getData($from_cache = false)
{
    global $config;
    global $cache_message;
    // If we're getting data from cache, do it
    if ($from_cache === true && is_file($config['cache_file'])) {
        $cache = json_decode(file_get_contents($config['cache_file']), true);
        // Only proceed if the array is a cache - invalid otherwise
        if (is_array($cache)) {
            if ($cache['config_hash'] == md5(json_encode($config))) {
                if (time() < $cache['cache_expiry']) {
                    return $cache;
                }
            } else {
                $cache_message = 'Configuration has changed, cache has been refreshed.';
            }
        }
    }
    // Include EasyBitcoin library and set up connection
    include_once './php/easybitcoin.php';
    $bitcoin = new Bitcoin($config['rpc_user'], $config['rpc_pass'], $config['rpc_host'], $config['rpc_port']);
    // Setup SSL if configured
    if ($config['rpc_ssl'] === true) {
        $bitcoin->setSSL($config['rpc_ssl_ca']);
    }
    // Get info
    $data = $bitcoin->getinfo();
    // Handle errors if they happened
    if (!$data) {
        $return_data['error'] = $bitcoin->error;
        $return_data['status'] = $bitcoin->status;
        writeToCache($return_data);
        return $return_data;
    }
    // Get free disk space
    if ($config['display_free_disk_space'] === true) {
        $data['free_disk_space'] = getFreeDiskSpace();
    }
    if (isset($config['display_ip']) && $config['display_ip'] === true) {
        // Use bitcoind IP
        if ($config['use_bitcoind_ip'] === true) {
            $net_info = $bitcoin->getnetworkinfo();
            $data['node_ip'] = $net_info['localaddresses'][0]['address'];
        } else {
            $data['node_ip'] = $_SERVER['SERVER_ADDR'];
        }
    }
    // Add peer info
    if ($config['display_peer_info'] === true) {
        $data['peers'] = parsePeers($bitcoin->getpeerinfo());
    }
    // Node geolocation
    if ($config['display_ip_location'] === true && $config['display_ip'] === true) {
        $data['ip_location'] = getGeolocation($data['node_ip'], 'all');
    }
    // Bitcoin Daemon uptime
    if ($config['display_bitcoind_uptime'] === true || strcmp(PHP_OS, "Linux") == 0) {
        $data['bitcoind_uptime'] = getProcessUptime($config['bitcoind_process_name']);
    }
    // Get max height from bitnodes.21.co
    if ($config['display_max_height'] === true) {
        $bitnodes_ch = curl_init();
        curl_setopt($bitnodes_ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($bitnodes_ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($bitnodes_ch, CURLOPT_USERAGENT, 'Bitcoin Node Status Page');
        curl_setopt($bitnodes_ch, CURLOPT_URL, "https://bitnodes.21.co/api/v1/snapshots/");
        $exec_result = json_decode(curl_exec($bitnodes_ch), true);
        // Don't close handle if we reuse it
        if ($config['display_bitnodes_info'] !== true) {
            curl_close($bitnodes_ch);
        }
        $data['max_height'] = $exec_result['results'][0]['latest_height'];
        $data['node_height_percent'] = round($data['blocks'] / $data['max_height'] * 100, 1);
    }
    // Get node info from bitnodes.21.co
    if ($config['display_bitnodes_info'] === true) {
        if ($bitnodes_ch === false) {
            $bitnodes_ch = curl_init();
            curl_setopt($bitnodes_ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($bitnodes_ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($bitnodes_ch, CURLOPT_USERAGENT, 'Bitcoin Node Status Page');
        }
        // Get node info
        curl_setopt($bitnodes_ch, CURLOPT_URL, "https://getaddr.bitnodes.21.co/api/v1/nodes/" . $data['node_ip'] . "-8333/");
        $data['bitnodes_info'] = json_decode(curl_exec($bitnodes_ch), true);
        // Get latency info
        curl_setopt($bitnodes_ch, CURLOPT_URL, "https://getaddr.bitnodes.21.co/api/v1/nodes/" . $data['node_ip'] . "-8333/latency/");
        $latency = json_decode(curl_exec($bitnodes_ch), true);
        $data['bitnodes_info']['latest_latency'] = $latency['daily_latency'][0];
    }
    // Get chart data
    if ($config['display_chart'] === true & is_file($config['stats_file'])) {
        $data['chart'] = json_decode(file_get_contents($config['stats_file']), true);
    }
    writeToCache($data);
    return $data;
}
Exemplo n.º 7
0
    $data = array();
}
// If viewing is enabled, just output and die
if (isset($_GET['view'])) {
    print_r($data);
    die;
}
// Include EasyBitcoin library and set up connection
require_once './php/easybitcoin.php';
$bitcoin = new Bitcoin($config['rpc_user'], $config['rpc_pass'], $config['rpc_host'], $config['rpc_port']);
// Setup SSL if configured
if ($config['rpc_ssl'] === true) {
    $bitcoin->setSSL($config['rpc_ssl_ca']);
}
// Get info and handle errors
$new_raw_data = $bitcoin->getinfo();
if (!$new_raw_data) {
    die("RPC Error");
}
// Append to array
$data[] = array('time' => time(), 'connections' => $new_raw_data['connections']);
// Purge old data
for ($i = 0; $i < count($data); $i++) {
    if ($data[$i]['time'] < time() - $config['stats_max_age']) {
        array_splice($data, $i, 1);
    }
}
// Save array
if (file_put_contents($config['stats_file'], json_encode($data), LOCK_EX) === false) {
    die("Failure storing data");
}
Exemplo n.º 8
0
echo "<th>Conns</th>";
echo "<th>Price</th>";
echo "<th>Reward</th>";
echo "<th>Index *</th>";
echo "</tr>";
echo "</thead><tbody>";
echo "<tr class='ssrow'>";
echo "<td><img src='{$coin->image}' width=24></td>";
if ($coin->enable) {
    echo "<td>[ + ]</td>";
} else {
    echo "<td>[&nbsp;&nbsp;&nbsp;&nbsp;]</td>";
}
echo "<td><b><a href='/site/coin?id={$coin->id}'>{$coin->name}</a></b></td>";
echo "<td><b>{$coin->symbol}</b></td>";
$info = $remote->getinfo();
if (!$info) {
    echo "ERROR {$remote->error}<br><br>";
    //	echo "<td></td>";
    return;
}
$errors = isset($info['errors']) ? $info['errors'] : '';
$balance = isset($info['balance']) ? $info['balance'] : '';
$txfee = isset($info['paytxfee']) ? $info['paytxfee'] : '';
$connections = isset($info['connections']) ? $info['connections'] : '';
$blocks = isset($info['blocks']) ? $info['blocks'] : '';
echo "<td>{$coin->difficulty}</td>";
if (!empty($errors)) {
    echo "<td style='color: red;' title='{$errors}'>{$blocks}</td>";
} else {
    echo "<td>{$blocks}</td>";
Exemplo n.º 9
0
function BackendCoinsUpdate()
{
    //	debuglog(__FUNCTION__);
    $t1 = microtime(true);
    $pool_rate = array();
    foreach (yaamp_get_algos() as $algo) {
        $pool_rate[$algo] = yaamp_pool_rate($algo);
    }
    $coins = getdbolist('db_coins', "installed");
    foreach ($coins as $coin) {
        //		debuglog("doing $coin->name");
        $coin = getdbo('db_coins', $coin->id);
        if (!$coin) {
            continue;
        }
        $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
        $info = $remote->getinfo();
        if (!$info) {
            $coin->enable = false;
            //	$coin->auto_ready = false;
            $coin->connections = 0;
            $coin->save();
            continue;
        }
        //		debuglog($info);
        $coin->enable = true;
        if (isset($info['difficulty'])) {
            $difficulty = $info['difficulty'];
        } else {
            $difficulty = $remote->getdifficulty();
        }
        if (is_array($difficulty)) {
            $coin->difficulty = $difficulty['proof-of-work'];
            if (isset($difficulty['proof-of-stake'])) {
                $coin->difficulty_pos = $difficulty['proof-of-stake'];
            }
        } else {
            $coin->difficulty = $difficulty;
        }
        if ($coin->algo == 'quark') {
            $coin->difficulty /= 0x100;
        }
        if ($coin->difficulty == 0) {
            $coin->difficulty = 1;
        }
        $coin->errors = isset($info['errors']) ? $info['errors'] : '';
        $coin->txfee = isset($info['paytxfee']) ? $info['paytxfee'] : '';
        $coin->connections = isset($info['connections']) ? $info['connections'] : '';
        $coin->balance = isset($info['balance']) ? $info['balance'] : 0;
        $coin->mint = dboscalar("select sum(amount) from blocks where coin_id={$coin->id} and category='immature'");
        if (empty($coin->master_wallet)) {
            $coin->master_wallet = $remote->getaccountaddress('');
            //	debuglog($coin->master_wallet);
        }
        if (empty($coin->rpcencoding)) {
            $difficulty = $remote->getdifficulty();
            if (is_array($difficulty)) {
                $coin->rpcencoding = 'POS';
            } else {
                $coin->rpcencoding = 'POW';
            }
        }
        if ($coin->hassubmitblock == NULL) {
            $remote->submitblock('');
            if (strcasecmp($remote->error, 'method not found') == 0) {
                $coin->hassubmitblock = false;
            } else {
                $coin->hassubmitblock = true;
            }
        }
        if ($coin->auxpow == NULL) {
            $ret = $remote->getauxblock();
            if (strcasecmp($remote->error, 'method not found') == 0) {
                $coin->auxpow = false;
            } else {
                $coin->auxpow = true;
            }
        }
        //		if($coin->symbol != 'BTC')
        //		{
        //			if($coin->symbol == 'PPC')
        //				$template = $remote->getblocktemplate('');
        //			else
        $template = $remote->getblocktemplate('{}');
        if ($template && isset($template['coinbasevalue'])) {
            $coin->reward = $template['coinbasevalue'] / 100000000 * $coin->reward_mul;
            if ($coin->symbol == 'TAC' && isset($template['_V2'])) {
                $coin->charity_amount = $template['_V2'] / 100000000;
            }
            if (isset($template['payee_amount']) && $coin->symbol != 'LIMX') {
                $coin->charity_amount = $template['payee_amount'] / 100000000;
                $coin->reward -= $coin->charity_amount;
                //	debuglog("$coin->symbol $coin->charity_amount $coin->reward");
            } else {
                if (!empty($coin->charity_address)) {
                    if ($coin->charity_amount) {
                    } else {
                        $coin->reward -= $coin->reward * $coin->charity_percent / 100;
                    }
                }
            }
            if (isset($template['bits'])) {
                $target = decode_compact($template['bits']);
                $coin->difficulty = target_to_diff($target);
            }
        } else {
            if (strcasecmp($remote->error, 'method not found') == 0) {
                $template = $remote->getmemorypool();
                if ($template && isset($template['coinbasevalue'])) {
                    $coin->usememorypool = true;
                    $coin->reward = $template['coinbasevalue'] / 100000000 * $coin->reward_mul;
                    if (isset($template['bits'])) {
                        $target = decode_compact($template['bits']);
                        $coin->difficulty = target_to_diff($target);
                    }
                } else {
                    $coin->auto_ready = false;
                    $coin->errors = $remote->error;
                }
            } else {
                $coin->auto_ready = false;
                $coin->errors = $remote->error;
            }
        }
        if (strcasecmp($coin->errors, 'No more PoW blocks') == 0) {
            $coin->dontsell = true;
            $coin->auto_ready = false;
        }
        //		}
        if ($coin->block_height != $info['blocks']) {
            $count = $info['blocks'] - $coin->block_height;
            $ttf = (time() - $coin->last_network_found) / $count;
            if (empty($coin->actual_ttf)) {
                $coin->actual_ttf = $ttf;
            }
            $coin->actual_ttf = percent_feedback($coin->actual_ttf, $ttf, 5);
            $coin->last_network_found = time();
        }
        $coin->version = $info['version'];
        $coin->block_height = $info['blocks'];
        $coin->save();
        //	debuglog(" end $coin->name");
    }
    $coins = getdbolist('db_coins', "enable order by auxpow desc");
    foreach ($coins as $coin) {
        $coin = getdbo('db_coins', $coin->id);
        if (!$coin) {
            continue;
        }
        if ($coin->difficulty) {
            $coin->index_avg = $coin->reward * $coin->price * 10000 / $coin->difficulty;
            if (!$coin->auxpow && $coin->rpcencoding == 'POW') {
                $indexaux = dboscalar("select sum(index_avg) from coins where enable and visible and auto_ready and auxpow and algo='{$coin->algo}'");
                $coin->index_avg += $indexaux;
            }
        }
        if ($coin->network_hash) {
            $coin->network_ttf = $coin->difficulty * 0x100000000 / $coin->network_hash;
        }
        if (isset($pool_rate[$coin->algo])) {
            $coin->pool_ttf = $coin->difficulty * 0x100000000 / $pool_rate[$coin->algo];
        }
        if (strstr($coin->image, 'http')) {
            $data = file_get_contents($coin->image);
            $coin->image = "/images/coin-{$coin->id}.png";
            @unlink(YAAMP_HTDOCS . $coin->image);
            file_put_contents(YAAMP_HTDOCS . $coin->image, $data);
        }
        $coin->save();
    }
    $d1 = microtime(true) - $t1;
    controller()->memcache->add_monitoring_function(__METHOD__, $d1);
}
Exemplo n.º 10
0
       font-size: 17px;
       white-space: pre; }
a { color: #303030; }
div.mid { width: 900px;
          margin: 2% auto; }
td { width: 16%; }
td.urgh { width: 100%; }
td.key { text-align: right; }
td.value { padding-left: 16px; width: 100%; }
tr.illu:hover { background-color: #c8c8c8; }
</style>
</head>
<body>
<?php 
$rpc = new Bitcoin($rpcUser, $rpcPass, $rpcHost, $rpcPort);
$info = $rpc->getinfo();
if ($rpc->status !== 200 && $rpc->error !== '') {
    die('Failed to connect. Check your coin\'s .conf file and your RPC parameters.');
}
if ($coinPoS === true) {
    $diffNom = 'Difficulty &middot; PoS';
    $diff = sprintf('%.4f', $info['difficulty']['proof-of-work']) . ' &middot; ' . sprintf('%.4f', $info['difficulty']['proof-of-stake']);
    $hashRate = $rpc->getmininginfo()['netmhashps'];
} else {
    $diffNom = 'Difficulty';
    $diff = $info['difficulty'];
    $hashRate = $rpc->getnetworkhashps() / 1000000;
}
$hashRate = sprintf('%.2f', $hashRate);
echo "<div class=\"mid\"><table><tr><td class=\"urgh\"><b><a href=\"{$coinHome}\">{$coinName}</a></b> block explorer</td><td>Blocks:</td><td><a href=\"?{$info['blocks']}\">{$info['blocks']}</a></td></tr>";
echo "<tr><td /><td>{$diffNom}:</td><td>{$diff}</td></tr>";
Exemplo n.º 11
0
function sellCoinToExchange($coin)
{
    if ($coin->dontsell) {
        return;
    }
    $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
    $info = $remote->getinfo();
    if (!$info || !$info['balance']) {
        return false;
    }
    if (!empty($coin->symbol2)) {
        $coin2 = getdbosql('db_coins', "symbol='{$coin->symbol2}'");
        if (!$coin2) {
            return;
        }
        $amount = $info['balance'] - $info['paytxfee'];
        $amount *= 0.9;
        //		debuglog("sending $amount $coin->symbol to main wallet");
        $tx = $remote->sendtoaddress($coin2->master_wallet, $amount);
        //		if(!$tx) debuglog($remote->error);
        return;
    }
    $market = getBestMarket($coin);
    if (!$market) {
        return;
    }
    if (!$coin->sellonbid && $market->lastsent != null && $market->lastsent > $market->lasttraded) {
        //		debuglog("*** not sending $coin->name to $market->name. last tx is late ***");
        return;
    }
    $deposit_address = $market->deposit_address;
    $marketname = $market->name;
    if (empty($deposit_address)) {
        return false;
    }
    $reserved1 = dboscalar("select sum(balance) from accounts where coinid={$coin->id}");
    $reserved2 = dboscalar("select sum(amount*price) from earnings\n\t\twhere status!=2 and userid in (select id from accounts where coinid={$coin->id})");
    $reserved = ($reserved1 + $reserved2) * 10;
    $amount = $info['balance'] - $info['paytxfee'] - $reserved;
    //	if($reserved>0)
    //	{
    //		debuglog("$reserved1 $reserved2 out of {$info['balance']}");
    //		debuglog("reserving $reserved $coin->symbol out of $coin->balance, available $amount");
    //	}
    if ($amount < $coin->reward / 4) {
        //	debuglog("not enough $coin->symbol to sell $amount < $coin->reward /4");
        return false;
    }
    $deposit_info = $remote->validateaddress($deposit_address);
    if (!$deposit_info || !isset($deposit_info['isvalid']) || !$deposit_info['isvalid']) {
        debuglog("sell invalid address {$deposit_address}");
        return;
    }
    $amount = round($amount, 8);
    //	debuglog("sending $amount $coin->symbol to $marketname, $deposit_address");
    $market->lastsent = time();
    $market->save();
    //	sleep(1);
    $tx = $remote->sendtoaddress($deposit_address, $amount);
    if (!$tx) {
        //	debuglog($remote->error);
        if ($coin->symbol == 'MUE') {
            $amount = min($amount, 5000);
        } else {
            if ($coin->symbol == 'DIME') {
                $amount = min($amount, 10000000);
            } else {
                if ($coin->symbol == 'CNOTE') {
                    $amount = min($amount, 10000);
                } else {
                    if ($coin->symbol == 'SRC') {
                        $amount = min($amount, 500);
                    } else {
                        $amount = round($amount * 0.99, 8);
                    }
                }
            }
        }
        //		debuglog("sending $amount $coin->symbol to $deposit_address");
        sleep(1);
        $tx = $remote->sendtoaddress($deposit_address, $amount);
        if (!$tx) {
            debuglog("sending {$amount} {$coin->symbol} to {$deposit_address}");
            debuglog($remote->error);
            return;
        }
    }
    $exchange = new db_exchange();
    $exchange->market = $marketname;
    $exchange->coinid = $coin->id;
    $exchange->send_time = time();
    $exchange->quantity = $amount;
    $exchange->price_estimate = $coin->price;
    $exchange->status = 'waiting';
    $exchange->tx = $tx;
    $exchange->save();
    return;
}