diff --git a/server/index.js b/server/index.js index 5e164fb..a799335 100644 --- a/server/index.js +++ b/server/index.js @@ -9,10 +9,8 @@ logger.log('debug', db.connect(config.mongodb.uri, config.mongodb.options); - db.connection.once('open', () => { - // DB Audit returns best height to node - db.blocks.findMissingBlocks((err, bestBlockHeight) => { + db.blocks.getBestBlockHeight((err, bestBlockHeight) => { // Pass height to node to start Sync logger.log('debug', `Starting Bcoin from best height: ${bestBlockHeight}`); diff --git a/server/lib/db/blocks.js b/server/lib/db/blocks.js index 78eba2f..198f99c 100644 --- a/server/lib/db/blocks.js +++ b/server/lib/db/blocks.js @@ -39,8 +39,8 @@ function getLastBlock(cb) { .limit(1); } -// Returns the missing block if it exists. Otherwise, return tip. -function findMissingBlocks(cb) { +// Returns highest consecutive block height +function getBestBlockHeight(cb) { logger.log('debug', 'Verifying Mongo Blockchain'); return Block.getHeights((err, blocks) => { @@ -59,7 +59,7 @@ function findMissingBlocks(cb) { } module.exports = { - findMissingBlocks, + getBestBlockHeight, getRawBlock, getTopBlocks, getLastBlock, diff --git a/server/lib/db/transactions.js b/server/lib/db/transactions.js index 35dde60..340116a 100644 --- a/server/lib/db/transactions.js +++ b/server/lib/db/transactions.js @@ -36,39 +36,8 @@ function getTxCountByAddress(address, cb) { return Transactions.countByAddress(address, cb); } -function updateInput(txid, inputid, value, address) { - return Transactions.updateInput(txid, inputid, value, address); -} - -// Updates empty inputs with prevout addr & value -function auditInputs() { - getEmptyInputs( - (err, txs) => { - if (err) { - return logger.log('warn', - `No Empty Inputs found: ${err.err}`); - } - // For each tx with unmarked inputs - return txs.forEach((inputTx) => { - inputTx.inputs.forEach((input) => { - const txHash = input.prevout.hash; - const outIdx = input.prevout.index; - - return getTxById(txHash, (error, tx) => { - if (error || !tx) { - // Mongo save is async. Bcoin is kinda sync... Does not mean the tx will not be found - return logger.log('warn', - `No Tx found: ${txHash} ${error}`); - } - return updateInput(inputTx._id, input._id, tx.outputs[outIdx].value, tx.outputs[outIdx].address); - }); - }); - }); - }); -} module.exports = { - auditInputs, getEmptyInputs, getTopTransactions, getTxById, @@ -76,5 +45,4 @@ module.exports = { getTxCountByBlock, getTxByAddress, getTxCountByAddress, - updateInput, };