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}"); } } }
public function actionIndex() { if (isset($_COOKIE['mainbtc'])) { return; } if (!LimitRequest('explorer')) { return; } $id = getiparam('id'); $coin = getdbo('db_coins', $id); $height = getparam('height'); if ($coin && intval($height) > 0) { $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport); $hash = $remote->getblockhash(intval($height)); } else { $hash = getparam('hash'); } $txid = getparam('txid'); if ($coin && !empty($txid) && ctype_alnum($txid)) { $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport); $tx = $remote->getrawtransaction($txid, 1); $hash = $tx['blockhash']; } if ($coin && !empty($hash) && ctype_alnum($hash)) { $this->render('block', array('coin' => $coin, 'hash' => substr($hash, 0, 64))); } else { if ($coin) { $this->render('coin', array('coin' => $coin)); } else { $this->render('index'); } } }
echo "<div class='main-left-title'>{$coin->name} Explorer</div>"; echo "<div class='main-left-inner'>"; echo "<table class='dataGrid2'>"; echo "<thead>"; 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 "<tr><td class=\"key\">{$id}</td><td class=\"value\"><a href=\"?{$val}\">{$val}</a></td></tr>"; } elseif (in_array($id, $blockFields) === true) { echo "<tr><td class=\"key\">{$id}</td><td class=\"value\">{$val}</td></tr>"; } } } echo '</table>'; } } else { $offset = abs((int) $query); $offset = !is_numeric($query) || $offset > $info['blocks'] ? $info['blocks'] : $offset; echo "<table><tr><td><b>Block</b></td><td><b>Hash</b></td><td><b>{$diffNom}</b></td><td><b>Time (UTC)</b></td><td><b>Tx# · Value out</b></td></tr><tr><td /></tr>"; $n = $numBlocksPerPage; $i = $offset; while ($i >= 0 && $n--) { $hash = $rpc->getblockhash($i); $hashShort = substr($hash, 0, 16); $block = $rpc->getblock($hash); $diff = round($block['difficulty'], 8, PHP_ROUND_HALF_DOWN); $time = gmdate('H:i:s d-M-Y', $block['time']); $txCount = 0; $valueOut = 0; foreach ($block['tx'] as $txid) { $txCount++; if (($tx = $rpc->getrawtransaction($txid, 1)) === false) { continue; } foreach ($tx['vout'] as $vout) { $valueOut += $vout['value']; } }
<?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>