aboutsummaryrefslogtreecommitdiffstats
path: root/public/js/calculator.coffee
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2016-11-22 12:01:38 -0800
committerAdam Soltys <[email protected]>2016-12-26 14:22:39 -0800
commit6101cbf5db17faa2c32d81fc28a3971fb3b98c12 (patch)
treee09e43a8779e1d2b95f461834994d724a2f0c323 /public/js/calculator.coffee
parentfe21ed758564087bb73d19c26dbbae4a94268b0a (diff)
downloadcoinos-server-6101cbf5db17faa2c32d81fc28a3971fb3b98c12.tar.gz
coinos-server-6101cbf5db17faa2c32d81fc28a3971fb3b98c12.zip
Switch to blockcypher API from blockchain
Diffstat (limited to 'public/js/calculator.coffee')
-rw-r--r--public/js/calculator.coffee16
1 files changed, 8 insertions, 8 deletions
diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee
index fccc0c5e..7d185f24 100644
--- a/public/js/calculator.coffee
+++ b/public/js/calculator.coffee
@@ -169,13 +169,13 @@ listen = ->
setTimeout(listen, 12000)
else
fail(SOCKET_FAIL) if g.attempts > 3
- g.blockchain = new WebSocket("wss://ws.blockchain.info/inv")
+ g.blockchain = new WebSocket("wss://socket.blockcypher.com/v1/btc/main")
g.blockchain.onopen = ->
if g.blockchain.readyState is 1
g.attempts = 0
clear(SOCKET_FAIL)
- g.blockchain.send('{"op":"addr_sub", "addr":"' + g.user.address + '"}')
+ g.blockchain.send('{"event":"unconfirmed-tx", "address":"' + g.user.address + '"}')
else
setTimeout(g.blockchain.onopen, 12000 * g.attempts)
@@ -190,17 +190,17 @@ listen = ->
listen()
g.blockchain.onmessage = (e) ->
- results = eval('(' + e.data + ')')
+ tx = JSON.parse(e.data)
+
amount = 0
- txid = results.x.hash
+ txid = tx.hash
return if txid == g.last
g.last = txid
- $.each(results.x.out, (i, v) ->
- if (v.addr == g.user.address)
- amount += v.value / 100000000
- )
+ for output in tx.outputs
+ if (output.addresses[0] == g.user.address)
+ amount += output.value / 100000000
logTransaction(txid, amount)