The block reward halving is upon us, and people celebrating need a way to be informed at the moment of the event. The go-to link right now is bitcoinclock.com, but AFAIK it doesn't actually do anything when the event happens.
With the help of
gweedo, I bring you the
Block halving party countdown, as a service to those who wish a salient way to pinpoint the exact time to begin the festivities.
You can set as a parameter the block you wish to celebrate (default is 209999, the last block with 50 BTC reward, after which the network starts working on a 25 BTC block).
When the target block is found, the background becomes green and 3 beeps are sounded. A block before that the background is orange and 1 beep is sounded, and two blocks before the target the background is red.
It uses blockexplorer.com data, so should be about as accurate as it.
You can try it out with a nearby target to test it and become familiar with the functionality.
The code consists of 2 files:
getBlockHeight.php:
<?php
$ch = curl_init("https://blockexplorer.com/q/getblockcount");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
curl_close($ch);
?>
index.php:
<?php
$height=209999;
if(isset($_GET['i'])){
$height=$_GET['i'];
}
?>
<html>
<head>
<title>Block halving party countdown</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://raw.github.com/egonelbre/jsfx/master/lib/audio.js" type="text/javascript"></script>
<script src="https://raw.github.com/egonelbre/jsfx/master/lib/jsfx.js" type="text/javascript"></script>
<script src="https://raw.github.com/egonelbre/jsfx/master/lib/jsfxlib.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var height=parseInt('<?php echo $height; ?>');
var sound = jsfxlib.createWave(["saw",0.0000,0.4000,0.0000,0.1320,0.0000,0.1020,20.0000,638.0000,2400.0000,0.0000,0.0000,0.0000,0.0100,0.0003,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,1.0000,0.0000,0.0000,0.1000,0.0000]);
var lastheight=0;
var extrabeeps=0;
check();
self.setInterval(function(){check()},1000);
function check(){
var currentheight;
$.get('getBlockHeight.php', function(res) {
currentheight=parseInt(res);
if (extrabeeps>0)
{
sound.play();
extrabeeps--;
}
if(currentheight>lastheight&&lastheight<height)
{
if((height-2)>currentheight){
$('body').css("background-color","white");
}else if((height-2)==currentheight){
$('body').css("background-color","red");
}else if((height-1)==currentheight){
$('body').css("background-color","orange");
sound.play();
}else if(height<=currentheight){
$('body').css("background-color","green");
sound.play();
extrabeeps=2;
}
}
lastheight=currentheight;
if(height>currentheight){
$('#amount').html(height-currentheight);
}else if(height<=currentheight){
$('h1').html("HAPPY NEW REWARD!");
}
});
}
});
</script>
</head>
<body>
<center>
<p>
<h1>Blocks remaining: <span id="amount"></span></h1>
<form method="get" action="index.php">
Enter your block height: <input type="text" name="i" /><br />
<input type="submit" value="Set" />
</form>
</p>
</center>
</body>
</html>
Enjoy!