Skip to content

Commit d91f122

Browse files
committed
...
1 parent 79b263a commit d91f122

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

scrape-blockexplorer.coffee

+16-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ exports.get_unspent_outpoints = (address, callback) ->
99

1010
http.get {host:"blockexplorer.com", port:80, path:"/address/#{address}"}, (res) ->
1111
readData res, (data) ->
12-
[received, sent_transactions] = scrape_address_ledger data.toString 'utf-8'
12+
html = data.toString 'utf-8'
13+
[received, sent_transactions] = scrape_address_ledger html, address
1314

1415
async.map sent_transactions, tx_input_outpoints, (err, results) ->
1516

1617
# Set of received outpoints
1718
set = {}
1819
for row in received
19-
set[row.outpoint] = row
20+
set["#{row.hash}:#{row.n}"] = row
2021

2122
# Setminus the spent ones
2223
for outpoints in results
@@ -46,7 +47,16 @@ tx_input_outpoints = (tx_hash, cb) ->
4647
cb null, outpoints
4748

4849

49-
scrape_address_ledger = (html) ->
50+
satoshis_from_decimal = (text) ->
51+
if text.match /^[0-9]+$/
52+
parseInt(text, 10) * 1e8
53+
else
54+
[left, right] = text.split '.'
55+
assert.ok (right.length <= 8), "right.length > 8"
56+
rightSatoshis = parseInt(right, 10) * Math.pow(10, 8 - right.length)
57+
(left * 1e8) + rightSatoshis
58+
59+
scrape_address_ledger = (html, address) ->
5060

5161
received = []
5262
sent_transactions_set = {}
@@ -73,9 +83,9 @@ scrape_address_ledger = (html) ->
7383
received.push {
7484
hash: hash
7585
n: n
76-
outpoint: "#{hash}:#{n}"
77-
block_number: block_number
78-
value_str: value_str
86+
satoshis: satoshis_from_decimal(value_str)
87+
amount: value_str
88+
address: address
7989
}
8090
else
8191
sent_transactions_set[hash] = true

server.coffee

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
process.on 'uncaughtException', (e) ->
3+
console.log "*** Exception: #{e}"
4+
25
express = require 'express'
36

47
app = express.createServer()
@@ -7,7 +10,7 @@ app.configure () ->
710
app.use express.methodOverride()
811
app.use express.bodyParser()
912
app.use app.router
10-
# app.use express.errorHandler()
13+
app.use express.errorHandler()
1114

1215
require('./app')(app)
1316

0 commit comments

Comments
 (0)