diff --git a/lib/index.js b/lib/index.js index f786386..2a97d2e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,5 @@ module.exports = { models: require('./models'), Insight: require('./insight'), - bitcore: require('litecore-lib'), + litecore: require('litecore-lib'), }; diff --git a/lib/insight.js b/lib/insight.js index 5c06ba1..0181fa2 100644 --- a/lib/insight.js +++ b/lib/insight.js @@ -225,6 +225,30 @@ Insight.prototype.getBlocks = function(callback) { }); }; +/** + * @callback Insight.GetBlockIndexCallback + * @param {Error} err + * @param {string} blockhash + */ + +/** + * Get block index + * @param {number} blockheight + * @param {GetBlockIndexCallback} callback + * */ +Insight.prototype.getBlockIndex = function(blockheight, callback) { + $.checkArgument(_.isFunction(callback)); + + this.requestGet('/api/block-index/' + blockheight, function(err, res, body) { + if (err || res.statusCode !== 200) { + return callback(err || res); + } + let { blockHash } = JSON.parse(body); + + return callback(null, blockHash); + }); +}; + /** * @callback Insight.GetBlockCallback * @param {Error} err