function system_flag_set($flag_name, $flag_value) { $flag_exists = mysqli_isrow($GLOBALS["tables"]["flag"], "`name` = '" . $flag_name . "'"); if ($flag_exists["data"]) { $inserted = mysqli_setfield($GLOBALS["tables"]["flag"], "value", $flag_value, "`name` = '" . $flag_name . "'"); } else { $flag["name"] = $flag_name; $flag["value"] = $flag_value; $inserted = mysqli_setrow($GLOBALS["tables"]["flag"], $flag); } return $inserted["success"]; }
******************************************************************************/ // 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 while ($start < $top) { // Increment the explorer height to indicate the next desired block $start++; spectra_log_write(0, "Loading Block: " . $start); // The next block is loaded spectra_block_load($start); // Increment the block count $count_loaded++; } // Log the number of blocks loaded spectra_log_write(0, "Loaded " . $count_loaded . " Blocks."); }
// Check to make sure that the rebalance flag is set if (system_flag_get("balance_rebuild") < 1) { system_flag_set("balance_rebuild", 1); } // Some data for the log spectra_log_write(0, "Beginning Balance Rebuild"); // Wipe all input counts from the account ledger $wiped = mysqli_setfield($GLOBALS["tables"]["ledger"], "tx_in", 0, "1=1"); // Wipe all input values from the account ledger $wiped = mysqli_setfield($GLOBALS["tables"]["ledger"], "received", 0, "1=1"); // Wipe all output counts from the account ledger $wiped = mysqli_setfield($GLOBALS["tables"]["ledger"], "tx_out", 0, "1=1"); // Wipe all output values from the account ledger $wiped = mysqli_setfield($GLOBALS["tables"]["ledger"], "spent", 0, "1=1"); // Wipe all balance values from the account ledger $wiped = mysqli_setfield($GLOBALS["tables"]["ledger"], "balance", 0, "1=1"); // Some data for the log spectra_log_write(0, "Existing Balances Were Deleted"); // For this version we will be iterating the list of addresses in the chain $response = $GLOBALS["db"]["obj"]->query("SELECT count(*) as `count` FROM `" . $GLOBALS["tables"]["ledger"] . "`"); $record = $response->fetch_assoc(); $count_addr = $record["count"]; // Some data for the log spectra_log_write(0, "Updating Account Ledger (" . $count_addr . " Addresses)"); // Addresses are handled in chunks to avoid memory issues $count_loop = 0; $count_req = ceil($count_addr / 1000); while ($count_loop < $count_req) { // Output for the log and to keep the console active spectra_log_write(0, "Group " . ($count_loop + 1) . " Of " . $count_req); // Retrieve the addresses