Skip to content

Instantly share code, notes, and snippets.

@whiskers75
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whiskers75/189e46d9056dbb9b0191 to your computer and use it in GitHub Desktop.
Save whiskers75/189e46d9056dbb9b0191 to your computer and use it in GitHub Desktop.
var SocketClient = require('websocket').client;
var client = new SocketClient();
var satoshi = 100000000;
var piGlow = require('piglow');
var animation = require('piglow-animations').animation;
console.log('whiskers75\'s PiGlow Bitcoin Script');
console.log('http://whiskers75.co.uk');
piGlow(function(e, pie) {
if (e) throw e;
function fade(target, interval) {
for (x = 10; x < 150; x = x + interval) {
pie[target] = x;
}
for (x = 150; x > 10; x = x - interval) {
pie[target] = x;
}
pie[target] = 0;
};
pie.all = 0;
client.on('connectFailed', function(err) {
throw err;
});
client.on('connect', function(ws) {
console.log('[' + Date() + '] Connected to blockchain.info');
function send(o) {
ws.sendUTF(JSON.stringify(o));
}
ws.on('message', function(msg) {
msg = JSON.parse(msg.utf8Data);
if (msg.op == 'utx') {
var totalTransacted = 0;
msg.x.out.forEach(function(output) {
totalTransacted = totalTransacted + output.value;
});
totalTransacted = Number((totalTransacted / satoshi).toFixed(2));
if (totalTransacted < 0.01) return;
console.log('[' + Date() + '] ' + totalTransacted + '฿ transacted - http://blockchain.info/tx/' + msg.x.hash);
if (totalTransacted < 1) return fade('ring_0', 4);
if (totalTransacted < 10) return fade('ring_1', 3);
if (totalTransacted < 20) return fade('ring_2', 3);
if (totalTransacted < 40) return fade('ring_3', 2);
if (totalTransacted < 80) return fade('ring_4', 2);
if (totalTransacted < 160) return fade('ring_5', 1);
}
if (msg.op == 'block') {
console.log('### BLOCK #' + msg.x.blockIndex + ' ###');
return fade('all', 0.5);
}
});
send({'op': 'unconfirmed_sub'});
send({'op': 'blocks_sub'});
});
client.connect('ws://ws.blockchain.info/inv');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment