aboutsummaryrefslogtreecommitdiffstats
path: root/js/bitcoin.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2012-10-17 20:23:41 -0700
committerAdam Soltys <[email protected]>2012-10-17 20:23:41 -0700
commit9298fa3f6798eb8d046a641e7dcb022d4ff14824 (patch)
tree47e86330b5ce4646f1256ea570bcc8a414f0aa9f /js/bitcoin.js
parent9be6aaf6cda1767eb6ea2145671f5d2bba6c30b2 (diff)
downloadcoinos-server-9298fa3f6798eb8d046a641e7dcb022d4ff14824.tar.gz
coinos-server-9298fa3f6798eb8d046a641e7dcb022d4ff14824.zip
Include bootstrap
Diffstat (limited to 'js/bitcoin.js')
-rw-r--r--js/bitcoin.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/js/bitcoin.js b/js/bitcoin.js
new file mode 100644
index 00000000..7bb43b91
--- /dev/null
+++ b/js/bitcoin.js
@@ -0,0 +1,89 @@
+$(function() {
+ var websocket = new WebSocket("ws://api.blockchain.info:8335/inv");
+ var exchange = 0;
+ var total = 0;
+ var received = 0;
+ var address = getParameterByName('address');
+
+ setupqr();
+
+ if (address == "")
+ window.location = 'index.html?address=1SoLtySab29J2tAdF2x3PosjnwWF37wEY'
+
+ $('#address').html(address);
+
+ websocket.onopen = function() {
+ websocket.send('{"op":"addr_sub", "addr":"' + address + '"}');
+ }
+
+ websocket.onmessage = function(e) {
+ var results = eval('(' + e.data + ')');
+ var from_address = '';
+
+ $.each(results.x.out, function(i, v) {
+ if (v.addr == address) {
+ received += v.value / 100000000;
+ }
+ });
+
+ $.each(results.x.inputs, function(i, v) {
+ from_address = v.prev_out.addr
+ if (v.prev_out.addr == address) {
+ input -= v.prev_out.value / 100000000;
+ }
+ });
+
+ $('#status').html('Received: ' + received.toString());
+ if (total <= received) {
+ $('#status').css('color', 'green');
+ }
+
+ $.get('record_transaction.php',
+ {
+ address: from_address,
+ date: getFormattedDate(),
+ received: received,
+ exchange: exchange
+ }
+ );
+ }
+
+ $.getJSON('ticker.json', function (data) {
+ exchange = 100 / data.out;
+ exchange = exchange + exchange * 0.03;
+ exchange = Math.ceil(exchange * 100) / 100;
+ $('#exchange').html(exchange);
+ updateTotal();
+ });
+
+ $('#owing').keyup(updateTotal);
+ $('#owing').focus();
+
+ function updateTotal() {
+ var owing = parseFloat($('#owing').val());
+ total = owing / exchange;
+ total = Math.ceil(total * 10000) / 10000;
+ if (!$.isNumeric(total)) total = '';
+ $('#total').html(total.toString());
+ doqr('bitcoin:' + address + '?amount=' + total.toString());
+ }
+});
+
+function getParameterByName(name) {
+ name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
+ var regexS = "[\\?&]" + name + "=([^&#]*)";
+ var regex = new RegExp(regexS);
+ var results = regex.exec(window.location.search);
+ if(results == null)
+ return "";
+ else
+ return decodeURIComponent(results[1].replace(/\+/g, " "));
+}
+
+function getFormattedDate() {
+ var date = new Date();
+ var str = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
+
+ return str;
+}
+