From 6faa6d5e36e64372026e52a838334a3bb2353853 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 24 Sep 2012 11:11:03 -0700 Subject: Basic transaction recording --- index.html | 22 ++++++++++++++++++++-- record_transaction.php | 14 ++++++++++++++ ticker.json | 1 + transactions.csv | 10 ++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 record_transaction.php create mode 100644 ticker.json create mode 100644 transactions.csv diff --git a/index.html b/index.html index 724cc489..74f190ea 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,7 @@ websocket.onmessage = function(e) { var results = eval('(' + e.data + ')'); + var from_address = ''; $.each(results.x.out, function(i, v) { if (v.addr == address) { @@ -34,6 +35,7 @@ }); $.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; } @@ -43,10 +45,19 @@ if (total <= received) { $('#status').css('color', 'green'); } + + $.get('record_transaction.php', + { + address: from_address, + date: getFormattedDate(), + received: received, + exchange: exchange + } + ); } - $.getJSON('ticker', function (data) { - exchange = data.return.last.value; + $.getJSON('ticker.json', function (data) { + exchange = data.return.last_local.value; $('#exchange').html(exchange); updateTotal(); }); @@ -73,6 +84,13 @@ 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; + }