diff options
| author | Adam Soltys <[email protected]> | 2012-11-12 17:31:37 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2012-11-12 17:31:40 -0800 |
| commit | c3d599a58a6d5a86527478b4b712b00134d0547e (patch) | |
| tree | f4716b141c2b91b97715a442120daa922873bee0 | |
| parent | 95d18698d19102da315091aee16f49809f96e9ab (diff) | |
| download | coinos-server-c3d599a58a6d5a86527478b4b712b00134d0547e.tar.gz coinos-server-c3d599a58a6d5a86527478b4b712b00134d0547e.zip | |
Switch from mysql to redis
| -rw-r--r-- | app.coffee | 36 | ||||
| -rw-r--r-- | public/js/calculator.coffee | 35 | ||||
| -rw-r--r-- | views/index.html | 3 |
3 files changed, 29 insertions, 45 deletions
@@ -24,15 +24,11 @@ app.get('/report', (req, res) -> res.render('report', js: (-> global.js), css: (-> global.css)) ) -app.get('/client/:login', (req, res) -> - connection = require('mysql').createConnection(config.database) - - connection.connect() - connection.query("SELECT name, address, commission, logo FROM users WHERE login = ?", - [req.params.login], (err, rows) -> - res.write(JSON.stringify(rows)) - connection.end() - res.end() +app.get('/client/:client', (req, res) -> + db = require("redis").createClient() + db.hgetall(req.params.client, (err, obj) -> + res.write(JSON.stringify(obj)) + res.end() ) ) @@ -65,24 +61,10 @@ app.get('/ticker', (req, res) -> ) app.post('/create', (req, res) -> - connection = require('mysql').createConnection(config.database) - - connection.connect() - connection.query(""" - INSERT INTO users - (login, name, address, commission) - VALUES - (?, ?, ?, ?) - """, - [ - req.body.login, - req.body.name, - req.body.address, - req.body.commission - ], (err, rows) -> - connection.end() - res.writeHead(302, 'Location': '/' + req.body.login) - res.end() + db = require("redis").createClient() + db.hmset(req.body.login, req.body, -> + res.writeHead(302, 'Location': '/' + req.body.login) + res.end() ) ) diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee index 08757249..6861bb16 100644 --- a/public/js/calculator.coffee +++ b/public/js/calculator.coffee @@ -20,11 +20,10 @@ $(-> if client? and client $.getJSON('client/' + client, (data) -> - user = data[0] - g.title = user.name - g.address = user.address - g.commission = user.commission - g.logo = user.logo + g.title = data.name + g.address = data.address + g.commission = data.commission + g.logo = data.logo setupPage() ) @@ -40,14 +39,14 @@ $(-> updateTotal = -> amount = parseFloat($('#amount').val()) - total = amount / exchange + total = amount / g.exchange total = Math.ceil(total * 10000) / 10000 unless $.isNumeric(total) total = '' $('#total').html(total.toString()) - displayQR('bitcoin:' + address + '?amount=' + total.toString()) + displayQR('bitcoin:' + g.address + '?amount=' + total.toString()) exchangeFail = -> $('#error').show().html("Error fetching exchange rate") @@ -63,7 +62,7 @@ fetchExchangeRate = -> exchange = 1000 / data.out exchange = exchange - exchange * commission * 0.01 g.exchange = Math.ceil(exchange * 100) / 100 - $('#exchange').val(exchange.toFixed(2)) + $('#exchange').val(g.exchange.toFixed(2)) updateTotal() $('#error').hide() @@ -72,18 +71,18 @@ fetchExchangeRate = -> setTimeout(fetchExchangeRate, 900000) setupPage = -> - unless address - address = '1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr' + unless g.address + g.address = '1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr' - unless commission - commission = 3 + unless g.commission + g.commission = 3 - if logo - $('#logo').attr('src', logo).show() + if g.logo + $('#logo').attr('src', g.logo).show() else $('#title').html(title).show() - $('#address').html(address) + $('#address').html(g.address) $('#received').hide() fetchExchangeRate() @@ -95,7 +94,7 @@ setupSocket = -> g.websocket = new WebSocket("ws://api.blockchain.info:8335/inv") g.websocket.onopen = -> - g.websocket.send('{"op":"addr_sub", "addr":"' + address + '"}') + g.websocket.send('{"op":"addr_sub", "addr":"' + g.address + '"}') g.websocket.onerror = g.websocket.onclose = -> @@ -110,13 +109,13 @@ setupSocket = -> received = 0 $.each(results.x.out, (i, v) -> - if (v.addr == address) + if (v.addr == g.address) received += v.value / 100000000 ) $.each(results.x.inputs, (i, v) -> from_address = v.prev_out.addr - if (v.prev_out.addr == address) + if (v.prev_out.addr == g.address) input -= v.prev_out.value / 100000000 ) diff --git a/views/index.html b/views/index.html index 4080f66c..1182ff4e 100644 --- a/views/index.html +++ b/views/index.html @@ -18,6 +18,9 @@ <label for="name">Title:</label> <input type="text" id="name" name="name" /> + <label for="logo">Image:</label> + <input type="text" id="logo" name="logo" /> + <label for="address">Bitcoin Address:</label> <input type="text" id="address" name="address" /> |
