refactor final polish
This commit is contained in:
parent
f7582586ba
commit
80d81a3bb5
67
README.md
67
README.md
|
@ -7,7 +7,11 @@
|
|||
|
||||
## 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
|
||||
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).
|
||||
|
||||
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].
|
||||
|
||||
|
||||
* **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.
|
||||
to remove the need of running Bitcoin Core separately. [More info](https://github.com/bitpay/bitcore-node/issues/57).
|
||||
|
||||
## Quick Install
|
||||
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:
|
||||
|
||||
$ node index.js
|
||||
$ npm start
|
||||
|
||||
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
|
||||
with the blockchain state, which may take some time. You can check
|
||||
sync progress at http://localhost:3001/api/sync.
|
||||
with the blockchain state, which will take some time. You can check
|
||||
sync progress at http://localhost:8080/v1/node.
|
||||
|
||||
|
||||
## 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:
|
||||
```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.
|
||||
# to start a livenet instance
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
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;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
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
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
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
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
BitcoreHTTP:
|
||||
port: 18080
|
||||
logging: true
|
||||
BitcoreNode:
|
||||
LevelUp: ./testnet-db
|
||||
network: testnet
|
||||
NetworkMonitor:
|
||||
host: localhost
|
||||
port: 18333
|
||||
Reporter: none # none, simple, matrix
|
||||
RPC:
|
||||
user: user
|
||||
pass: password
|
||||
|
|
26
index.js
26
index.js
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var BitcoreNode = require('./lib/node');
|
||||
var reporters = require('./lib/reporters');
|
||||
var BitcoreHTTP = require('./api/lib/http');
|
||||
var bitcore = require('bitcore');
|
||||
var Promise = require('bluebird');
|
||||
Promise.longStackTraces();
|
||||
|
@ -10,12 +10,12 @@ BitcoreNode.errors = require('./lib/errors');
|
|||
|
||||
if (require.main === module) {
|
||||
var config = require('config');
|
||||
var network = config.get('BitcoreNode').network;
|
||||
console.log('Starting bitcore-node', network, 'network');
|
||||
var nodeConfig = config.get('BitcoreHTTP.BitcoreNode');
|
||||
var httpConfig = config.get('BitcoreHTTP');
|
||||
var network = nodeConfig.network;
|
||||
console.log('Starting bitcore-node-http', network, 'network');
|
||||
bitcore.Networks.defaultNetwork = bitcore.Networks.get(network);
|
||||
|
||||
var node = BitcoreNode.create(config.get('BitcoreNode'));
|
||||
node.start();
|
||||
var node = BitcoreNode.create(nodeConfig);
|
||||
node.on('error', function(err) {
|
||||
if (err.code === 'ECONNREFUSED') {
|
||||
console.log('Connection to bitcoind failed');
|
||||
|
@ -27,14 +27,12 @@ if (require.main === module) {
|
|||
node.stop();
|
||||
process.exit();
|
||||
});
|
||||
|
||||
var reporterName = config.get('BitcoreNode.Reporter');
|
||||
var reporter = reporters[reporterName];
|
||||
if (!reporter) {
|
||||
throw new Error('Unrecognized network reporter: ' + reporterName +
|
||||
'. Available: ' + Object.keys(reporters));
|
||||
}
|
||||
node.on('Transaction', reporter);
|
||||
var http = new BitcoreHTTP(node, httpConfig);
|
||||
http.start()
|
||||
.catch(function(err) {
|
||||
http.stop();
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = BitcoreNode;
|
||||
|
|
Loading…
Reference in New Issue