<commit_before><?php

require_once 'includes.php';

print_stats_top();

$blockhash = substr($_SERVER["PATH_INFO"],1,64);

if (!isset($link)) { $link = pg_pconnect("dbname=$psqldb user=$psqluser password='$<PASSWORD>' host=$psqlhost"); }

$getblockjson = "{\"method\":\"getblock\", \"id\":\"1\", \"params\":[\"$blockhash\"]}";

$query_hash = "blockinfo.php " . hash("sha256", "blockinfo.php $getblockjson");
$getblock = apc_fetch($query_hash);

if (!isset($getblock["result"])) {
	# check if Eligius block
	$getblock = my_curl_request($bitcoinrpcurl, $getblockjson);
	if (!isset($getblock["result"])) {
		$getblock["result"] = "Error";
		apc_add($query_hash, $getblock, 300);
	} else {
		$blockhashesc = pg_escape_string($link, $blockhash);
		$sql = "select blockhash from $psqlschema.stats_blocks where server=$serverid and blockhash='$blockhashesc' limit 1;";
		$result = pg_exec($link, $sql);
		$numrows = pg_numrows($result);
		if ($numrows == 1) {
			apc_add($query_hash, $getblock, 864000);
		} else {
			# not Eligius block...
			$getblock["result"] = "NonEligius";
			apc_add($query_hash, $getblock, 300);
		}
	}
}
if (($getblock["result"]["hash"] != $blockhash) || (strlen($blockhash) != 64)) {
	if ((isset($getblock["result"])) && ($getblock["result"] == "NonEligius")) {
		print "Block is not from $poolname - $blockhash<BR><a HREF=\"http://blockchain.info/block/$blockhash\">View $blockhash on Blockchain.info</A>\n";
	} else {
		print "Block not found - $blockhash\n";
	}
	print_stats_bottom();
	exit;
}

$block = $getblock["result"];

print "<H1>Block #{$block["height"]}</H2>";

$txcount = count($block["tx"]);

print "<TABLE BORDER=1>";

print "<TR><TD><B>Block hash:</B></TD><TD>$blockhash<BR><A HREF=\"http://blockchain.info/block/$blockhash\" TARGET=\"_blank\">View on Blockchain.info</A> - <A HREF=\"http://blockexplorer.com/block/$blockhash\" TARGET=\"_blank\">View on Blockexplorer.com</A></TD></TR>";
print "<TR><TD><B>Height:</B></TD><TD>{$block["height"]}</TD></TR>";
print "<TR><TD><B>Previous Block hash:</B></TD><TD>{$block["previousblockhash"]}</TD></TR>";
print "<TR><TD><B>Merkle root:</B></TD><TD>{$block["merkleroot"]}</TD></TR>";
print "<TR><TD><B>Difficulty:</B></TD><TD>{$block["difficulty"]}</TD></TR>";
print "<TR><TD><B>Bits:</B></TD><TD>{$block["bits"]}</TD></TR>";
print "<TR><TD><B>Nonce:</B></TD><TD>{$block["nonce"]}</TD></TR>";
print "<TR><TD><B>Version:</B></TD><TD>{$block["version"]}</TD></TR>";
$t = date("Y-m-d H:i:s",$block["time"]);
print "<TR><TD><B>Time:</B></TD><TD>$t</TD></TR>";

print "<TR><TD><B>Transactions:</B></TD><TD>$txcount</TD></TR>";
print "<TR><TD><B>Size:</B></TD><TD>{$block["size"]} bytes</TD></TR>";
print "<TR><TD><B>Coinbase transaction id:</B></TD><TD>{$block["tx"][0]}</TD></TR>";


$cbtxid = $block["tx"][0];

$gettxnjson = "{\"method\":\"getrawtransaction\", \"id\":\"1\", \"params\":[\"$cbtxid\",1]}";

$query_hash = "blockinfo.php cbtx " . hash("sha256", "blockinfo.php $gettxnjson");
$gettxn = apc_fetch($query_hash);
if (!isset($gettxn["result"])) {
	$gettxn = my_curl_request($bitcoinrpcurl, $gettxnjson);
	apc_add($query_hash, $gettxn, 864000);
}


$cbtx = $gettxn["result"];

$cbtext = $cbtx["vin"][0]["coinbase"];

$cbouts = count($cbtx["vout"]);
print "<TR><TD><B>Addresses paid in coinbase tx:</B></TD><TD>$cbouts</TD></TR>";

print "</TABLE>";

print "<h2>Payouts in Coinbase Transaction</h2>";

print "<TABLE BORDER=1>";

$failsafe = 0;

for($i=0;$i<$cbouts;$i++) {

	$out = $cbtx["vout"][$i];


	$ammt = $out["value"];
	$pammt = prettySatoshis($ammt*100000000);
	$addr = $out["scriptPubKey"]["addresses"][0];

	$nickname = ""; $dolink = 1;
	if ($addr == "18d3HV2bm94UyY4a9DrPfoZ17sXuiDQq2B") {
		$nickname = "Eligius Offline Wallet";
		$dolink = 0;
	}
	if ($addr == "1GBT3CRvTCadJGUEKrsbv1AdvLqcjscaUb") {
		$failsafe = 1;
		$nickname = "Eligius CPPSRB Failsafe Notification";
		$dolink = 0;
	}

	if ($nickname == "") {
		$nickname = get_nickname($link,get_user_id_from_address($link,$addr));
	}

	#print "$addr ($nickname) - $pammt<BR>";
	if ($nickname != "") {
		if ($dolink == 1) {<commit_msg>Change nonce to hex, add new failsafe addr<commit_after><?php

require_once 'includes.php';

print_stats_top();

$blockhash = substr($_SERVER["PATH_INFO"],1,64);

if (!isset($link)) { $link = pg_pconnect("dbname=$psqldb user=$psqluser password='<PASSWORD>' host=$psqlhost"); }

$getblockjson = "{\"method\":\"getblock\", \"id\":\"1\", \"params\":[\"$blockhash\"]}";

$query_hash = "blockinfo.php " . hash("sha256", "blockinfo.php $getblockjson");
$getblock = apc_fetch($query_hash);

if (!isset($getblock["result"])) {
	# check if Eligius block
	$getblock = my_curl_request($bitcoinrpcurl, $getblockjson);
	if (!isset($getblock["result"])) {
		$getblock["result"] = "Error";
		apc_add($query_hash, $getblock, 300);
	} else {
		$blockhashesc = pg_escape_string($link, $blockhash);
		$sql = "select blockhash from $psqlschema.stats_blocks where server=$serverid and blockhash='$blockhashesc' limit 1;";
		$result = pg_exec($link, $sql);
		$numrows = pg_numrows($result);
		if ($numrows == 1) {
			apc_add($query_hash, $getblock, 864000);
		} else {
			# not Eligius block...
			$getblock["result"] = "NonEligius";
			apc_add($query_hash, $getblock, 300);
		}
	}
}
if (($getblock["result"]["hash"] != $blockhash) || (strlen($blockhash) != 64)) {
	if ((isset($getblock["result"])) && ($getblock["result"] == "NonEligius")) {
		print "Block is not from $poolname - $blockhash<BR><a HREF=\"http://blockchain.info/block/$blockhash\">View $blockhash on Blockchain.info</A>\n";
	} else {
		print "Block not found - $blockhash\n";
	}
	print_stats_bottom();
	exit;
}

$block = $getblock["result"];

print "<H1>Block #{$block["height"]}</H2>";

$txcount = count($block["tx"]);

print "<TABLE BORDER=1>";

print "<TR><TD><B>Block hash:</B></TD><TD>$blockhash<BR><A HREF=\"http://blockchain.info/block/$blockhash\" TARGET=\"_blank\">View on Blockchain.info</A> - <A HREF=\"http://blockexplorer.com/block/$blockhash\" TARGET=\"_blank\">View on Blockexplorer.com</A></TD></TR>";
print "<TR><TD><B>Height:</B></TD><TD>{$block["height"]}</TD></TR>";
print "<TR><TD><B>Previous Block hash:</B></TD><TD>{$block["previousblockhash"]}</TD></TR>";
print "<TR><TD><B>Merkle root:</B></TD><TD>{$block["merkleroot"]}</TD></TR>";
print "<TR><TD><B>Difficulty:</B></TD><TD>{$block["difficulty"]}</TD></TR>";
print "<TR><TD><B>Bits:</B></TD><TD>{$block["bits"]}</TD></TR>";
$nonce = sprintf("%8x",$block["nonce"]);
print "<TR><TD><B>Nonce:</B></TD><TD>$nonce</TD></TR>";
print "<TR><TD><B>Version:</B></TD><TD>{$block["version"]}</TD></TR>";
$t = date("Y-m-d H:i:s",$block["time"]);
print "<TR><TD><B>Time:</B></TD><TD>$t</TD></TR>";

print "<TR><TD><B>Transactions:</B></TD><TD>$txcount</TD></TR>";
print "<TR><TD><B>Size:</B></TD><TD>{$block["size"]} bytes</TD></TR>";
print "<TR><TD><B>Coinbase transaction id:</B></TD><TD>{$block["tx"][0]}</TD></TR>";


$cbtxid = $block["tx"][0];

$gettxnjson = "{\"method\":\"getrawtransaction\", \"id\":\"1\", \"params\":[\"$cbtxid\",1]}";

$query_hash = "blockinfo.php cbtx " . hash("sha256", "blockinfo.php $gettxnjson");
$gettxn = apc_fetch($query_hash);
if (!isset($gettxn["result"])) {
	$gettxn = my_curl_request($bitcoinrpcurl, $gettxnjson);
	apc_add($query_hash, $gettxn, 864000);
}


$cbtx = $gettxn["result"];

$cbtext = $cbtx["vin"][0]["coinbase"];

$cbouts = count($cbtx["vout"]);
print "<TR><TD><B>Addresses paid in coinbase tx:</B></TD><TD>$cbouts</TD></TR>";

print "</TABLE>";

print "<h2>Payouts in Coinbase Transaction</h2>";

print "<TABLE BORDER=1>";

$failsafe = 0;

for($i=0;$i<$cbouts;$i++) {

	$out = $cbtx["vout"][$i];


	$ammt = $out["value"];
	$pammt = prettySatoshis($ammt*100000000);
	$addr = $out["scriptPubKey"]["addresses"][0];

	$nickname = ""; $dolink = 1;
	if ($addr == "<KEY>") {
		$nickname = "Eligius Offline Wallet";
		$dolink = 0;
	}
	if (($addr == "1GBT3CRvTCadJGUEKrsbv1AdvLqcjscaUb") || ($addr == "1FAi1SafERPBXBkq4g8WrhNZ1hR9BRUiSU")) {
		$failsafe = 1;
		$nickname = "Eligius CPPSRB Failsafe Notification";
		$dolink = 0;
	}

	if ($nickname == "") {
		$nickname = get_nickname($link,get_user_id_from_address($link,$addr));
	}

	#print "$addr ($nickname) - $pammt<BR>";
	if ($nickname != "") {
		if ($dolink == 1) {
{'fraction_non_alphanumeric': 0.2724079457364341, 'fraction_numerical': 0.01744186046511628, 'mean_word_length': 6.148917748917749, 'pattern_counts': {'":': 12, '<': 250, '<?xml version=': 0, '>': 246, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1490531', 'n_tokens_mistral': 3493, 'n_tokens_neox': 3323, 'n_words': 507}