diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..f070f6e4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: +- '0.10' +install: npm install diff --git a/README.md b/README.md index a1a4ff09..7d81e386 100644 --- a/README.md +++ b/README.md @@ -99,9 +99,9 @@ In case the network is changed (testnet to livenet or vice versa) levelDB databa The initial synchronization process scans the blockchain from the paired bitcoind server to update addresses and balances. *insight* needs one (and only one) trusted bitcoind node to run. This node must have finished downloading the blockchain before running *insight*. -While *insight* is synchronizing the website can be accessed (the sync process is embedded in the webserver), but there may be missing data or incorrect balances for addresses. The 'sync' status is shown on the top-right of all pages. +While *insight* is synchronizing the website can be accessed (the sync process is embedded in the webserver), but there may be missing data or incorrect balances for addresses. The 'sync' status is shown at the `/api/sync` endpoint. -The blockchain can be read from bitcoind's raw `.dat` files or RPC interface. Reading the information from the `.dat` files is much faster so it's the recommended (and default) alternative. `.dat` files are scanned in the default location for each platform. In case a non-standard location is used, it needs to be defined (see the Configuration section). The synchronization type being used can be seen at the [Status page](http://localhost:3001/status). As of June 2014, using `.dat` files the sync process takes 9 hrs. for livenet and 30 mins. for testnet. +The blockchain can be read from bitcoind's raw `.dat` files or RPC interface. Reading the information from the `.dat` files is much faster so it's the recommended (and default) alternative. `.dat` files are scanned in the default location for each platform (for example, `~/.bitcoin` on Linux). In case a non-standard location is used, it needs to be defined (see the Configuration section). As of June 2014, using `.dat` files the sync process takes 9 hrs. for livenet and 30 mins. for testnet. While synchronizing the blockchain, *insight* listens for new blocks and transactions relayed by the bitcoind node. Those are also stored on *insight*'s database. In case *insight* is shutdown for a period of time, restarting it will trigger a partial (historic) synchronization of the blockchain. Depending on the size of that synchronization task, a reverse RPC or forward `.dat` syncing strategy will be used. @@ -121,7 +121,7 @@ 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``` + ```~/.insight/``` Please note that previous version's of Insight-API store that on `/db` this can be changed on config/config.js. As of June 2014, storing the livenet blockchain takes ~35GB of disk space (2GB for the testnet). @@ -137,7 +137,7 @@ To run the tests ```$ grunt test``` -Contributions and suggestions are welcomed at [insight-api github repository](https://github.com/bitpay/insight-api). +Contributions and suggestions are welcome at [insight-api github repository](https://github.com/bitpay/insight-api). ## API @@ -170,23 +170,23 @@ Sample return: ``` json [ { - address: "n2PuaAguxZqLddRbTnAoAuwKYgN2w2hZk7", - txid: "dbfdc2a0d22a8282c4e7be0452d595695f3a39173bed4f48e590877382b112fc", - vout: 0, - ts: 1401276201, - scriptPubKey: "76a914e50575162795cd77366fb80d728e3216bd52deac88ac", - amount: 0.001, - confirmations: 3 + address: "n2PuaAguxZqLddRbTnAoAuwKYgN2w2hZk7", + txid: "dbfdc2a0d22a8282c4e7be0452d595695f3a39173bed4f48e590877382b112fc", + vout: 0, + ts: 1401276201, + scriptPubKey: "76a914e50575162795cd77366fb80d728e3216bd52deac88ac", + amount: 0.001, + confirmations: 3 }, { - address: "n2PuaAguxZqLddRbTnAoAuwKYgN2w2hZk7", - txid: "e2b82af55d64f12fd0dd075d0922ee7d6a300f58fe60a23cbb5831b31d1d58b4", - vout: 0, - ts: 1401226410, - scriptPubKey: "76a914e50575162795cd77366fb80d728e3216bd52deac88ac", - amount: 0.001, - confirmation: 6 - confirmationsFromCache: true, + address: "n2PuaAguxZqLddRbTnAoAuwKYgN2w2hZk7", + txid: "e2b82af55d64f12fd0dd075d0922ee7d6a300f58fe60a23cbb5831b31d1d58b4", + vout: 0, + ts: 1401226410, + scriptPubKey: "76a914e50575162795cd77366fb80d728e3216bd52deac88ac", + amount: 0.001, + confirmation: 6 + confirmationsFromCache: true, } ] ``` diff --git a/config/config.js b/config/config.js index 48d359a1..c6bd673e 100644 --- a/config/config.js +++ b/config/config.js @@ -1,23 +1,23 @@ 'use strict'; var path = require('path'), - fs = require('fs'), - rootPath = path.normalize(__dirname + '/..'), - env, - db, - port, - b_port, - p2p_port; + fs = require('fs'), + rootPath = path.normalize(__dirname + '/..'), + env, + db, + port, + b_port, + p2p_port; var packageStr = fs.readFileSync('package.json'); var version = JSON.parse(packageStr).version; function getUserHome() { - return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; + return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; } -var home = process.env.INSIGHT_DB || ( getUserHome() + '/.insight' ); +var home = process.env.INSIGHT_DB || (getUserHome() + '/.insight'); if (process.env.INSIGHT_NETWORK === 'livenet') { env = 'livenet'; @@ -25,8 +25,7 @@ if (process.env.INSIGHT_NETWORK === 'livenet') { port = '3000'; b_port = '8332'; p2p_port = '8333'; -} -else { +} else { env = 'testnet'; db = home + '/testnet'; port = '3001'; @@ -35,7 +34,7 @@ else { } -switch(process.env.NODE_ENV) { +switch (process.env.NODE_ENV) { case 'production': env += ''; break; @@ -61,11 +60,11 @@ if (!dataDir) { dataDir += network === 'testnet' ? 'testnet3' : ''; var safeConfirmations = process.env.INSIGHT_SAFE_CONFIRMATIONS || 6; -var ignoreCache = process.env.INSIGHT_IGNORE_CACHE || 0; +var ignoreCache = process.env.INSIGHT_IGNORE_CACHE || 0; var bitcoindConf = { - protocol: process.env.BITCOIND_PROTO || 'http', + protocol: process.env.BITCOIND_PROTO || 'http', user: process.env.BITCOIND_USER || 'user', pass: process.env.BITCOIND_PASS || 'pass', host: process.env.BITCOIND_HOST || '127.0.0.1', @@ -79,7 +78,7 @@ var bitcoindConf = { /*jshint multistr: true */ console.log( -'\n\ + '\n\ ____ _ __ __ ___ _ \n\ / _/___ _____(_)___ _/ /_ / /_ / | ____ (_)\n\ / // __ \\/ ___/ / __ `/ __ \\/ __/ / /\| \| / __ \\/ / \n\ @@ -104,23 +103,26 @@ console.log( \nChange setting by assigning the enviroment variables in the last column. Example:\n\ $ INSIGHT_NETWORK="testnet" BITCOIND_HOST="123.123.123.123" ./insight.js\ \n\n', -version, -network, home, safeConfirmations, ignoreCache?'yes':'no', -bitcoindConf.user, -bitcoindConf.pass?'Yes(hidden)':'No', -bitcoindConf.protocol, -bitcoindConf.host, -bitcoindConf.port, -bitcoindConf.p2pPort, -dataDir+(network==='testnet'?'*':''), -(network==='testnet'?'* (/testnet3 is added automatically)':'') + version, + network, home, safeConfirmations, ignoreCache ? 'yes' : 'no', + bitcoindConf.user, + bitcoindConf.pass ? 'Yes(hidden)' : 'No', + bitcoindConf.protocol, + bitcoindConf.host, + bitcoindConf.port, + bitcoindConf.p2pPort, + dataDir + (network === 'testnet' ? '*' : ''), (network === 'testnet' ? '* (/testnet3 is added automatically)' : '') ); -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); +if (!fs.existsSync(db)) { + var err = fs.mkdirSync(db); + if (err) { + console.log(err); + console.log("## ERROR! Can't create insight directory! \n"); + console.log('\tPlease create it manually: ', db); + process.exit(-1); + } } module.exports = { @@ -130,7 +132,7 @@ module.exports = { apiPrefix: '/api', port: port, leveldb: db, - bitcoind: bitcoindConf, + bitcoind: bitcoindConf, network: network, disableP2pSync: false, disableHistoricSync: false,