예제 #1
0
 if ($sql_num_results > 0) {
     $sql_row = mysql_fetch_array($sql_result);
     $ip_address = $sql_row["IP_Address"];
     $domain = $sql_row["domain"];
     $subfolder = $sql_row["subfolder"];
     $port_number = $sql_row["port_number"];
     $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 65, "transclerk.php?action=block_hash&block_number={$random_block}");
     if (empty($poll_peer) == TRUE) {
         // Add failure points to the peer in case further issues
         modify_peer_grade($ip_address, $domain, $subfolder, $port_number, 4);
     }
     if (empty($poll_peer) == FALSE && strlen($poll_peer) > 60) {
         // Do a real hash compare
         $current_generation_block = transaction_cycle(0, TRUE);
         $time1 = transaction_cycle(0 - $current_generation_block + $random_block);
         $time2 = transaction_cycle(0 - $current_generation_block + 1 + $random_block);
         $sql = "SELECT hash FROM `transaction_history` WHERE `timestamp` >= {$time1} AND `timestamp` < {$time2} ORDER BY `timestamp`, `hash`";
         $sql_result = mysql_query($sql);
         $sql_num_results = mysql_num_rows($sql_result);
         $random_hash_build = 0;
         if ($sql_num_results > 0) {
             for ($i = 0; $i < $sql_num_results; $i++) {
                 $sql_row = mysql_fetch_array($sql_result);
                 $random_hash_build .= $sql_row["hash"];
             }
         }
         $random_hash_build = hash('sha256', $random_hash_build);
         if ($poll_peer !== $random_hash_build && empty($poll_peer) == FALSE) {
             // Something is wrong, transaction history has an error.
             // Schedule a check in case the peer has an error and not us.
             mysql_query("UPDATE `main_loop_status` SET `field_data` = '{$random_block}' WHERE `main_loop_status`.`field_name` = 'transaction_history_block_check' LIMIT 1");
예제 #2
0
         } else {
             if ($loop_active == 3) {
                 mysql_query("DELETE FROM `main_loop_status` WHERE `main_loop_status`.`field_name` = 'treasurer_heartbeat_active'");
                 exit;
             } else {
                 // Script called while still working
                 exit;
             }
         }
     }
 }
 //***********************************************************************************
 //***********************************************************************************
 $previous_transaction_cycle = transaction_cycle(-1);
 $current_transaction_cycle = transaction_cycle(0);
 $next_transaction_cycle = transaction_cycle(1);
 //*****************************************************************************************************
 //*****************************************************************************************************
 // Check my transaction queue and copy pending transaction to the main transaction queue, giving priority
 // to self created transactions over 3rd party submitted transactions
 $sql = "(SELECT * FROM `my_transaction_queue` WHERE `public_key` = '" . my_public_key() . "' ORDER BY `my_transaction_queue`.`timestamp` ASC) \n\tUNION (SELECT * FROM `my_transaction_queue` ORDER BY `my_transaction_queue`.`timestamp` ASC) LIMIT 100";
 $sql_result = mysql_query($sql);
 $sql_num_results = mysql_num_rows($sql_result);
 if ($sql_num_results > 0) {
     // Can we copy my transaction queue to the main queue in the allowed time?
     // Not allowed 180 seconds before and 20 seconds after transaction cycle.
     if ($next_transaction_cycle - time() > 180 && time() - $current_transaction_cycle > 20) {
         $firewall_blocked = intval(mysql_result(mysql_query("SELECT field_data FROM `main_loop_status` WHERE `field_name` = 'firewall_blocked_peer' LIMIT 1"), 0, 0));
         for ($i = 0; $i < $sql_num_results; $i++) {
             $sql_row = mysql_fetch_array($sql_result);
             $public_key = $sql_row["public_key"];
예제 #3
0
 $transclerk_block_check = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'block_check_start' LIMIT 1"), 0, "field_data");
 if ($transclerk_block_check < ($i + 1) * 500 && $transclerk_block_check != "0") {
     // Break out of loop; Don't do anything until transclerk is finished with this range
     break;
 }
 write_log("Building New Transaction Foundation #{$i}", "FO");
 // Start the process to rebuild the transaction foundation
 // but walk the history of that range first to check for errors.
 $foundation_time_start = $i * 500;
 $foundation_time_end = $i * 500 + 500;
 $do_history_walk = walkhistory($foundation_time_start, $foundation_time_end);
 if ($do_history_walk == 0) {
     // History walk checks out, start building the transaction foundation hash
     // out of every piece of data in the database
     $time1 = transaction_cycle(0 - $current_generation_block + $foundation_time_start);
     $time2 = transaction_cycle(0 - $current_generation_block + $foundation_time_end);
     $sql = "SELECT timestamp, public_key_from, public_key_to, hash, attribute FROM `transaction_history` WHERE `timestamp` >= {$time1} AND `timestamp` <= {$time2} ORDER BY `timestamp`, `hash`";
     $sql_result2 = mysql_query($sql);
     $sql_num_results2 = mysql_num_rows($sql_result2);
     $hash = $sql_num_results2;
     for ($f = 0; $f < $sql_num_results2; $f++) {
         $sql_row2 = mysql_fetch_array($sql_result2);
         $hash .= $sql_row2["timestamp"] . $sql_row2["public_key_from"] . $sql_row2["public_key_to"] . $sql_row2["hash"] . $sql_row2["attribute"];
     }
     $hash = hash('sha256', $hash);
     $sql = "INSERT INTO `transaction_foundation` (`block` ,`hash`)VALUES ('{$i}', '{$hash}')";
     if (mysql_query($sql) == TRUE) {
         // Success
         write_log("New Transaction Foundation #{$i} Complete", "FO");
         // Wipe Balance Index table to reset index creation of public key balances
         if (mysql_query("TRUNCATE TABLE `balance_index`") == FALSE) {
예제 #4
0
             mysql_query("UPDATE `main_loop_status` SET `field_data` = '1' WHERE `main_loop_status`.`field_name` = 'queueclerk_heartbeat_active' LIMIT 1");
         } else {
             if ($loop_active == 3) {
                 mysql_query("DELETE FROM `main_loop_status` WHERE `main_loop_status`.`field_name` = 'queueclerk_heartbeat_active'");
                 exit;
             } else {
                 // Script called while still working
                 exit;
             }
         }
     }
 }
 //***********************************************************************************
 //***********************************************************************************
 $next_transaction_cycle = transaction_cycle(1);
 $current_transaction_cycle = transaction_cycle(0);
 $treasurer_status = intval(mysql_result(mysql_query("SELECT field_data FROM `main_loop_status` WHERE `field_name` = 'treasurer_heartbeat_active' LIMIT 1"), 0, 0));
 // Can we work on the transactions in the database?
 // Not allowed 30 seconds before and 30 seconds after transaction cycle.
 if ($next_transaction_cycle - time() > 30 && time() - $current_transaction_cycle > 30 && $treasurer_status == 2) {
     // Create a hash of my own transaction queue
     $transaction_queue_hash = queue_hash();
     $db_queue_hash = mysql_result(mysql_query("SELECT field_data FROM `options` WHERE `field_name` = 'transaction_queue_hash' LIMIT 1"), 0, 0);
     if ($db_queue_hash !== $transaction_queue_hash) {
         // Store in database for proper update when peers are polling this info
         mysql_query("UPDATE `options` SET `field_data` = '{$transaction_queue_hash}' WHERE `options`.`field_name` = 'transaction_queue_hash' LIMIT 1");
     }
     // How does my transaction queue compare to others?
     // Ask all of my active peers
     $sql = "SELECT * FROM `active_peer_list` ORDER BY RAND() LIMIT 10";
     $sql_result = mysql_query($sql);
예제 #5
0
function transaction_queue()
{
    $next_transaction_cycle = transaction_cycle(1);
    $current_transaction_cycle = transaction_cycle(0);
    $results;
    // Wipe transaction queue of all old transaction from current to previous cycle
    if (rand(1, 2) == 2) {
        mysql_query("DELETE QUICK FROM `transaction_queue` WHERE `transaction_queue`.`timestamp` < {$current_transaction_cycle}");
    }
    // Create a hash of my own transaction queue
    $transaction_queue_hash = queue_hash();
    // How does my transaction queue compare to others?
    // Ask all of my active peers
    ini_set('user_agent', 'Timekoin Client (Queueclerk) v' . TIMEKOIN_VERSION);
    ini_set('default_socket_timeout', 2);
    // Timeout for request in seconds
    $transaction_queue_hash_match = 0;
    $transaction_queue_hash_different = 0;
    $hash_different = array();
    $sql = "SELECT * FROM `active_peer_list` ORDER BY RAND()";
    $sql_result = mysql_query($sql);
    $sql_num_results = mysql_num_rows($sql_result);
    $transaction_queue_hash_match = 0;
    $transaction_queue_hash_different = 0;
    if ($sql_num_results > 0) {
        $hash_different = array();
        for ($i = 0; $i < $sql_num_results; $i++) {
            $sql_row = mysql_fetch_array($sql_result);
            $ip_address = $sql_row["IP_Address"];
            $domain = $sql_row["domain"];
            $subfolder = $sql_row["subfolder"];
            $port_number = $sql_row["port_number"];
            $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 40, "queueclerk.php?action=trans_hash&client=api");
            if ($transaction_queue_hash === $poll_peer) {
                $transaction_queue_hash_match++;
            } else {
                if (empty($poll_peer) == FALSE) {
                    $transaction_queue_hash_different++;
                    $hash_different["ip_address{$transaction_queue_hash_different}"] = $ip_address;
                    $hash_different["domain{$transaction_queue_hash_different}"] = $domain;
                    $hash_different["subfolder{$transaction_queue_hash_different}"] = $subfolder;
                    $hash_different["port_number{$transaction_queue_hash_different}"] = $port_number;
                }
            }
        }
        // End for Loop
    }
    // End number of results check
    // Compare tallies
    if ($transaction_queue_hash_different > 0) {
        // Transaction Queue still not in sync with all peers
        $hash_array = array();
        $transaction_counter = 0;
        for ($i = 1; $i < $transaction_queue_hash_different + 1; $i++) {
            $ip_address = $hash_different["ip_address{$i}"];
            $domain = $hash_different["domain{$i}"];
            $subfolder = $hash_different["subfolder{$i}"];
            $port_number = $hash_different["port_number{$i}"];
            $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 8200, "queueclerk.php?action=queue&client=api");
            // Bring up first match (if any) to compare agaist our database
            $match_number = 1;
            $current_hash = find_string("---queue{$match_number}=", "---end{$match_number}", $poll_peer);
            $transaction_counter = 0;
            $peer_transaction_limit = 100;
            $mismatch_error_count = 0;
            $mismatch_error_limit = 10;
            while (empty($current_hash) == FALSE) {
                // Count transactions coming from this peer
                $transaction_counter++;
                if ($transaction_counter > $peer_transaction_limit) {
                    break;
                }
                if ($mismatch_error_count > $mismatch_error_limit) {
                    break;
                }
                //Check if this transaction is already in our queue
                $hash_match = mysql_result(mysql_query("SELECT hash FROM `transaction_queue` WHERE `hash` = '{$current_hash}' LIMIT 1"), 0, 0);
                if (empty($hash_match) == TRUE) {
                    // This peer has a different transaction, ask for the full details of it
                    $poll_hash = poll_peer($ip_address, $domain, $subfolder, $port_number, 1500, "queueclerk.php?action=transaction&number={$current_hash}&client=api");
                    $transaction_timestamp = filter_sql(find_string("-----timestamp=", "-----public_key", $poll_hash));
                    $transaction_public_key = find_string("-----public_key=", "-----crypt1", $poll_hash);
                    $transaction_crypt1 = filter_sql(find_string("-----crypt1=", "-----crypt2", $poll_hash));
                    $transaction_crypt2 = filter_sql(find_string("-----crypt2=", "-----crypt3", $poll_hash));
                    $transaction_crypt3 = filter_sql(find_string("-----crypt3=", "-----hash", $poll_hash));
                    $transaction_hash = filter_sql(find_string("-----hash=", "-----attribute", $poll_hash));
                    $transaction_attribute = find_string("-----attribute=", "-----end", $poll_hash);
                    $transaction_qhash = find_string("---qhash=", "---endqhash", $poll_hash);
                    // If a qhash is included, use this to verify the data
                    if (empty($transaction_qhash) == FALSE) {
                        $qhash = $transaction_timestamp . $transaction_public_key . $transaction_crypt1 . $transaction_crypt2 . $transaction_crypt3 . $transaction_hash . $transaction_attribute;
                        $qhash = hash('md5', $qhash);
                        // Compare hashes to make sure data is intact
                        if ($transaction_qhash != $qhash) {
                            $transaction_attribute = "mismatch";
                            $mismatch_error_count++;
                        }
                    } else {
                        // Qhash is required to match hash now
                        $transaction_attribute = "mismatch";
                        $mismatch_error_count++;
                    }
                    $transaction_public_key = filter_sql(base64_decode($transaction_public_key));
                    if ($transaction_attribute == "T" || $transaction_attribute == "G") {
                        // Decrypt transaction information for regular transaction data
                        // and check to make sure the public key that is being sent to
                        // has not been tampered with.
                        $transaction_info = tk_decrypt($transaction_public_key, base64_decode($transaction_crypt3));
                        $inside_transaction_hash = find_string("HASH=", "", $transaction_info, TRUE);
                        // Check if a message is encoded in this data as well
                        if (strlen($inside_transaction_hash) != 64) {
                            // A message is also encoded
                            $inside_transaction_hash = find_string("HASH=", "---MSG", $transaction_info);
                        }
                        // Check Hash against 3 crypt fields
                        $crypt_hash_check = hash('sha256', $transaction_crypt1 . $transaction_crypt2 . $transaction_crypt3);
                    }
                    $final_hash_compare = hash('sha256', $transaction_crypt1 . $transaction_crypt2);
                    // Check to make sure this transaction is even valid (hash check, length check, & timestamp)
                    if ($transaction_hash == $crypt_hash_check && $inside_transaction_hash == $final_hash_compare && strlen($transaction_public_key) > 300 && $transaction_timestamp >= $current_transaction_cycle && $transaction_timestamp < $next_transaction_cycle) {
                        // Check for 100 public key limit in the transaction queue
                        $sql = "SELECT timestamp FROM `transaction_queue` WHERE `public_key` = '{$transaction_public_key}'";
                        $sql_result = mysql_query($sql);
                        $sql_num_results = mysql_num_rows($sql_result);
                        if ($sql_num_results < 100) {
                            // Transaction hash and real hash match
                            $sql = "INSERT INTO `transaction_queue` (`timestamp`,`public_key`,`crypt_data1`,`crypt_data2`,`crypt_data3`, `hash`, `attribute`)\n\t\t\t\t\t\t\tVALUES ('{$transaction_timestamp}', '{$transaction_public_key}', '{$transaction_crypt1}', '{$transaction_crypt2}' , '{$transaction_crypt3}', '{$transaction_hash}' , '{$transaction_attribute}')";
                            mysql_query($sql);
                        }
                    }
                }
                // End Empty Hash Check
                $match_number++;
                $current_hash = find_string("---queue{$match_number}=", "---end{$match_number}", $poll_peer);
            }
            // End While Loop
        }
        // End For Loop
    }
    // End Compare Tallies
    return;
}
예제 #6
0
             mysql_query("UPDATE `main_loop_status` SET `field_data` = '1' WHERE `main_loop_status`.`field_name` = 'genpeer_heartbeat_active' LIMIT 1");
         } else {
             if ($loop_active == 3) {
                 mysql_query("DELETE FROM `main_loop_status` WHERE `main_loop_status`.`field_name` = 'genpeer_heartbeat_active'");
                 exit;
             } else {
                 // Script called while still working
                 exit;
             }
         }
     }
 }
 //***********************************************************************************
 //***********************************************************************************
 $next_generation_cycle = transaction_cycle(1);
 $current_generation_cycle = transaction_cycle(0);
 // Can we work on the transactions in the database?
 // Not allowed 35 seconds before and 35 seconds after generation cycle.
 if ($next_generation_cycle - time() > 35 && time() - $current_generation_cycle > 35) {
     //***********************************************************************************
     if (election_cycle() == TRUE) {
         // Find all transactions between the Previous Transaction Cycle and the Current
         $sql = "SELECT * FROM `generating_peer_queue` WHERE `timestamp` < {$current_generation_cycle} ORDER BY `generating_peer_queue`.`IP_Address` ASC";
         $sql_result = mysql_query($sql);
         $sql_num_results = mysql_num_rows($sql_result);
         if ($sql_num_results > 0) {
             if ($sql_num_results == 1) {
                 // Winner by default
                 $sql_row = mysql_fetch_array($sql_result);
                 $public_key = $sql_row["public_key"];
                 $IP_Address = $sql_row["IP_Address"];
예제 #7
0
            } else {
                $show_last = 10;
                // Default number of last items to show
            }
            $body_string = '<strong>Showing Last <font color="blue">' . $show_last . '</font> Transaction Cycles</strong>';
            // Start the Transaction Browser section
            $body_string .= '<div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" ><tr><th>Transaction Cycle</th>
				<th>Transactions</th></tr>';
            // How many transactions back from the present time to display?
            $show_last_counter = $show_last;
            $counter = -1;
            // Transaction back from present cycle
            while ($show_last_counter > 0) {
                $start_transaction_cycle = transaction_cycle($counter);
                $end_transaction_cycle = transaction_cycle($counter + 1);
                $jump_to_transaction = transaction_cycle($counter + 5);
                $sql = "SELECT * FROM `transaction_history` WHERE `timestamp` >= '{$start_transaction_cycle}' AND `timestamp` < '{$end_transaction_cycle}'";
                $sql_result = mysql_query($sql);
                $sql_num_results = mysql_num_rows($sql_result);
                if ($_POST["highlight_cycle"] - 1500 == $start_transaction_cycle) {
                    $body_string .= '<tr><td class="style2"><p style="font-size: 12px;"><h9 id="' . $start_transaction_cycle . '"></h9><font color="blue">' . $start_transaction_cycle . '<br>' . unix_timestamp_to_human($start_transaction_cycle) . '</font></p></td>
						<td class="style2"><table border="0" cellspacing="0" cellpadding="0"><tr>';
                } else {
                    $body_string .= '<tr><td class="style2"><p style="font-size: 12px;"><h9 id="' . $start_transaction_cycle . '"></h9>' . $start_transaction_cycle . '<br>' . unix_timestamp_to_human($start_transaction_cycle) . '</p></td>
						<td class="style2"><table border="0" cellspacing="0" cellpadding="0"><tr>';
                }
                $koin_kounter = 0;
                $row_count_limit = 12;
                if ($sql_num_results > 1) {
                    // Build row with icons
                    for ($i = 0; $i < $sql_num_results; $i++) {
예제 #8
0
function visual_repair($block_start = 0)
{
    $current_generation_block = transaction_cycle(0, TRUE);
    $output;
    // Wipe all blocks ahead
    $time_range = transaction_cycle(0 - $current_generation_block + $block_start);
    $sql = "DELETE QUICK FROM `transaction_history` WHERE `transaction_history`.`timestamp` >= {$time_range} AND `attribute` = 'H'";
    if (mysql_query($sql) == TRUE) {
        $output .= '<tr><td class="style2">Clearing Hash Timestamps Ahead of Block #' . $block_start . '</td></tr>';
    } else {
        return '<tr><td class="style2">Database ERROR, stopping repair process...</td></tr>';
    }
    $generation_arbitrary = ARBITRARY_KEY;
    for ($t = $block_start; $t < $current_generation_block; $t++) {
        $output .= "<tr><td><strong>Repairing Block# {$t}</strong>";
        $time1 = transaction_cycle(0 - $current_generation_block - 1 + $t);
        $time2 = transaction_cycle(0 - $current_generation_block + $t);
        $sql = "SELECT timestamp, hash, attribute FROM `transaction_history` WHERE `timestamp` >= {$time1} AND `timestamp` < {$time2} ORDER BY `timestamp`, `hash` ASC";
        $sql_result = mysql_query($sql);
        $sql_num_results = mysql_num_rows($sql_result);
        $hash = 0;
        for ($i = 0; $i < $sql_num_results; $i++) {
            $sql_row = mysql_fetch_array($sql_result);
            $hash .= $sql_row["hash"];
        }
        // Transaction hash
        $hash = hash('sha256', $hash);
        $sql = "INSERT INTO `transaction_history` (`timestamp` ,`public_key_from` ,`public_key_to` ,`crypt_data1` ,`crypt_data2` ,`crypt_data3` ,`hash` ,`attribute`)\n\t\tVALUES ('{$time2}', '{$generation_arbitrary}', '{$generation_arbitrary}', '{$generation_arbitrary}', '{$generation_arbitrary}', '{$generation_arbitrary}', '{$hash}', 'H')";
        if (mysql_query($sql) == FALSE) {
            // Something failed
            $output .= '<br><strong><font color="red">Repair ERROR in Database</font></strong></td></tr>';
        } else {
            $output .= '<br><strong><font color="blue">Repair Complete...</font></strong></td></tr>';
        }
    }
    // End for loop
    return $output;
}
예제 #9
0
파일: api.php 프로젝트: LoveLeAnon/timekoin
            $sql = "SELECT * FROM `transaction_history` WHERE `timestamp` >= '{$start_transaction_cycle}' AND `timestamp` < '{$end_transaction_cycle}'";
            $sql_result = mysql_query($sql);
            $sql_num_results = mysql_num_rows($sql_result);
            if ($sql_num_results > 1) {
                // Build row with icons
                for ($i = 0; $i < $sql_num_results; $i++) {
                    $sql_row = mysql_fetch_array($sql_result);
                    if ($sql_row["attribute"] == 'G' || $sql_row["attribute"] == 'T') {
                        // Transaction Amount
                        $transaction_info = tk_decrypt($sql_row["public_key_from"], base64_decode($sql_row["crypt_data3"]));
                        $amount += intval(find_string("AMOUNT=", "---TIME", $transaction_info));
                        $transaction_counter++;
                    }
                }
            }
            echo "---TIMESTAMP{$output_counter}=" . transaction_cycle($counter);
            echo "---NUM{$output_counter}={$transaction_counter}";
            echo "---AMOUNT{$output_counter}={$amount}---END{$output_counter}";
            $output_counter++;
            $counter--;
            $last--;
        }
    }
    // End Permission Check
    // Log inbound IP activity
    log_ip("AP", scale_trigger(100));
    exit;
}
//***********************************************************************************
//***********************************************************************************
if ($_GET["action"] == "pk_recv") {
예제 #10
0
function send_timekoins($my_private_key, $my_public_key, $send_to_public_key, $amount, $message)
{
    if (empty($my_private_key) == TRUE || empty($my_public_key) == TRUE || empty($send_to_public_key) == TRUE) {
        return FALSE;
    }
    ini_set('user_agent', 'Timekoin Client v' . TIMEKOIN_VERSION);
    ini_set('default_socket_timeout', 3);
    // Timeout for request in seconds
    $arr1 = str_split($send_to_public_key, 181);
    $encryptedData1 = tk_encrypt($my_private_key, $arr1[0]);
    $encryptedData64_1 = base64_encode($encryptedData1);
    $encryptedData2 = tk_encrypt($my_private_key, $arr1[1]);
    $encryptedData64_2 = base64_encode($encryptedData2);
    // Sanitization of message
    // Filter symbols that might lead to a transaction hack attack
    $symbols = array("|", "?", "=");
    // SQL + URL
    $message = str_replace($symbols, "", $message);
    // Trim any message to 64 characters max and filter any sql
    $message = filter_sql(substr($message, 0, 64));
    $transaction_data = "AMOUNT={$amount}---TIME=" . time() . "---HASH=" . hash('sha256', $encryptedData64_1 . $encryptedData64_2) . "---MSG={$message}";
    $encryptedData3 = tk_encrypt($my_private_key, $transaction_data);
    $encryptedData64_3 = base64_encode($encryptedData3);
    $triple_hash_check = hash('sha256', $encryptedData64_1 . $encryptedData64_2 . $encryptedData64_3);
    $timestamp = transaction_cycle(0) + 1;
    $attribute = "T";
    $qhash = $timestamp . base64_encode($my_public_key) . $encryptedData64_1 . $encryptedData64_2 . $encryptedData64_3 . $triple_hash_check . $attribute;
    $qhash = hash('md5', $qhash);
    // Create map with request parameters
    $params = array('timestamp' => $timestamp, 'public_key' => base64_encode($my_public_key), 'crypt_data1' => $encryptedData64_1, 'crypt_data2' => $encryptedData64_2, 'crypt_data3' => $encryptedData64_3, 'hash' => $triple_hash_check, 'attribute' => $attribute, 'qhash' => $qhash);
    // Build Http query using params
    $query = http_build_query($params);
    // Create Http context details
    $contextData = array('method' => 'POST', 'header' => "Connection: close\r\n" . "Content-Length: " . strlen($query) . "\r\n", 'content' => $query);
    // Create context resource for our request
    $context = stream_context_create(array('http' => $contextData));
    // Try all Active Peer Servers
    $sql_result = mysql_query("SELECT * FROM `active_peer_list` ORDER BY RAND()");
    $sql_num_results = mysql_num_rows($sql_result);
    $return_results;
    for ($i = 0; $i < $sql_num_results; $i++) {
        $sql_row = mysql_fetch_array($sql_result);
        $ip_address = $sql_row["IP_Address"];
        $domain = $sql_row["domain"];
        $subfolder = $sql_row["subfolder"];
        $port_number = $sql_row["port_number"];
        $code = $sql_row["code"];
        $poll_peer = filter_sql(poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "api.php?action=send_tk&hash={$code}", $context));
        if ($poll_peer == "OK") {
            write_log("Peer: [{$ip_address}{$domain}:{$port_number}/{$subfolder}] Accepted the Transaction for Processing", "T");
            $return_results = TRUE;
        }
    }
    if ($return_results == TRUE) {
        // Success in sending transaction
        return TRUE;
    } else {
        // No peer servers accepted the transaction data :(
        write_log("No Peers Accepted the Transaction", "T");
        return FALSE;
    }
}
예제 #11
0
function tools_bar()
{
    $default_walk = foundation_cycle(0, TRUE) * 500;
    $default_check = transaction_cycle(0, TRUE) - 10;
    $default_current = transaction_cycle(0, TRUE);
    return '<FORM ACTION="index.php?menu=tools&amp;action=walk_history" METHOD="post">
	<table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="History Walk"/></td>
	<td>Cycle#<input type="text" size="6" name="walk_history" value="' . $default_walk . '" /></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=schedule_check" METHOD="post">
	<table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="Check"/></td>
	<td>Cycle#<input type="text" size="6" name="schedule_check" value="' . $default_check . '" /></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=repair" METHOD="post">
	<table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="Repair" onclick="return confirm(\'Transaction Repair Can Take a Long Time. Continue?\');" /></td>
	<td>From Cycle#<input type="text" size="6" name="repair_from" value="' . $default_check . '" /></td></tr></table></FORM>
	<br><br><hr>
	<FORM ACTION="index.php?menu=tools&amp;action=check_tables" METHOD="post" onclick="return confirm(\'Database Check Can Take a Long Time. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Check DB"/></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=optimize_tables" METHOD="post" onclick="return confirm(\'Database Optimize Can Take a Long Time. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Optimize DB"/></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=repair_tables" METHOD="post" onclick="return confirm(\'Database Repair Can Take a Long Time. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Repair DB"/></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=clear_foundation" METHOD="post" onclick="return confirm(\'This Will Clear All Foundation Hashes. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Foundation"/></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=clear_banlist" METHOD="post" onclick="return confirm(\'This Will Clear All Banned IPs. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Banlist"/></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=clear_gen" METHOD="post" onclick="return confirm(\'This Will Clear The Peer Generation List & Election Queue. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Gen"/></td></tr></table></FORM>
	<br><br>';
}
예제 #12
0
function tools_bar()
{
    $default_walk = foundation_cycle(0, TRUE) * 500;
    $default_check = transaction_cycle(0, TRUE) - 10;
    $default_current = transaction_cycle(0, TRUE);
    $main_active = mysql_result(mysql_query("SELECT field_data FROM `main_loop_status` WHERE `field_name` = 'main_heartbeat_active' LIMIT 1"), 0, 0);
    if ($main_active != FALSE) {
        $disable_db_util = "DISABLED";
    }
    return '<FORM ACTION="index.php?menu=tools&amp;action=walk_history" METHOD="post">
	<table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="History Walk"/></td>
	<td>Cycle#<input type="text" size="6" name="walk_history" value="' . $default_walk . '" /></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=schedule_check" METHOD="post">
	<table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="Check"/></td>
	<td>Cycle#<input type="text" size="6" name="schedule_check" value="' . $default_check . '" /></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=repair" METHOD="post">
	<table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="Repair" onclick="return confirm(\'Transaction Repair Can Take a Long Time. Continue?\');" /></td>
	<td>From Cycle#<input type="text" size="6" name="repair_from" value="' . $default_check . '" /></td></tr></table></FORM>
	<br><br><hr>
	<FORM ACTION="index.php?menu=tools&amp;action=check_tables" METHOD="post" onclick="return confirm(\'Database Check Can Take a Long Time. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Check DB"/ ' . $disable_db_util . '></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=optimize_tables" METHOD="post" onclick="return confirm(\'Database Optimize Can Take a Long Time. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Optimize DB" ' . $disable_db_util . '/></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=repair_tables" METHOD="post" onclick="return confirm(\'Database Repair Can Take a Long Time. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Repair DB" ' . $disable_db_util . '/></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=clear_foundation" METHOD="post" onclick="return confirm(\'This Will Clear All Foundation Hashes. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Foundation"/></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=clear_banlist" METHOD="post" onclick="return confirm(\'This Will Clear All Banned IPs. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Banlist"/></td></tr></table></FORM>
	<FORM ACTION="index.php?menu=tools&amp;action=clear_gen" METHOD="post" onclick="return confirm(\'This Will Clear The Peer Generation List & Election Queue. Continue?\');">
	<table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Gen"/></td></tr></table></FORM>
	<br><br>';
}
예제 #13
0
function tools_bar()
{
    $default_walk = foundation_cycle(0, TRUE) * 500;
    $default_check = transaction_cycle(0, TRUE) - 10;
    $default_current = transaction_cycle(0, TRUE);
    return '<FORM ACTION="index.php?menu=tools&amp;action=walk_history" METHOD="post">
		<table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="History Walk"/></td>
		<td>Block#<input type="text" size="7" name="walk_history" value="' . $default_walk . '" /></td></tr></table></FORM>
		<FORM ACTION="index.php?menu=tools&amp;action=check_tables" METHOD="post" onclick="return confirm(\'Database Check Can Take a Long Time. Continue?\');">
		<table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Check DB"/></td></tr></table></FORM>
		<FORM ACTION="index.php?menu=tools&amp;action=optimize_tables" METHOD="post" onclick="return confirm(\'Database Optimize Can Take a Long Time. Continue?\');">
		<table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Optimize DB"/></td></tr></table></FORM>
		<FORM ACTION="index.php?menu=tools&amp;action=repair_tables" METHOD="post" onclick="return confirm(\'Database Repair Can Take a Long Time. Continue?\');">
		<table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Repair DB"/></td></tr></table></FORM>
		<br><br><br><hr>
		<FORM ACTION="index.php?menu=tools&amp;action=schedule_check" METHOD="post">
		<table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Schedule Check"/></td>
		<td>Block#<input type="text" size="7" name="schedule_check" value="' . $default_check . '" /></td></tr></table></FORM>
		<FORM ACTION="index.php?menu=tools&amp;action=repair" METHOD="post">
		<table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Repair" onclick="return confirm(\'Transaction Repair Can Take a Long Time. Continue?\');" /></td>
		<td>From Block#<input type="text" size="7" name="repair_from" value="' . $default_check . '" /></td></tr></table></FORM>
		<br><br><br>';
}
예제 #14
0
             if ($loop_active == 3) {
                 mysql_query("DELETE FROM `main_loop_status` WHERE `main_loop_status`.`field_name` = 'treasurer_heartbeat_active'");
                 exit;
             } else {
                 // Script called while still working
                 exit;
             }
         }
     }
 }
 //***********************************************************************************
 //***********************************************************************************
 $previous_generation_cycle = transaction_cycle(-1);
 $current_generation_cycle = transaction_cycle(0);
 $next_generation_cycle = transaction_cycle(1);
 $current_generation_block = transaction_cycle(0, TRUE);
 //*****************************************************************************************************
 //*****************************************************************************************************
 // Check my transaction queue and copy pending transaction to the main transaction queue, giving priority
 // to self created transactions over 3rd party submitted transactions
 $sql = "(SELECT * FROM `my_transaction_queue` WHERE `public_key` = '" . my_public_key() . "' ORDER BY `my_transaction_queue`.`timestamp` ASC) \n\tUNION (SELECT * FROM `my_transaction_queue` ORDER BY `my_transaction_queue`.`timestamp` ASC) LIMIT 100";
 $sql_result = mysql_query($sql);
 $sql_num_results = mysql_num_rows($sql_result);
 if ($sql_num_results > 0) {
     // Can we copy my transaction queue to the main queue in the allowed time?
     // Not allowed 120 seconds before and 20 seconds after transaction cycle.
     if ($next_generation_cycle - time() > 120 && time() - $current_generation_cycle > 20) {
         $firewall_blocked = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'firewall_blocked_peer' LIMIT 1"), 0, "field_data");
         for ($i = 0; $i < $sql_num_results; $i++) {
             $sql_row = mysql_fetch_array($sql_result);
             $time_created = $sql_row["timestamp"];
예제 #15
0
                 // Script called while still working
                 exit;
             }
         }
     }
 }
 //***********************************************************************************
 //***********************************************************************************
 $current_transaction_cycle = transaction_cycle(0);
 $next_transaction_cycle = transaction_cycle(1);
 $foundation_status = intval(mysql_result(mysql_query("SELECT field_data FROM `main_loop_status` WHERE `field_name` = 'foundation_heartbeat_active' LIMIT 1"), 0, 0));
 // Can we work on the key balances in the database?
 // Not allowed 120 seconds before and 40 seconds after transaction cycle.
 // Don't run if the Foundation Manager is busy (idle = 2)
 if ($next_transaction_cycle - time() > 120 && time() - $current_transaction_cycle > 40 && $foundation_status == 2) {
     $current_transaction_block = transaction_cycle(0, TRUE);
     $current_foundation_block = foundation_cycle(0, TRUE);
     // Check to make sure enough lead time exist in advance to building
     // another balance index. (60 cycles) or 5 hours
     if ($current_transaction_block - $current_foundation_block * 500 > 60) {
         // -1 Foundation Blocks (Standard)
         $cache_block = foundation_cycle(-1, TRUE);
     } else {
         // -2 Foundation Blocks - Buffers 5 hours after the newest foundation block
         $cache_block = foundation_cycle(-2, TRUE);
     }
     // Build self balance index first
     $public_key_hash = hash('md5', my_public_key());
     $balance_index = mysql_result(mysql_query("SELECT block FROM `balance_index` WHERE `public_key_hash` = '{$public_key_hash}' AND `block` = {$cache_block} LIMIT 1"), 0, 0);
     if ($balance_index === FALSE) {
         // Create self first :)
예제 #16
0
function tools_bar()
{
    $default_walk = foundation_cycle(0, TRUE) * 500;
    $default_check = transaction_cycle(0, TRUE) - 10;
    $default_current = transaction_cycle(0, TRUE);
    return '<table cellspacing="10" border="0"><tr><td><FORM ACTION="index.php?menu=tools&action=walk_history" METHOD="post"><input type="submit" value="History Walk"/></td>
		<td>Block#<input type="text" size="7" name="walk_history" value="' . $default_walk . '" /></td></FORM><td>|</br>|</td>
		<td><FORM ACTION="index.php?menu=tools&action=check_tables" METHOD="post"><input type="submit" value="Check DB"/></td></FORM></td><td>|</br>|</td>
		<td><FORM ACTION="index.php?menu=tools&action=optimize_tables" METHOD="post"><input type="submit" value="Optimize DB"/></td></FORM></td><td>|</br>|</td>
		<td><FORM ACTION="index.php?menu=tools&action=repair_tables" METHOD="post"><input type="submit" value="Repair DB"/></td></FORM>
		</tr></table><hr></hr>
		<table cellspacing="10" border="0"><tr><td><FORM ACTION="index.php?menu=tools&action=schedule_check" METHOD="post"><input type="submit" value="Schedule Check"/></td>
		<td>Block#<input type="text" size="7" name="schedule_check" value="' . $default_check . '" /></td></FORM><td>|</br>|</td>
		<td><FORM ACTION="index.php?menu=tools&action=repair" METHOD="post"><input type="submit" value="Repair"/></td>
		<td>From Block#<input type="text" size="7" name="repair_from" value="' . $default_check . '" /></td>
		</FORM></tr></table>';
}
예제 #17
0
 }
 // End New Peers vs Max New Peers check
 //***********************************************************************************
 //***********************************************************************************
 // Send a heartbeat to all active peers in our list to make sure they are still online
 $sql = "SELECT * FROM `active_peer_list`";
 $sql_result = mysql_query($sql);
 $sql_num_results = mysql_num_rows($sql_result);
 // Grab random Transaction Foundation Hash
 $rand_block = rand(0, foundation_cycle(0, TRUE) - 5);
 // Range from Start to Last 5 Foundation Hash
 $random_foundation_hash = mysql_result(mysql_query("SELECT hash FROM `transaction_foundation` WHERE `block` = {$rand_block} LIMIT 1"), 0, 0);
 // Grab random Transaction Hash
 $rand_block2 = rand(transaction_cycle(0 - transaction_cycle(0, TRUE), TRUE), transaction_cycle(-1000, TRUE));
 // Range from Start to Last 1000 Transaction Hash
 $rand_block2 = transaction_cycle(0 - $rand_block2);
 $random_transaction_hash = mysql_result(mysql_query("SELECT hash FROM `transaction_history` WHERE `timestamp` = {$rand_block2} LIMIT 1"), 0, 0);
 $rand_block2 = ($rand_block2 - TRANSACTION_EPOCH - 300) / 300;
 for ($i = 0; $i < $sql_num_results; $i++) {
     $sql_row = mysql_fetch_array($sql_result);
     if (rand(1, 2) == 2) {
         $ip_address = $sql_row["IP_Address"];
         $domain = $sql_row["domain"];
         $subfolder = $sql_row["subfolder"];
         $port_number = $sql_row["port_number"];
         $last_heartbeat = $sql_row["last_heartbeat"];
         $join_peer_list = $sql_row["join_peer_list"];
         // Choose the type polling done
         $poll_type = rand(1, 6);
         // 1&2=CRC32
         // 3&4=Server Full Check
예제 #18
0
                     $new_string = str_replace("---enable=1", "---enable=0", $new_string);
                     // Update DB to Disable Task When Finished
                     mysql_query("UPDATE `options` SET `field_data` = '{$new_string}' WHERE `options`.`field_name` = '{$tx_record_name}' LIMIT 1");
                     write_log("Auto Transfer Task ({$tx_name}) Has Completed.", "T");
                 }
             }
         }
         // One Shot Amount Match Transfer
         if ($tx_type == "repeatamount") {
             $tx_key3 = find_string("---key3=", "---amount", $sql_row["field_data"]);
             $tx_key3 = mysql_result(mysql_query("SELECT field_data FROM `my_keys` WHERE `field_name` = '{$tx_key3}' LIMIT 1"), 0, 0);
             $tx_amount = find_string("---amount=", "---amount_match", $sql_row["field_data"]);
             $amount_match = find_string("---amount_match=", "---end", $sql_row["field_data"]);
             // Only check once per transaction cycle or otherwise it will just make a transfer every time it scans
             // Check allowed 180 seconds before and 60 seconds after transaction cycle.
             if (transaction_cycle(1) - time() > 180 && time() - transaction_cycle(0) >= 60) {
                 if (check_crypt_balance($tx_key2) >= $amount_match) {
                     // Create Transaction
                     if (send_timekoins($tx_key1, $tx_key2, $tx_key3, $tx_amount, NULL) == TRUE) {
                         write_log("Auto Transfer Task ({$tx_name}) Has Completed.", "T");
                     }
                 }
             }
         }
         // Repeating Amount Match Transfer
     }
     // Check if enabled
 }
 // Looping through all task
 // Idle State
 mysql_query("UPDATE `main_loop_status` SET `field_data` = '2' WHERE `main_loop_status`.`field_name` = 'autotransfer.php' LIMIT 1");
예제 #19
0
function transaction_queue()
{
    $next_transaction_cycle = transaction_cycle(1);
    $current_transaction_cycle = transaction_cycle(0);
    $results;
    // Wipe transaction queue of all old transaction from current to previous cycle
    if (rand(1, 2) == 2) {
        mysql_query("DELETE QUICK FROM `transaction_queue` WHERE `transaction_queue`.`timestamp` < {$current_transaction_cycle}");
    }
    // Create a hash of my own transaction queue
    $transaction_queue_hash = queue_hash();
    // How does my transaction queue compare to others?
    // Ask all of my active peers
    ini_set('user_agent', 'Timekoin Client (Queueclerk) v' . TIMEKOIN_VERSION);
    ini_set('default_socket_timeout', 2);
    // Timeout for request in seconds
    $transaction_queue_hash_match = 0;
    $transaction_queue_hash_different = 0;
    $hash_different = array();
    $sql = "SELECT * FROM `active_peer_list` ORDER BY RAND()";
    $sql_result = mysql_query($sql);
    $sql_num_results = mysql_num_rows($sql_result);
    $transaction_queue_hash_match = 0;
    $transaction_queue_hash_different = 0;
    if ($sql_num_results > 0) {
        $hash_different = array();
        for ($i = 0; $i < $sql_num_results; $i++) {
            $sql_row = mysql_fetch_array($sql_result);
            $ip_address = $sql_row["IP_Address"];
            $domain = $sql_row["domain"];
            $subfolder = $sql_row["subfolder"];
            $port_number = $sql_row["port_number"];
            $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 32, "queueclerk.php?action=trans_hash&client=api");
            if ($transaction_queue_hash === $poll_peer) {
                $transaction_queue_hash_match++;
            } else {
                if (empty($poll_peer) == FALSE) {
                    $transaction_queue_hash_different++;
                    $hash_different["ip_address{$transaction_queue_hash_different}"] = $ip_address;
                    $hash_different["domain{$transaction_queue_hash_different}"] = $domain;
                    $hash_different["subfolder{$transaction_queue_hash_different}"] = $subfolder;
                    $hash_different["port_number{$transaction_queue_hash_different}"] = $port_number;
                }
            }
        }
        // End for Loop
    }
    // End number of results check
    // Compare tallies
    if ($transaction_queue_hash_different > 0) {
        // Transaction Queue still not in sync with all peers
        $hash_array = array();
        $transaction_counter = 0;
        for ($i = 1; $i < $transaction_queue_hash_different + 1; $i++) {
            $ip_address = $hash_different["ip_address{$i}"];
            $domain = $hash_different["domain{$i}"];
            $subfolder = $hash_different["subfolder{$i}"];
            $port_number = $hash_different["port_number{$i}"];
            $poll_peer = filter_sql(poll_peer($ip_address, $domain, $subfolder, $port_number, 83000, "queueclerk.php?action=queue&client=api"));
            // Bring up first match (if any) to compare agaist our database
            $match_number = 1;
            $current_hash = find_string("---queue{$match_number}=", "---end{$match_number}", $poll_peer);
            $transaction_counter = 0;
            $peer_transaction_limit = 1000;
            $mismatch_error_count = 0;
            $mismatch_error_limit = 10;
            while (empty($current_hash) == FALSE) {
                // Count transactions coming from this peer
                $transaction_counter++;
                if ($transaction_counter > $peer_transaction_limit) {
                    break;
                }
                if ($mismatch_error_count > $mismatch_error_limit) {
                    break;
                }
                if (strlen($current_hash) >= 64) {
                    // Old Queue System Check
                    //Check if this transaction is already in our queue
                    $hash_match = mysql_result(mysql_query("SELECT timestamp FROM `transaction_queue` WHERE `hash` = '{$current_hash}' LIMIT 1"), 0, 0);
                } else {
                    // New Queue System Check
                    $sql2 = "SELECT * FROM `transaction_queue`";
                    $sql_result2 = mysql_query($sql2);
                    $sql_num_results2 = mysql_num_rows($sql_result2);
                    $queue_hash_test = NULL;
                    $hash_match = NULL;
                    if ($sql_num_results2 > 0) {
                        for ($i2 = 0; $i2 < $sql_num_results2; $i2++) {
                            $sql_row2 = mysql_fetch_array($sql_result2);
                            $queue_hash_test .= $sql_row2["timestamp"] . $sql_row2["public_key"] . $sql_row2["crypt_data1"] . $sql_row2["crypt_data2"] . $sql_row2["crypt_data3"] . $sql_row2["hash"] . $sql_row2["attribute"];
                            if (hash('md5', $queue_hash_test) == $current_hash) {
                                // This Transaction Already Exist in the Queue
                                $hash_match = TRUE;
                                break;
                            } else {
                                // No match, continue searching
                                $hash_match = NULL;
                            }
                            // No match, move on to next record
                            $queue_hash_test = NULL;
                        }
                    }
                }
                if (empty($hash_match) == TRUE) {
                    // This peer has a different transaction, ask for the full details of it
                    $poll_hash = poll_peer($ip_address, $domain, $subfolder, $port_number, 1500, "queueclerk.php?action=transaction&number={$current_hash}&client=api");
                    $transaction_timestamp = find_string("-----timestamp=", "-----public_key", $poll_hash);
                    $transaction_public_key = find_string("-----public_key=", "-----crypt1", $poll_hash);
                    $transaction_crypt1 = find_string("-----crypt1=", "-----crypt2", $poll_hash);
                    $transaction_crypt2 = find_string("-----crypt2=", "-----crypt3", $poll_hash);
                    $transaction_crypt3 = find_string("-----crypt3=", "-----hash", $poll_hash);
                    $transaction_hash = find_string("-----hash=", "-----attribute", $poll_hash);
                    $transaction_attribute = find_string("-----attribute=", "-----end", $poll_hash);
                    $transaction_qhash = find_string("---qhash=", "---endqhash", $poll_hash);
                    // If a qhash is included, use this to verify the data
                    if (empty($transaction_qhash) == FALSE) {
                        $qhash = $transaction_timestamp . $transaction_public_key . $transaction_crypt1 . $transaction_crypt2 . $transaction_crypt3 . $transaction_hash . $transaction_attribute;
                        $qhash = hash('md5', $qhash);
                        // Compare hashes to make sure data is intact
                        if ($transaction_qhash != $qhash) {
                            $transaction_attribute = "mismatch";
                            $mismatch_error_count++;
                        } else {
                            // Make sure hash is actually valid and not made up to stop other transactions
                            $crypt_hash_check = hash('sha256', $transaction_crypt1 . $transaction_crypt2 . $transaction_crypt3);
                            if ($crypt_hash_check != $transaction_hash) {
                                // Ok, something is wrong here...
                                $transaction_attribute = "mismatch";
                                $mismatch_error_count++;
                            }
                        }
                    } else {
                        // Qhash is required to match hash
                        $transaction_attribute = "mismatch";
                        $mismatch_error_count++;
                    }
                    $transaction_public_key = filter_sql(base64_decode($transaction_public_key));
                    if ($transaction_attribute == "R") {
                        // Check to make sure this public key isn't forged or made up to win the list
                        $inside_transaction_hash = tk_decrypt($transaction_public_key, base64_decode($transaction_crypt1));
                        $final_hash_compare = $transaction_crypt2;
                        $crypt_hash_check = $transaction_hash;
                        $valid_amount = TRUE;
                        // No amount, but needs this to pass amount test
                        $public_key_to = $transaction_public_key;
                        // None is used, but needs this to pass the key length test
                    } else {
                        if ($transaction_attribute == "T" || $transaction_attribute == "G") {
                            // Decrypt transaction information for regular transaction data
                            // and check to make sure the public key that is being sent to
                            // has not been tampered with.
                            $transaction_info = tk_decrypt($transaction_public_key, base64_decode($transaction_crypt3));
                            // Find destination public key
                            $public_key_to_1 = tk_decrypt($transaction_public_key, base64_decode($transaction_crypt1));
                            $public_key_to_2 = tk_decrypt($transaction_public_key, base64_decode($transaction_crypt2));
                            $public_key_to = $public_key_to_1 . $public_key_to_2;
                            $transaction_amount_sent = find_string("AMOUNT=", "---TIME", $transaction_info);
                            $transaction_amount_sent_test = intval($transaction_amount_sent);
                            if ($transaction_amount_sent_test == $transaction_amount_sent) {
                                // Is a valid integer, amount greater than zero?
                                if ($transaction_amount_sent > 0) {
                                    $valid_amount = TRUE;
                                } else {
                                    $valid_amount = FALSE;
                                }
                            } else {
                                // Is NOT a valid integer, fail check
                                $valid_amount = FALSE;
                            }
                            if ($transaction_attribute == "G") {
                                if ($transaction_amount_sent_test > 10) {
                                    // Filter silly generation amounts :p
                                    $valid_amount = FALSE;
                                }
                            }
                            $inside_transaction_hash = find_string("HASH=", "", $transaction_info, TRUE);
                            // Check if a message is encoded in this data as well
                            if (strlen($inside_transaction_hash) != 64) {
                                // A message is also encoded
                                $inside_transaction_hash = find_string("HASH=", "---MSG", $transaction_info);
                            }
                            // Check Hash against 3 crypt fields
                            $crypt_hash_check = hash('sha256', $transaction_crypt1 . $transaction_crypt2 . $transaction_crypt3);
                        }
                        $final_hash_compare = hash('sha256', $transaction_crypt1 . $transaction_crypt2);
                    }
                    // Check to make sure this transaction is even valid (hash check, length check, & timestamp)
                    if ($transaction_hash == $crypt_hash_check && $inside_transaction_hash == $final_hash_compare && strlen($transaction_public_key) > 300 && strlen($public_key_to) > 300 && $transaction_timestamp >= $current_transaction_cycle && $transaction_timestamp < $next_transaction_cycle && $valid_amount == TRUE) {
                        // Check for 100 public key limit in the transaction queue
                        $sql = "SELECT timestamp FROM `transaction_queue` WHERE `public_key` = '{$transaction_public_key}'";
                        $sql_result = mysql_query($sql);
                        $sql_num_results = mysql_num_rows($sql_result);
                        if ($sql_num_results < 100) {
                            // Transaction hash and real hash match.
                            mysql_query("INSERT INTO `transaction_queue` (`timestamp`,`public_key`,`crypt_data1`,`crypt_data2`,`crypt_data3`, `hash`, `attribute`)\n\t\t\t\t\t\t\tVALUES ('{$transaction_timestamp}', '{$transaction_public_key}', '{$transaction_crypt1}', '{$transaction_crypt2}' , '{$transaction_crypt3}', '{$transaction_hash}' , '{$transaction_attribute}')");
                        }
                    }
                }
                // End Empty Hash Check
                $match_number++;
                $current_hash = find_string("---queue{$match_number}=", "---end{$match_number}", $poll_peer);
            }
            // End While Loop
        }
        // End For Loop
    }
    // End Compare Tallies
    return;
}