diff --git a/README.md b/README.md index 31dba97c..fa84d193 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,8 @@ If bitcoind is shutdown, *insight* needs to be stopped and restarted once bitcoi ### DB storage requirement To store the blockchain and address related information, *insight* uses LevelDB. Two DBs are created: txs and blocks. By default these are stored on - ```/db``` + ```/db``` +Please note that previous version's of Insight-API store that on `/db` this can be changed on config/config.js. As of February 2014, storing the livenet blockchain takes ~30GB of disk space (2GB for the testnet). diff --git a/config/config.js b/config/config.js index bb020097..f59a8f2f 100644 --- a/config/config.js +++ b/config/config.js @@ -1,6 +1,7 @@ 'use strict'; var path = require('path'), + fs = require('fs'), rootPath = path.normalize(__dirname + '/..'), env, db, @@ -8,16 +9,23 @@ var path = require('path'), b_port, p2p_port; + +function getUserHome() { + return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; +} + +var home = process.env.INSIGHT_DB || ( getUserHome() + '/insight-api-db' ); + if (process.env.INSIGHT_NETWORK === 'livenet') { env = 'livenet'; - db = rootPath + '/db'; + db = home; port = '3000'; b_port = '8332'; p2p_port = '8333'; } else { env = 'testnet'; - db = rootPath + '/db/testnet'; + db = home + '/testnet'; port = '3001'; b_port = '18332'; p2p_port = '18333'; @@ -48,6 +56,13 @@ if (!dataDir) { } dataDir += network === 'testnet' ? 'testnet3' : ''; + +if (! fs.existsSync(db)){ + + console.log('## ERROR ##\n\tDB Directory "%s" not found. \n\tCreate it, move your old DB there or set the INSIGHT_DB environment variable.\n\tNOTE: In older insight-api versions, db was stored at /db', db); + process.exit(-1); +} + module.exports = { root: rootPath, publicPath: process.env.INSIGHT_PUBLIC_PATH || false, diff --git a/lib/TransactionDb.js b/lib/TransactionDb.js index a33bd195..e2db7dcb 100644 --- a/lib/TransactionDb.js +++ b/lib/TransactionDb.js @@ -30,6 +30,8 @@ var Rpc = imports.rpc || require('./Rpc'), async = require('async'), config = require('../config/config'), assert = require('assert'); + + var db = imports.db || levelup(config.leveldb + '/txs',{maxOpenFiles: MAX_OPEN_FILES} ); var Script = require('bitcore/Script'); // This is 0.1.2 = > c++ version of base57-native