function FindNewGenerations($bitcoinController) { $blockcount = 0; $username = ''; //Get list of last 200 transactions $transactions = $bitcoinController->query("listtransactions", "*", "200"); //Go through all the transactions check if there is 50BTC inside $numAccounts = count($transactions); for ($i = 0; $i < $numAccounts; $i++) { //Check for 50BTC inside only if they are in the generate category if ($transactions[$i]["category"] == "generate" || $transactions[$i]["category"] == "immature") { //At this point we may or may not have found a block, //Check to see if this account addres is already added to `networkBlocks` $accountExistsQ = mysql_query("SELECT id FROM networkBlocks WHERE accountAddress = '" . $transactions[$i]["txid"] . "' ORDER BY blockNumber DESC LIMIT 0,1") or sqlerr(__FILE__, __LINE__); $accountExists = mysql_num_rows($accountExistsQ); //Insert txid into latest network block if (!$accountExists) { //Get last winning block $lastSuccessfullBlockQ = mysql_query("SELECT blockNumber, id, username FROM winning_shares ORDER BY id DESC LIMIT 1") or sqlerr(__FILE__, __LINE__); $lastSuccessfullBlockR = mysql_fetch_object($lastSuccessfullBlockQ); $timestamp = $transactions[$i]["time"]; $id = $lastSuccessfullBlockR->id; $rpcType = "http"; // http or https $rpcUsername = "******"; // username $rpcPassword = "******"; // password $rpcHost = "localhost"; $rpcPort = 9000; $bitcoinController = new BitcoinClient($rpcType, $rpcUsername, $rpcPassword, $rpcHost, $rpcPort); $currentBlockNumber = $bitcoinController->getblocknumber(); $confirms = $transactions[$i]["confirmations"]; $lastBlockNumber = $currentBlockNumber + 1 - $confirms; $stats = new Stats(); mysql_query("INSERT INTO networkBlocks (blockNumber, timestamp, accountAddress, confirms) " . "VALUES ('{$lastBlockNumber}', '{$timestamp}', '" . $transactions[$i]["txid"] . "', '" . $transactions[$i]["confirmations"] . "')") or sqlerr(__FILE__, __LINE__); $stats = new Stats(); $lastwinningid = $stats->lastWinningShareId(); $shareQ = mysql_query("SELECT sum(shares) as total from rounddetails WHERE blockNumber = {$lastBlockNumber}"); $shareC = mysql_fetch_object($shareQ); $winningShareQ = mysql_query("SELECT id, username FROM shares where upstream_result = 'Y' AND id > {$lastwinningid}") or sqlerr(__FILE__, __LINE__); while ($winningShareR = mysql_fetch_object($winningShareQ)) { mysql_query("INSERT INTO winning_shares (blockNumber, username, share_id) VALUES ({$lastBlockNumber},'{$winningShareR->username}',{$winningShareR->id})") or sqlerr(__FILE__, __LINE__); removeCache("last_winning_share_id"); } // $q = "UPDATE winning_shares SET amount = " . $transactions[$i]["amount"] . ", timestamp = " . $timestamp . ", txid = '".$transactions[$i]["txid"] . "', type = '" . $transactions[$i]["category"] . "', shares = ". $shareC->total . " WHERE blockNumber = $lastBlockNumber"; $q = "UPDATE winning_shares SET amount = " . $transactions[$i]["amount"] . ", timestamp = " . $timestamp . ", txid = '" . $transactions[$i]["txid"] . "', type = '" . $transactions[$i]["category"] . "' WHERE blockNumber = {$lastBlockNumber}"; echo $q; mysql_query($q) or sqlerr(__FILE__, __LINE__); $username = $lastSuccessfullBlockR->username; $splitUsername = explode(".", $username); $realUsername = $splitUsername[0]; $blockcount = $blockcount + 1; $username .= $realUsername . ' '; } } } }
ScriptIsRunLocally(); lock("shares"); //Include Block class include $includedir . "block.php"; $block = new Block(); //Get current block number $currentBlockNumber = $bitcoinController->getblocknumber(); $lastBlockNumber = $currentBlockNumber - 1; //Get latest block in database $latestDbBlock = $block->getLatestDbBlockNumber(); //Do block work if new block if ($latestDbBlock < $lastBlockNumber) { //Insert last block number into networkBlocks include $includedir . "stats.php"; $stats = new Stats(); $lastwinningid = $stats->lastWinningShareId(); $block->InsertNetworkBlocks($lastBlockNumber, $lastwinningid); //Find new generations $block->FindNewGenerations($bitcoinController); //Update confirms on unrewarded winning blocks $block->UpdateConfirms($bitcoinController); } unlock("shares"); //Check for unscored blocks() if ($block->CheckUnscoredBlocks()) { lock("money"); try { //Get Difficulty $difficulty = $bitcoinDifficulty; if (!$difficulty) { echo "no difficulty! exiting\n";