Merge pull request #142 from maraoz/improve/setup

Improve setup
This commit is contained in:
Matias Alejo Garcia 2014-07-30 09:48:38 -03:00
commit eaedda5aa6
3 changed files with 55 additions and 49 deletions

4
.travis.yml Normal file
View File

@ -0,0 +1,4 @@
language: node_js
node_js:
- '0.10'
install: npm install

View File

@ -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
```<user's home>/db```
```~/.insight/```
Please note that previous version's of Insight-API store that on `<insight's root>/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

View File

@ -17,7 +17,7 @@ function getUserHome() {
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;
@ -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 <insight-root>/db', db);
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 = {