updateKeys($hash160, NULL, $blockhash); } if (is_null($type)) { $type = "Strange"; } pg_query_params($db, "INSERT INTO outputs (tx,index,value,scriptpubkey,hash160,type,block) VALUES (decode(\$1,'hex'),\$2,\$3,\$4,decode(\$5,'hex'),\$6,decode(\$7,'hex'));", array($txhash, $index, $value, $scriptpubkey, $hash160, $type, $blockhash)); echo "Hash160: " . $hash160 . "\$\n"; echo "Type: " . $type . "\$\n"; echo "Index: " . $index . "\$\n"; echo "Value: " . $value . "\$\n"; echo "Scriptpubkey: " . $scriptpubkey . "\$\n"; } pg_query_params($db, "UPDATE transactions SET fee=(SELECT (SELECT sum(value) FROM inputs WHERE tx=decode(\$1,'hex'))-(SELECT sum(value) from outputs WHERE tx=decode(\$1,'hex'))) WHERE hash=decode(\$1,'hex');", array($txhash)); return $txvalue; } $blockcount = getblockcount(); $wehave = pg_fetch_assoc(pg_query($db, "SELECT max(number) AS max FROM blocks;")); $wehave = (int) $wehave["max"]; echo "\r\n\r\n" . date("r") . "\r\n\r\n"; if ($wehave < 10) { $wehave = 10; } if ($blockcount <= $wehave) { echo "No update necessary\n"; die; } $rescan = false; $wehave = $wehave - 10; rescan: echo "Starting block update: {$wehave} to {$blockcount}\r\n"; $earliest = true;
function spectra_network_statistics() { echo "\t<h1> Network Statistics </h1> \n\n"; echo "\t<div id=\"network_panel\">\n\n"; $network_info = getinfo(); if (isset($network_info["blocks"]) && $network_info["blocks"] != "") { echo "\t\t<div class=\"network_detail\">\n"; echo "\t\t\t<div class=\"network_detail_label\"> \n"; echo "\t\t\t\tBlock Count: \n"; echo "\t\t\t</div> \n"; echo "\t\t\t<div class=\"network_detail_value\"> \n"; echo "\t\t\t\t" . $network_info["blocks"] . "\n"; echo "\t\t\t</div> \n"; echo "\t\t</div> \n\n"; } if (isset($network_info["difficulty"]) && $network_info["difficulty"] != "") { echo "\t\t<div class=\"network_detail\">\n"; echo "\t\t\t<div class=\"network_detail_label\"> \n"; echo "\t\t\t\tDifficulty: \n"; echo "\t\t\t</div> \n"; echo "\t\t\t<div class=\"network_detail_value\"> \n"; echo "\t\t\t\t" . $network_info["difficulty"] . "\n"; echo "\t\t\t</div> \n"; echo "\t\t</div> \n\n"; } if (isset($network_info["connections"]) && $network_info["connections"] != "") { echo "\t\t<div class=\"network_detail\">\n"; echo "\t\t\t<div class=\"network_detail_label\"> \n"; echo "\t\t\t\tConnections: \n"; echo "\t\t\t</div> \n"; echo "\t\t\t<div class=\"network_detail_value\"> \n"; echo "\t\t\t\t" . $network_info["connections"] . "\n"; echo "\t\t\t</div> \n"; echo "\t\t</div> \n\n"; } $net_speed = getnetworkhashps(); if ($net_speed != "" && !is_array($net_speed)) { echo "\t\t<div class=\"network_detail\">\n"; echo "\t\t\t<div class=\"network_detail_label\"> \n"; echo "\t\t\t\tNetwork H/s: \n"; echo "\t\t\t</div> \n"; echo "\t\t\t<div class=\"network_detail_value\"> \n"; echo "\t\t\t\t" . $net_speed . "\n"; echo "\t\t\t</div> \n"; echo "\t\t</div>\n\n"; } // Sort out the time of the last block in the node $node_height = getblockcount(); $node_hash = getblockhash($node_height); $node_block = getblock($node_hash); if (!is_numeric($node_block["time"])) { $node_block["time"] = strtotime($node_block["time"]); } // Calculate the time since the last block $last_time = floor((time() - $node_block["time"]) / 60); echo "\t\t<div class=\"network_detail\">\n"; echo "\t\t\t<div class=\"network_detail_label\"> \n"; echo "\t\t\t\tLast Block: \n"; echo "\t\t\t</div> \n"; echo "\t\t\t<div class=\"network_detail_value\"> \n"; echo "\t\t\t\t" . $last_time . " Minutes\n"; echo "\t\t\t</div> \n"; echo "\t\t</div> \n\n"; echo "\t</div>\n\n"; }
spectra_api_response($requested); } } if ($_REQUEST["method"] == "getpeerinfo") { $requested = getpeerinfo(); if (isset($requested["error"]) && $requested["error"] != "") { spectra_api_response("", 0, $requested["error"]["message"]); } else { spectra_api_response($requested); } } /****************************************************************************** Node / Chain API ******************************************************************************/ if ($_REQUEST["method"] == "getblockcount") { $requested = getblockcount(); if (isset($requested["error"]) && $requested["error"] != "") { spectra_api_response("", 0, $requested["error"]["message"]); } else { spectra_api_response($requested); } } if ($_REQUEST["method"] == "getblockhash") { if (!isset($_REQUEST["height"])) { spectra_api_response("", 0, "Block Height (&height=xxxxx) Is Required For Method 'getblockhash'"); } $requested = getblockhash((int) $_REQUEST["height"]); if (isset($requested["error"]) && $requested["error"] != "") { spectra_api_response("", 0, $requested["error"]["message"]); } else { spectra_api_response($requested);
$height_exp = $height_exp - 1; // The next block is retrieved from the explorer $data_exp = mysqli_getrow($GLOBALS["tables"]["block"], "`height` = '" . $height_exp . "'"); // The next hash is retrieved from the node $hash_node = getblockhash($height_exp); // The while loop will perform the comparison against the new values } // The block height of the match found is written to the log spectra_log_write(0, "Found sync at block " . $height_exp); } /****************************************************************************** Load New Blocks ******************************************************************************/ // Block heights are reloaded in case of a resync $start = spectra_block_height(); $top = getblockcount(); // If there is not a new block, end the checks if ($start >= $top) { // Make a note to the maintenance log spectra_log_write(0, "No new block, loading complete."); } else { // Log the new block height spectra_log_write(0, "Explorer Block: " . $start . " - Node Block: " . $top); // Get the data for the prior block from the node $hash_back = getblockhash((int) $start); $data_node = getblock($hash_back); // Update the prior block record $result = mysqli_setfield($GLOBALS["tables"]["block"], "nextblockhash", $data_node["nextblockhash"], "`hash` = '" . $data_node["hash"] . "'"); // Initialize a block counter for logging $count_loaded = 0; // Load any new blocks available from the node
<?php /****************************************************************************** This script assumes there are no blocks loaded in the explorer database and should only be used with a fresh installation. For ongoing maintenance you should configure your scheduler to run the script named "maint_crontab.php" instead. ******************************************************************************/ // Enable the spectra functionality require_once "../lib/spectra_config.php"; // Determine the current block height from the node $targ = getblockcount(); if (is_array($targ)) { spectra_log_write(1, "Communication Error: " . print_r($targ["error"], 1)); } // Most wallets do not display the genesis (0) block. The script // will begin loading with the first mined block at block 1. $load = 1; // Status for the log spectra_log_write(0, "Loading " . $GLOBALS["currency"]["name"] . " Block Chain"); spectra_log_write(0, "Node Height: " . $targ); // The blocks are loaded from the node. while ($load <= $targ) { // Each block is written to the log to ensure that any errors // generated can be tracked to the specific block spectra_log_write(0, "Loading Block: " . $load); // The current block is parsed into the database spectra_block_load($load); // The block counter is updated. $load++;