From 46c9027bdb438a78af28906a71ef390f7bef2247 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Thu, 10 Aug 2017 17:56:21 -0400 Subject: [PATCH 1/3] Fixed tx value out on home page --- lib/api/transaction.js | 1 + lib/parser/transaction.js | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/api/transaction.js b/lib/api/transaction.js index 846e974..15ac88a 100644 --- a/lib/api/transaction.js +++ b/lib/api/transaction.js @@ -111,6 +111,7 @@ module.exports = function transactionAPI(router) { coinbase: input.script, sequence: input.sequence, n: 0, + addr: input.address, })), vout: tx.outputs.map(output => ({ value: output.value / 1e8, diff --git a/lib/parser/transaction.js b/lib/parser/transaction.js index a875bda..557e4d0 100644 --- a/lib/parser/transaction.js +++ b/lib/parser/transaction.js @@ -16,18 +16,19 @@ function parse(entry, txs) { counter++; if (counter % socketThrottle === 0) { + io.sockets.emit('tx', { txid: txJSON.hash, - valueOut: tx.outputs.reduce((a, b) => { - a = a.toJSON(); - b = b.toJSON(); + valueOut: tx.outputs.reduce((sum, tx) => { + tx = tx.toJSON(); - const valA = (a.value || a.valueOut.value || 0) / 1e8; - const valB = (b.value || b.valueOut.value || 0) / 1e8; + const valB = (tx.value || tx.valueOut.value || 0) / 1e8; - return valA + valB; - }), - }, 0); + console.log(valB) + + return sum + valB; + }, 0), + }); } const t = new TxModel({ From 301e36b5c45a141075123bb40ae3cda12e697b19 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Thu, 10 Aug 2017 17:56:57 -0400 Subject: [PATCH 2/3] CORS added --- lib/api/CORS.js | 37 +++++++++++++++++++++++++++++++++++++ lib/api/index.js | 3 +++ 2 files changed, 40 insertions(+) create mode 100644 lib/api/CORS.js diff --git a/lib/api/CORS.js b/lib/api/CORS.js new file mode 100644 index 0000000..1e4bdcd --- /dev/null +++ b/lib/api/CORS.js @@ -0,0 +1,37 @@ +module.exports = function (req, res, next) { + let allowed = { + + origins: [ + '*', + ], + + methods: [ + 'HEAD', + 'GET', + 'POST', + 'PUT', + 'DELETE', + 'OPTIONS', + ], + + headers: [ + 'Content-Type', + 'Authorization', + 'Content-Length', + 'X-Requested-With', + 'Cache-Control', + 'X-Accept-Version', + 'x-signature', + 'x-pubkey', + 'x-identity', + 'cf-connecting-ip', + ], + + }; + + res.header('Access-Control-Allow-Origin', allowed.origins.join()); + res.header('Access-Control-Allow-Methods', allowed.methods.join()); + res.header('Access-Control-Allow-Headers', allowed.headers.join()); + + next(); +}; diff --git a/lib/api/index.js b/lib/api/index.js index 51f9ca6..382a20e 100644 --- a/lib/api/index.js +++ b/lib/api/index.js @@ -3,6 +3,9 @@ const config = require('../../config'); const app = express(); const api = express.Router(); +const CORS = require('./CORS'); + +app.use(CORS); // Serve insight ui front end from root dir public folder app.use('/', express.static('./public')); From 4a0138b6661b6db404658b592dec300145840ded Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Thu, 10 Aug 2017 21:35:55 -0400 Subject: [PATCH 3/3] Remove console logs. Fix cors --- server/README.md | 6 ++++++ server/lib/api/address.js | 7 ++++++- server/lib/api/index.js | 4 ++-- server/lib/api/socket.js | 8 -------- server/lib/node/index.js | 4 ++-- server/lib/parser/address.js | 4 ++-- server/lib/parser/transaction.js | 2 -- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/server/README.md b/server/README.md index 9e344d9..e1b8a56 100644 --- a/server/README.md +++ b/server/README.md @@ -33,3 +33,9 @@ Ctrl+D out of mongo rm -rf ${bcoin-prefix-in-config.js}/chain.ldb ``` + +### Contributing + +1. Fork +2. Branch +3. Send a PR \ No newline at end of file diff --git a/server/lib/api/address.js b/server/lib/api/address.js index 6ed7087..2b77eeb 100644 --- a/server/lib/api/address.js +++ b/server/lib/api/address.js @@ -1,4 +1,9 @@ -module.exports = function addressrouter(router) { +const Block = require('../../models/block.js'); +const logger = require('../logger'); + +const MAX_BLOCKS = 200; + +module.exports = function AddressAPI(router) { router.get('/addr/:addr', (req, res) => { res.send(req.params.addr); }); diff --git a/server/lib/api/index.js b/server/lib/api/index.js index 382a20e..f97e539 100644 --- a/server/lib/api/index.js +++ b/server/lib/api/index.js @@ -3,9 +3,9 @@ const config = require('../../config'); const app = express(); const api = express.Router(); -const CORS = require('./CORS'); +const cors = require('./cors'); -app.use(CORS); +app.use(cors); // Serve insight ui front end from root dir public folder app.use('/', express.static('./public')); diff --git a/server/lib/api/socket.js b/server/lib/api/socket.js index dfc4557..a0e02ea 100644 --- a/server/lib/api/socket.js +++ b/server/lib/api/socket.js @@ -1,23 +1,15 @@ module.exports = function addressrouter(io) { io.on('connection', (socket) => { socket.on('subscribe', (data) => { - console.log('subscribe message'); - console.log(data); }); socket.on('message', (data) => { - console.log('unsubscribe message'); - console.log(data); }); socket.on('unsubscribe', (data) => { - console.log('unsubscribe message'); - console.log(data); }); socket.on('disconnect', (data) => { - console.log('unsubscribe message'); - console.log(data); }); }); }; diff --git a/server/lib/node/index.js b/server/lib/node/index.js index e55a1ab..533262d 100644 --- a/server/lib/node/index.js +++ b/server/lib/node/index.js @@ -39,7 +39,7 @@ function start() { }); node.pool.on('peer', (peer) => { - // console.log(peer); + }); node.on('error', (err) => { @@ -48,7 +48,7 @@ function start() { }); node.mempool.on('tx', (tx) => { - console.log(tx) + }); } diff --git a/server/lib/parser/address.js b/server/lib/parser/address.js index 0c3616a..8d4955e 100644 --- a/server/lib/parser/address.js +++ b/server/lib/parser/address.js @@ -11,7 +11,7 @@ function parse(entry, txs) { tx.outputs.forEach((output) => { const outputJSON = output.toJSON(); - //console.log(outputJSON); + /* return new OutputModel({ address: outputJSON.address, @@ -22,7 +22,7 @@ function parse(entry, txs) { tx.inputs.forEach((input) => { const inputJSON = input.toJSON(); - //console.log(inputJSON); + /* return new InputModel({ prevout: inputJSON.prevout, script: inputJSON.script, diff --git a/server/lib/parser/transaction.js b/server/lib/parser/transaction.js index 557e4d0..9bb4fa3 100644 --- a/server/lib/parser/transaction.js +++ b/server/lib/parser/transaction.js @@ -24,8 +24,6 @@ function parse(entry, txs) { const valB = (tx.value || tx.valueOut.value || 0) / 1e8; - console.log(valB) - return sum + valB; }, 0), });