refactor final polish
This commit is contained in:
parent
f7582586ba
commit
80d81a3bb5
67
README.md
67
README.md
|
@ -7,7 +7,11 @@
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* **Bitcoin Core** - Download and Install [Bitcoin Core](http://bitcoin.org/en/download)
|
* **Node.js v0.10.0-v0.12.x** - Download and Install [Node.js](http://www.nodejs.org/download/).
|
||||||
|
|
||||||
|
* **NPM** - Node.js package manager, should be automatically installed when you get node.js.
|
||||||
|
|
||||||
|
* **Fully-synced Bitcoin Core** - Download and Install [Bitcoin Core](http://bitcoin.org/en/download)
|
||||||
|
|
||||||
`bitcore-node` needs a trusted Bitcoin Core instance to run. It will connect to it
|
`bitcore-node` needs a trusted Bitcoin Core instance to run. It will connect to it
|
||||||
through the RPC API and bitcoin peer-to-peer protocol.
|
through the RPC API and bitcoin peer-to-peer protocol.
|
||||||
|
@ -18,12 +22,7 @@ bitcoin data directory (usually `~/.bitcoin` on Linux, `%appdata%\Bitcoin\` on W
|
||||||
or `~/Library/Application Support/Bitcoin` on Mac OS X).
|
or `~/Library/Application Support/Bitcoin` on Mac OS X).
|
||||||
|
|
||||||
Bitcoin Core must be running and fully synced before running `bitcore-node`. We're planning
|
Bitcoin Core must be running and fully synced before running `bitcore-node`. We're planning
|
||||||
to remove the need of running Bitcoin Core separately. (More info)[https://github.com/bitpay/bitcore-node/issues/57].
|
to remove the need of running Bitcoin Core separately. [More info](https://github.com/bitpay/bitcore-node/issues/57).
|
||||||
|
|
||||||
|
|
||||||
* **Node.js v0.10.x** - Download and Install [Node.js](http://www.nodejs.org/download/).
|
|
||||||
|
|
||||||
* **NPM** - Node.js package manager, should be automatically installed when you get node.js.
|
|
||||||
|
|
||||||
## Quick Install
|
## Quick Install
|
||||||
Check the Prerequisites section above before installing.
|
Check the Prerequisites section above before installing.
|
||||||
|
@ -38,29 +37,65 @@ to remove the need of running Bitcoin Core separately. (More info)[https://githu
|
||||||
|
|
||||||
Run the main application:
|
Run the main application:
|
||||||
|
|
||||||
$ node index.js
|
$ npm start
|
||||||
|
|
||||||
Then open a browser and go to:
|
Then open a browser and go to:
|
||||||
|
|
||||||
http://localhost:3001
|
http://localhost:8080
|
||||||
|
|
||||||
Please note that the app will need to sync its internal database
|
Please note that the app will need to sync its internal database
|
||||||
with the blockchain state, which may take some time. You can check
|
with the blockchain state, which will take some time. You can check
|
||||||
sync progress at http://localhost:3001/api/sync.
|
sync progress at http://localhost:8080/v1/node.
|
||||||
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
`bitcore-node` is configured using [yaml](http://en.wikipedia.org/wiki/YAML) files. The application defaults are in the [config](config/) folder.
|
`bitcore-node` is configured using [yaml](http://en.wikipedia.org/wiki/YAML) files.
|
||||||
|
The application defaults are in the [api/config/](api/config/) folder.
|
||||||
|
|
||||||
Make sure that bitcoind is configured to [accept incoming connections using 'rpcallowip'](https://en.bitcoin.it/wiki/Running_Bitcoin).
|
To run the app with different configurations, simply do:
|
||||||
|
```sh
|
||||||
|
# to start a testnet instance
|
||||||
|
NODE_ENV=testnet npm start
|
||||||
|
|
||||||
In case the network is changed (testnet to livenet or vice versa) levelDB database needs to be deleted. This can be performed running:
|
# to start a livenet instance
|
||||||
```util/sync.js -D``` and waiting for `bitcore-node` to synchronize again. Once the database is deleted, the sync.js process can be safely interrupted (CTRL+C) and continued from the synchronization process embedded in main app.
|
NODE_ENV=livenet npm start
|
||||||
|
|
||||||
|
# start a custom configuration instance (will usee foo.yml)
|
||||||
|
NODE_ENV=foo npm start
|
||||||
|
$
|
||||||
|
```
|
||||||
|
|
||||||
|
A sample configuration file would be:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Sample configuration file with defaults for livenet
|
||||||
|
BitcoreHTTP:
|
||||||
|
port: 8080 # http api port
|
||||||
|
logging: true # enables request logging
|
||||||
|
BitcoreNode:
|
||||||
|
LevelUp: ./db # path to database location
|
||||||
|
network: livenet # bitcoin network (livenet, testnet)
|
||||||
|
NetworkMonitor:
|
||||||
|
host: localhost # p2p host
|
||||||
|
port: 8333 # p2p port
|
||||||
|
RPC:
|
||||||
|
host: 127.0.0.1 # rpc ip
|
||||||
|
port: 8332 # rpc port
|
||||||
|
user: user # rpc username
|
||||||
|
pass: password # rpc password
|
||||||
|
protocol: http #http, https
|
||||||
|
#rejectUnauthorized: false
|
||||||
|
#disableAgent: true
|
||||||
|
```
|
||||||
|
|
||||||
## Synchronization
|
## Synchronization
|
||||||
|
|
||||||
The initial synchronization process scans the blockchain from the paired bitcoind server to update addresses and balances. `bitcore-node` needs exactly one trusted bitcoind node to run. This node must have finished downloading the blockchain before running `bitcore-node`.
|
The initial synchronization process scans the blockchain from the paired
|
||||||
|
Bitcoin Core node to update addresses and balances. `bitcore-node` needs exactly one
|
||||||
|
trusted bitcoind node to run.
|
||||||
|
[There are plans to expand this to more than one](https://github.com/bitpay/bitcore-node/issues/58).
|
||||||
|
Bitcoin core must have finished downloading the blockchain before running `bitcore-node`.
|
||||||
|
|
||||||
While `bitcore-node` 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.
|
While `bitcore-node` 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.
|
||||||
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
BitcoreHTTP:
|
|
||||||
port: 8080
|
|
||||||
logging: true
|
|
||||||
BitcoreNode:
|
|
||||||
LevelUp: ./db
|
|
||||||
network: livenet
|
|
||||||
NetworkMonitor:
|
|
||||||
host: localhost
|
|
||||||
port: 8333
|
|
||||||
Reporter: none # none, simple, matrix
|
|
||||||
RPC:
|
|
||||||
user: user
|
|
||||||
pass: password
|
|
||||||
protocol: http #http, https
|
|
||||||
#rejectUnauthorized: false
|
|
||||||
#disableAgent: true
|
|
||||||
host: 127.0.0.1
|
|
||||||
port: 8332
|
|
|
@ -1,16 +0,0 @@
|
||||||
BitcoreHTTP:
|
|
||||||
port: 8080
|
|
||||||
logging: true
|
|
||||||
BitcoreNode:
|
|
||||||
LevelUp: ./db
|
|
||||||
network: livenet
|
|
||||||
NetworkMonitor:
|
|
||||||
host: localhost
|
|
||||||
port: 8333
|
|
||||||
Reporter: none # none, simple, matrix
|
|
||||||
RPC:
|
|
||||||
user: user
|
|
||||||
pass: password
|
|
||||||
protocol: http
|
|
||||||
host: 127.0.0.1
|
|
||||||
port: 8332
|
|
|
@ -1,16 +0,0 @@
|
||||||
BitcoreHTTP:
|
|
||||||
port: 8080
|
|
||||||
logging: true
|
|
||||||
BitcoreNode:
|
|
||||||
LevelUp: ./testnet-db
|
|
||||||
network: testnet
|
|
||||||
NetworkMonitor:
|
|
||||||
host: localhost
|
|
||||||
port: 18333
|
|
||||||
Reporter: none # none, simple, matrix
|
|
||||||
RPC:
|
|
||||||
user: user
|
|
||||||
pass: password
|
|
||||||
protocol: http
|
|
||||||
host: 127.0.0.1
|
|
||||||
port: 18332
|
|
15
api/index.js
15
api/index.js
|
@ -1,19 +1,4 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var BitcoreHTTP = require('./lib/http');
|
var BitcoreHTTP = require('./lib/http');
|
||||||
var bitcore = require('bitcore');
|
|
||||||
|
|
||||||
if (require.main === module) {
|
|
||||||
var config = require('config');
|
|
||||||
var network = config.get('BitcoreHTTP.BitcoreNode').network;
|
|
||||||
console.log('Starting bitcore-node-http', network, 'network');
|
|
||||||
bitcore.Networks.defaultNetwork = bitcore.Networks.get(network);
|
|
||||||
var http = BitcoreHTTP.create(config.get('BitcoreHTTP'));
|
|
||||||
http.start()
|
|
||||||
.catch(function(err) {
|
|
||||||
http.stop();
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = BitcoreHTTP;
|
module.exports = BitcoreHTTP;
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
BitcoreNode:
|
BitcoreHTTP:
|
||||||
LevelUp: ./db
|
port: 8080
|
||||||
network: livenet
|
logging: true
|
||||||
NetworkMonitor:
|
BitcoreNode:
|
||||||
host: localhost
|
LevelUp: ./db
|
||||||
port: 8333
|
network: livenet
|
||||||
Reporter: none # none, simple, matrix
|
NetworkMonitor:
|
||||||
RPC:
|
host: localhost
|
||||||
user: user
|
port: 8333
|
||||||
pass: password
|
RPC:
|
||||||
protocol: http # http, https
|
user: user
|
||||||
#rejectUnauthorized: false
|
pass: password
|
||||||
#disableAgent: true
|
protocol: http #http, https
|
||||||
host: 127.0.0.1
|
#rejectUnauthorized: false
|
||||||
port: 8332
|
#disableAgent: true
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 8332
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
BitcoreNode:
|
BitcoreHTTP:
|
||||||
LevelUp: ./db
|
port: 8080
|
||||||
network: livenet
|
logging: true
|
||||||
NetworkMonitor:
|
BitcoreNode:
|
||||||
host: localhost
|
LevelUp: ./db
|
||||||
port: 8333
|
network: livenet
|
||||||
Reporter: none # none, simple, matrix
|
NetworkMonitor:
|
||||||
RPC:
|
host: localhost
|
||||||
user: user
|
port: 8333
|
||||||
pass: password
|
RPC:
|
||||||
protocol: http
|
user: user
|
||||||
host: 127.0.0.1
|
pass: password
|
||||||
port: 8332
|
protocol: http
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 8332
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
BitcoreNode:
|
BitcoreHTTP:
|
||||||
LevelUp: ./testnet-db
|
port: 18080
|
||||||
network: testnet
|
logging: true
|
||||||
NetworkMonitor:
|
BitcoreNode:
|
||||||
host: localhost
|
LevelUp: ./testnet-db
|
||||||
port: 18333
|
network: testnet
|
||||||
Reporter: none # none, simple, matrix
|
NetworkMonitor:
|
||||||
RPC:
|
host: localhost
|
||||||
user: user
|
port: 18333
|
||||||
pass: password
|
RPC:
|
||||||
protocol: http
|
user: user
|
||||||
host: 127.0.0.1
|
pass: password
|
||||||
port: 18332
|
protocol: http
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 18332
|
||||||
|
|
26
index.js
26
index.js
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var BitcoreNode = require('./lib/node');
|
var BitcoreNode = require('./lib/node');
|
||||||
var reporters = require('./lib/reporters');
|
var BitcoreHTTP = require('./api/lib/http');
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
Promise.longStackTraces();
|
Promise.longStackTraces();
|
||||||
|
@ -10,12 +10,12 @@ BitcoreNode.errors = require('./lib/errors');
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
var config = require('config');
|
var config = require('config');
|
||||||
var network = config.get('BitcoreNode').network;
|
var nodeConfig = config.get('BitcoreHTTP.BitcoreNode');
|
||||||
console.log('Starting bitcore-node', network, 'network');
|
var httpConfig = config.get('BitcoreHTTP');
|
||||||
|
var network = nodeConfig.network;
|
||||||
|
console.log('Starting bitcore-node-http', network, 'network');
|
||||||
bitcore.Networks.defaultNetwork = bitcore.Networks.get(network);
|
bitcore.Networks.defaultNetwork = bitcore.Networks.get(network);
|
||||||
|
var node = BitcoreNode.create(nodeConfig);
|
||||||
var node = BitcoreNode.create(config.get('BitcoreNode'));
|
|
||||||
node.start();
|
|
||||||
node.on('error', function(err) {
|
node.on('error', function(err) {
|
||||||
if (err.code === 'ECONNREFUSED') {
|
if (err.code === 'ECONNREFUSED') {
|
||||||
console.log('Connection to bitcoind failed');
|
console.log('Connection to bitcoind failed');
|
||||||
|
@ -27,14 +27,12 @@ if (require.main === module) {
|
||||||
node.stop();
|
node.stop();
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
|
var http = new BitcoreHTTP(node, httpConfig);
|
||||||
var reporterName = config.get('BitcoreNode.Reporter');
|
http.start()
|
||||||
var reporter = reporters[reporterName];
|
.catch(function(err) {
|
||||||
if (!reporter) {
|
http.stop();
|
||||||
throw new Error('Unrecognized network reporter: ' + reporterName +
|
throw err;
|
||||||
'. Available: ' + Object.keys(reporters));
|
});
|
||||||
}
|
|
||||||
node.on('Transaction', reporter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = BitcoreNode;
|
module.exports = BitcoreNode;
|
||||||
|
|
Loading…
Reference in New Issue