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}"); } } }
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(); } }
echo "<tr>"; echo "<th>Time</th>"; echo "<th>Height</th>"; echo "<th>Diff</th>"; echo "<th>Transactions</th>"; echo "<th>Confirmations</th>"; echo "<th>Blockhash</th>"; echo "</tr>"; echo "</thead>"; $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport); for ($i = $coin->block_height; $i > $coin->block_height - 25; $i--) { $hash = $remote->getblockhash($i); if (!$hash) { continue; } $block = $remote->getblock($hash); if (!$block) { continue; } $d = datetoa2($block['time']); $confirms = isset($block['confirmations']) ? $block['confirmations'] : ''; $tx = count($block['tx']); $diff = $block['difficulty']; // debuglog($block); echo "<tr class='ssrow'>"; echo "<td>{$d}</td>"; echo "<td><a href='/explorer?id={$coin->id}&height={$i}'>{$i}</a></td>"; echo "<td>{$diff}</td>"; echo "<td>{$tx}</td>"; echo "<td>{$confirms}</td>"; echo "<td><span style='font-family: monospace;'><a href='/explorer?id={$coin->id}&hash={$hash}'>{$hash}</a></span></td>";
echo "<th>Confirmations</th>"; echo "<th></th>"; echo "</tr>"; echo "</thead><tbody>"; //$transactions = $remote->listsinceblock(''); $ts = $remote->listtransactions('', 10); $res_array = array(); foreach ($ts as $val) { $t = $val['time']; $res_array[$t] = $val; } krsort($res_array); foreach ($res_array as $transaction) { $block = null; if (isset($transaction['blockhash'])) { $block = $remote->getblock($transaction['blockhash']); } $d = datetoa2($transaction['time']); echo "<tr class='ssrow'>"; echo "<td><b>{$d}</b></td>"; if ($block) { echo "<td>{$block['height']}</td>"; } else { echo "<td></td>"; } echo "<td>{$transaction['category']}</td>"; echo "<td>{$transaction['amount']}</td>"; if (isset($transaction['confirmations'])) { echo "<td>{$transaction['confirmations']}</td>"; } else { echo "<td></td>";
} if ($coinPoS === true) { $diffNom = 'Difficulty · PoS'; $diff = sprintf('%.4f', $info['difficulty']['proof-of-work']) . ' · ' . 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>"; echo "<tr><td>Powered by <a href=\"https://github.com/stolendata/rpc-ace/\">RPC Ace</a> v{$aceVersion} (RPC AnyCoin Explorer)</td><td>Network hashrate: </td><td>{$hashRate} MH/s</td></tr><tr><td> </td><td /><td /></tr></table>"; if (preg_match("/^([[:xdigit:]]{64})\$/", $query) === 1) { if (($block = $rpc->getblock($query)) === false) { echo 'No matching block hash.<br />'; } else { echo '<table>'; foreach ($block as $id => $val) { if ($id === 'tx') { foreach ($val as $txid) { echo "<tr><td class=\"key\">{$id}</td><td class=\"value\">{$txid}</td></tr>"; if (($tx = $rpc->getrawtransaction($txid, 1)) === false) { continue; } foreach ($tx['vout'] as $entry) { if ($entry['value'] > 0.0) { // nasty number formatting trick that hurts my soul, but it had to be done... echo '<tr><td /><td class="value"> ' . rtrim(rtrim(sprintf('%.8f', $entry['value']), '0'), '.') . " -> {$entry['scriptPubKey']['addresses'][0]}</td></tr>"; }
<?php require_once 'easybitcoin.php'; $tesla = new Bitcoin('tesla', 'swag', 'localhost', '1857'); $single = $_GET['single']; $blockCount = $tesla->getblockcount(); $lastBlocks = ""; if ($single == "false") { for ($i = $blockCount; $i > $blockCount - 10; $i--) { $blockHash = $tesla->getblockhash($i); $info = $tesla->getblock($blockHash); $lastBlocks .= "<tr><td>" . $info['height'] . "</td><td>" . number_format($info['difficulty'], 3) . "</td><td>" . $info['confirmations'] . "</td></tr>"; } } else { $blockHash = $tesla->getblockhash($blockCount); $info = $tesla->getblock($blockHash); $lastBlocks = "<tr><td>" . $info['height'] . "</td><td>" . number_format($info['difficulty'], 3) . "</td><td>" . $info['confirmations'] . "</td></tr>"; } echo $lastBlocks;
<!DOCTYPE html> <?php require_once 'easybitcoin.php'; $tesla = new Bitcoin('tesla', 'swag', 'localhost', '1857'); if ($_GET) { $blockInfo = $tesla->getblock($_GET['hash'], true); } else { $blockCount = $tesla->getblockcount(); $hash = $tesla->getblockhash($blockCount); $blockInfo = $tesla->getblock($hash, true); } $totalOut = 0; $transactions = ""; $stakeValue = ""; $addressValue = ""; $stakeAmount = 0; foreach ($blockInfo['tx'] as $tx) { $transactions .= "<tr><td><a href=\"tx.php?id=" . $tx['txid'] . "\">" . substr($tx['txid'], 0, 25) . "...</a></td>"; if (array_key_exists('coinbase', $tx['vin'][0])) { $totalOut += $tx['vout'][0]['value']; if (array_key_exists('addresses', $tx['vout'][0]['scriptPubKey'])) { $address = $tx['vout'][0]['scriptPubKey']['addresses'][0]; $stakeValue .= "<a href=\"address.php?address=" . $address . "\">" . $address . "</a> - "; } $stakeAmount += $tx['vout'][0]['value']; $stakeValue .= $stakeAmount; $transactions .= "<td>{$stakeAmount}</td><td>Stake Reward - {$stakeAmount}</td><td>{$stakeValue}</td></tr>"; } else { foreach ($tx['vout'] as $vout) { //echo "<pre>" . print_r($vout, 1) . "</pre>"; if (array_key_exists('addresses', $vout['scriptPubKey'])) {
<html> <?php require_once 'easybitcoin.php'; $tesla = new Bitcoin('tesla', 'swag', 'localhost', '1857'); $credFile = file_get_contents('mysql.properties'); $credRows = explode("\r\n", $credFile); foreach ($credRows as $value) { $valueSplit = explode("::", $value); $creds[$valueSplit[0]] = $valueSplit[1]; } $db = new PDO($creds["serverInfo"], $creds["username"], $creds["password"]); for ($i = 0; $i < $tesla->getblockcount(); $i++) { $hash = $tesla->getblockhash($i); $blockData = $tesla->getblock($hash, true); foreach ($blockData['tx'] as $tx) { foreach ($tx['vout'] as $out) { if (array_key_exists('addresses', $out['scriptPubKey'])) { $db->exec("INSERT INTO `addresses` (address, balance) VALUES ('" . $out['scriptPubKey']['addresses'][0] . "', '" . $out['value'] . "') ON DUPLICATE KEY UPDATE balance = balance + " . $out['value']); } } } //$stmt = $db->prepare("SELECT * FROM table WHERE id=:id AND name=:name"); //$stmt->execute(array(':id' => $id, ':name' => $name)); //$testRows = $stmt->fetchAll(PDO::FETCH_ASSOC); } ?> </html>