diff --git a/server/lib/api/block.js b/server/lib/api/block.js index ee541e4..3041c2c 100644 --- a/server/lib/api/block.js +++ b/server/lib/api/block.js @@ -15,7 +15,7 @@ module.exports = function BlockAPI(router) { // Pass Mongo params, fields and limit to db api. return db.blocks.getByHash(blockHash, (err, block) => { - if (err) { + if (err || !block) { logger.log('err', err); return res.status(404).send(); } @@ -43,7 +43,6 @@ module.exports = function BlockAPI(router) { }); router.get('/blocks', (req, res) => { - const limit = parseInt(req.query.limit, 10) || 100; // Pass Mongo params, fields and limit to db api. db.blocks.getTopBlocks( (err, blocks) => { @@ -80,7 +79,7 @@ module.exports = function BlockAPI(router) { // Pass Mongo params, fields and limit to db api. return db.blocks.getRawBlock(blockHash, (err, block) => { - if (err) { + if (err || !block) { logger.log('error', `/rawblock/:blockHash: ${err}`); return res.status(404).send(); @@ -94,7 +93,7 @@ module.exports = function BlockAPI(router) { // Pass Mongo params, fields and limit to db api. return db.blocks.byHeight(height, (err, block) => { - if (err) { + if (err || !block) { logger.log('error', `/block-index/:height: ${err}`); return res.status(404).send(); diff --git a/server/lib/db/transactions.js b/server/lib/db/transactions.js index 8ea5d1f..9c7b724 100644 --- a/server/lib/db/transactions.js +++ b/server/lib/db/transactions.js @@ -1,5 +1,4 @@ const Transactions = require('../../models/transaction.js'); -const logger = require('../logger'); const config = require('../../config'); const Txs = new Transactions(); diff --git a/server/lib/node/index.js b/server/lib/node/index.js index 2e53167..2f73f29 100644 --- a/server/lib/node/index.js +++ b/server/lib/node/index.js @@ -24,18 +24,10 @@ function start() { db.blocks.bestHeight(entry.height); }); - node.chain.on('full', (block) => { - - }); - node.on('error', (err) => { logger.log('error', `${err}`); }); - - node.mempool.on('tx', (tx) => { - socket.emitTx(tx); - }); } module.exports = { diff --git a/server/lib/parser/transaction.js b/server/lib/parser/transaction.js index 4a1ebd2..73c559e 100644 --- a/server/lib/parser/transaction.js +++ b/server/lib/parser/transaction.js @@ -6,16 +6,7 @@ const util = require('../../lib/util'); const logger = require('../logger'); const db = require('../db'); -// Bleh, Bcoin pulls in blocks 20 at a time -// Crappy delay for now otherwise async saves -// could miss a tx if an input refs a block within -// the last 20 that hasn't saved. -// Aggregate stuff will replace all of this. - -let counter = 0; - function parse(entry, txs) { - counter++; txs.forEach((tx) => { const txJSON = tx.toJSON(); const txRAW = tx.toRaw(); @@ -61,12 +52,8 @@ function parse(entry, txs) { if (err) { logger.log('error', err.message); } - // As long as this modulo is divisible by 20 we should be OK for now. - // Closer to 20 = chattier at start and less ideal later on - if (counter % 20 === 0) { - findEmptyInputs(); - counter = 0; - } + + findEmptyInputs(); }); }); } @@ -84,10 +71,10 @@ function findEmptyInputs() { const txHash = input.prevout.hash; const outIdx = input.prevout.index; - return db.txs.getTxById(txHash, (err, tx) => { - if (err) { + return db.txs.getTxById(txHash, (error, tx) => { + if (error || !tx) { return logger.log('error', - `No Tx found: ${txHash} ${err.err}`); + `No Tx found: ${txHash} ${error}`); } return db.txs.updateInput(inputTx._id, input._id, tx.outputs[outIdx].value, tx.outputs[outIdx].address); }); diff --git a/server/models/transaction.js b/server/models/transaction.js index 2b2358a..318613a 100644 --- a/server/models/transaction.js +++ b/server/models/transaction.js @@ -83,7 +83,7 @@ TransactionSchema.methods.last = function lastTx(cb) { .sort({ height: -1 }); }; -TransactionSchema.methods.getEmptyInputs = function findEmptyInputs(cb) { +TransactionSchema.methods.getEmptyInputs = function getEmptyInputs(cb) { return this.model('Transaction').find({ 'inputs.prevout.hash': { $ne: '0000000000000000000000000000000000000000000000000000000000000000' }, 'inputs.address': '',