check for findOne null
This commit is contained in:
parent
c2c51e709a
commit
479d55de4a
@ -15,7 +15,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
// Pass Mongo params, fields and limit to db api.
|
// Pass Mongo params, fields and limit to db api.
|
||||||
return db.blocks.getByHash(blockHash,
|
return db.blocks.getByHash(blockHash,
|
||||||
(err, block) => {
|
(err, block) => {
|
||||||
if (err) {
|
if (err || !block) {
|
||||||
logger.log('err', err);
|
logger.log('err', err);
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
}
|
}
|
||||||
@ -43,7 +43,6 @@ module.exports = function BlockAPI(router) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.get('/blocks', (req, res) => {
|
router.get('/blocks', (req, res) => {
|
||||||
const limit = parseInt(req.query.limit, 10) || 100;
|
|
||||||
// Pass Mongo params, fields and limit to db api.
|
// Pass Mongo params, fields and limit to db api.
|
||||||
db.blocks.getTopBlocks(
|
db.blocks.getTopBlocks(
|
||||||
(err, blocks) => {
|
(err, blocks) => {
|
||||||
@ -80,7 +79,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
// Pass Mongo params, fields and limit to db api.
|
// Pass Mongo params, fields and limit to db api.
|
||||||
return db.blocks.getRawBlock(blockHash,
|
return db.blocks.getRawBlock(blockHash,
|
||||||
(err, block) => {
|
(err, block) => {
|
||||||
if (err) {
|
if (err || !block) {
|
||||||
logger.log('error',
|
logger.log('error',
|
||||||
`/rawblock/:blockHash: ${err}`);
|
`/rawblock/:blockHash: ${err}`);
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
@ -94,7 +93,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
// Pass Mongo params, fields and limit to db api.
|
// Pass Mongo params, fields and limit to db api.
|
||||||
return db.blocks.byHeight(height,
|
return db.blocks.byHeight(height,
|
||||||
(err, block) => {
|
(err, block) => {
|
||||||
if (err) {
|
if (err || !block) {
|
||||||
logger.log('error',
|
logger.log('error',
|
||||||
`/block-index/:height: ${err}`);
|
`/block-index/:height: ${err}`);
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
const Transactions = require('../../models/transaction.js');
|
const Transactions = require('../../models/transaction.js');
|
||||||
const logger = require('../logger');
|
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
|
|
||||||
const Txs = new Transactions();
|
const Txs = new Transactions();
|
||||||
|
|||||||
@ -24,18 +24,10 @@ function start() {
|
|||||||
db.blocks.bestHeight(entry.height);
|
db.blocks.bestHeight(entry.height);
|
||||||
});
|
});
|
||||||
|
|
||||||
node.chain.on('full', (block) => {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
node.on('error', (err) => {
|
node.on('error', (err) => {
|
||||||
logger.log('error',
|
logger.log('error',
|
||||||
`${err}`);
|
`${err}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
node.mempool.on('tx', (tx) => {
|
|
||||||
socket.emitTx(tx);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@ -6,16 +6,7 @@ const util = require('../../lib/util');
|
|||||||
const logger = require('../logger');
|
const logger = require('../logger');
|
||||||
const db = require('../db');
|
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) {
|
function parse(entry, txs) {
|
||||||
counter++;
|
|
||||||
txs.forEach((tx) => {
|
txs.forEach((tx) => {
|
||||||
const txJSON = tx.toJSON();
|
const txJSON = tx.toJSON();
|
||||||
const txRAW = tx.toRaw();
|
const txRAW = tx.toRaw();
|
||||||
@ -61,12 +52,8 @@ function parse(entry, txs) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
logger.log('error', err.message);
|
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
|
findEmptyInputs();
|
||||||
if (counter % 20 === 0) {
|
|
||||||
findEmptyInputs();
|
|
||||||
counter = 0;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -84,10 +71,10 @@ function findEmptyInputs() {
|
|||||||
const txHash = input.prevout.hash;
|
const txHash = input.prevout.hash;
|
||||||
const outIdx = input.prevout.index;
|
const outIdx = input.prevout.index;
|
||||||
|
|
||||||
return db.txs.getTxById(txHash, (err, tx) => {
|
return db.txs.getTxById(txHash, (error, tx) => {
|
||||||
if (err) {
|
if (error || !tx) {
|
||||||
return logger.log('error',
|
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);
|
return db.txs.updateInput(inputTx._id, input._id, tx.outputs[outIdx].value, tx.outputs[outIdx].address);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -83,7 +83,7 @@ TransactionSchema.methods.last = function lastTx(cb) {
|
|||||||
.sort({ height: -1 });
|
.sort({ height: -1 });
|
||||||
};
|
};
|
||||||
|
|
||||||
TransactionSchema.methods.getEmptyInputs = function findEmptyInputs(cb) {
|
TransactionSchema.methods.getEmptyInputs = function getEmptyInputs(cb) {
|
||||||
return this.model('Transaction').find({
|
return this.model('Transaction').find({
|
||||||
'inputs.prevout.hash': { $ne: '0000000000000000000000000000000000000000000000000000000000000000' },
|
'inputs.prevout.hash': { $ne: '0000000000000000000000000000000000000000000000000000000000000000' },
|
||||||
'inputs.address': '',
|
'inputs.address': '',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user