Socket
Socket
Sign inDemoInstall

insight-api

Package Overview
Dependencies
Maintainers
4
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insight-api - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

test/index.js

1

lib/blocks.js

@@ -6,3 +6,2 @@ 'use strict';

var bitcore = require('bitcore-lib');
var BufferUtil = bitcore.util.buffer;
var pools = require('../pools.json');

@@ -9,0 +8,0 @@ var BN = bitcore.crypto.BN;

@@ -18,2 +18,11 @@ 'use strict';

/**
* A service for Bitcore to enable HTTP routes to query information about the blockchain.
*
* @param {Object} options
* @param {Boolean} options.enableCache - This will enable cache-control headers
* @param {Number} options.cacheShortSeconds - The time to cache short lived cache responses.
* @param {Number} options.cacheLongSeconds - The time to cache long lived cache responses.
* @param {String} options.routePrefix - The URL route prefix
*/
var InsightAPI = function(options) {

@@ -29,2 +38,9 @@ BaseService.call(this, options);

if (!_.isUndefined(options.enableCache)) {
$.checkArgument(_.isBoolean(options.enableCache));
this.enableCache = options.enableCache;
}
this.cacheShortSeconds = options.cacheShortSeconds;
this.cacheLongSeconds = options.cacheLongSeconds;
if (!_.isUndefined(options.routePrefix)) {

@@ -43,2 +59,22 @@ this.routePrefix = options.routePrefix;

InsightAPI.prototype.cache = function(maxAge) {
var self = this;
return function(req, res, next) {
if (self.enableCache) {
res.header('Cache-Control', 'public, max-age=' + maxAge);
}
next();
};
};
InsightAPI.prototype.cacheShort = function() {
var seconds = this.cacheShortSeconds || 30; // thirty seconds
return this.cache(seconds);
};
InsightAPI.prototype.cacheLong = function() {
var seconds = this.cacheLongSeconds || 86400; // one day
return this.cache(seconds);
};
InsightAPI.prototype.getRoutePrefix = function() {

@@ -55,2 +91,3 @@ return this.routePrefix;

InsightAPI.prototype.setupRoutes = function(app) {
//Enable CORS

@@ -65,21 +102,20 @@ app.use(function(req, res, next) {

var blocks = new BlockController(this.node);
app.get('/blocks', blocks.list.bind(blocks));
app.get('/blocks', this.cacheShort(), blocks.list.bind(blocks));
app.get('/block/:blockHash', blocks.show.bind(blocks));
app.get('/block/:blockHash', this.cacheLong(), blocks.show.bind(blocks));
app.param('blockHash', blocks.block.bind(blocks));
app.get('/block-index/:height', blocks.blockIndex.bind(blocks));
app.get('/block-index/:height', this.cacheLong(), blocks.blockIndex.bind(blocks));
app.param('height', blocks.blockIndex.bind(blocks));
// Transaction routes
var transactions = new TxController(this.node);
app.get('/tx/:txid', transactions.show.bind(transactions));
app.get('/tx/:txid', this.cacheLong(), transactions.show.bind(transactions));
app.param('txid', transactions.transaction.bind(transactions));
app.get('/txs', transactions.list.bind(transactions));
app.get('/txs', this.cacheShort(), transactions.list.bind(transactions));
app.post('/tx/send', transactions.send.bind(transactions));
// Raw Routes
app.get('/rawtx/:txid', transactions.showRaw.bind(transactions));
app.get('/rawtx/:txid', this.cacheLong(), transactions.showRaw.bind(transactions));
app.param('txid', transactions.rawTransaction.bind(transactions));

@@ -89,21 +125,21 @@

var addresses = new AddressController(this.node);
app.get('/addr/:addr', addresses.checkAddr.bind(addresses), addresses.show.bind(addresses));
app.get('/addr/:addr/utxo', addresses.checkAddr.bind(addresses), addresses.utxo.bind(addresses));
app.get('/addrs/:addrs/utxo', addresses.checkAddrs.bind(addresses), addresses.multiutxo.bind(addresses));
app.post('/addrs/utxo', addresses.checkAddrs.bind(addresses), addresses.multiutxo.bind(addresses));
app.get('/addrs/:addrs/txs', addresses.checkAddrs.bind(addresses), addresses.multitxs.bind(addresses));
app.post('/addrs/txs', addresses.checkAddrs.bind(addresses), addresses.multitxs.bind(addresses));
app.get('/addr/:addr', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.show.bind(addresses));
app.get('/addr/:addr/utxo', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.utxo.bind(addresses));
app.get('/addrs/:addrs/utxo', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiutxo.bind(addresses));
app.post('/addrs/utxo', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiutxo.bind(addresses));
app.get('/addrs/:addrs/txs', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multitxs.bind(addresses));
app.post('/addrs/txs', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multitxs.bind(addresses));
// Address property routes
app.get('/addr/:addr/balance', addresses.checkAddr.bind(addresses), addresses.balance.bind(addresses));
app.get('/addr/:addr/totalReceived', addresses.checkAddr.bind(addresses), addresses.totalReceived.bind(addresses));
app.get('/addr/:addr/totalSent', addresses.checkAddr.bind(addresses), addresses.totalSent.bind(addresses));
app.get('/addr/:addr/unconfirmedBalance', addresses.checkAddr.bind(addresses), addresses.unconfirmedBalance.bind(addresses));
app.get('/addr/:addr/balance', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.balance.bind(addresses));
app.get('/addr/:addr/totalReceived', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.totalReceived.bind(addresses));
app.get('/addr/:addr/totalSent', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.totalSent.bind(addresses));
app.get('/addr/:addr/unconfirmedBalance', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.unconfirmedBalance.bind(addresses));
// Status route
var status = new StatusController(this.node);
app.get('/status', status.show.bind(status));
app.get('/sync', status.sync.bind(status));
app.get('/peer', status.peer.bind(status));
app.get('/version', status.version.bind(status));
app.get('/status', this.cacheShort(), status.show.bind(status));
app.get('/sync', this.cacheShort(), status.sync.bind(status));
app.get('/peer', this.cacheShort(), status.peer.bind(status));
app.get('/version', this.cacheShort(), status.version.bind(status));

@@ -110,0 +146,0 @@ // Address routes

@@ -62,6 +62,10 @@ 'use strict';

// Not exactly the total blockchain height,
// but we will reach 100% when our db and bitcoind are both fully synced
var totalHeight = this.node.services.bitcoind.height / (this.node.services.bitcoind.syncPercentage() / 100);
var info = {
status: status,
blockChainHeight: this.node.services.bitcoind.height,
syncPercentage: this.node.services.db.tip.__height / this.node.services.bitcoind.height * 100,
syncPercentage: Math.round(this.node.services.db.tip.__height / totalHeight * 100),
height: this.node.services.db.tip.__height,

@@ -68,0 +72,0 @@ error: null,

{
"name": "insight-api",
"description": "A Bitcoin blockchain REST and web socket API service for Bitcore Node.",
"version": "0.3.0",
"version": "0.3.1",
"repository": "git://github.com/bitpay/insight-api.git",

@@ -6,0 +6,0 @@ "contributors": [

@@ -128,3 +128,4 @@ 'use strict';

height: 500000,
isSynced: sinon.stub().returns(true)
isSynced: sinon.stub().returns(true),
syncPercentage: sinon.stub().returns(99.99)
}

@@ -131,0 +132,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc