Merge pull request #323 from braydonf/lib

bitcore -> bitcore-lib
This commit is contained in:
Stephen Pair 2015-10-18 17:59:17 -04:00
commit e9110ad93c
31 changed files with 180 additions and 101 deletions

View File

@ -6,7 +6,7 @@ A Bitcoin full node for building applications and services with Node.js. A node
## Install
```bash
npm install -g bitcore-node@latest
npm install -g bitcore-node
bitcore-node start
```
@ -16,15 +16,15 @@ Note: For your convenience, we distribute binaries for x86_64 Linux and x86_64 M
- Node.js v0.12
- ~100GB of disk storage
- ~1GB of RAM
- ~4GB of RAM
- Mac OS X >= 10.9, Ubuntu >= 12.04 (libc >= 2.15 and libstdc++ >= 6.0.16)
## Configuration
Bitcore Node includes a Command Line Interface (CLI) for managing, configuring and interfacing with your Bitcore Node.
Bitcore includes a Command Line Interface (CLI) for managing, configuring and interfacing with your Bitcore Node.
```bash
bitcore-node create -d <bitcoin-data-dir> mynode "My Node"
bitcore-node create -d <bitcoin-data-dir> mynode
cd mynode
bitcore-node add <service>
bitcore-node add https://github.com/yourname/helloworld
@ -40,10 +40,11 @@ bitcore-node start --daemon
## Add-on Services
There are several add-on services available to extend the functionality of Bitcore Node:
There are several add-on services available to extend the functionality of Bitcore:
- [Insight API](https://github.com/bitpay/insight-api/tree/v0.3.0)
- [Insight UI](https://github.com/bitpay/insight/tree/v0.3.0)
- [Bitcore Wallet Service](https://github.com/bitpay/bitcore-wallet-service)
## Documentation

View File

@ -3,7 +3,7 @@
var benchmark = require('benchmark');
var async = require('async');
var sinon = require('sinon');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var Block = bitcore.Block;
var AddressService = require('../lib/services/address');
var maxTime = 20;

5
bin/bitcore-node Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env node
// vi: ft=javascript -*- mode: JavaScript; -*-
var node = require('..');
node.cli.bitcore();

View File

@ -1,44 +0,0 @@
#!/usr/bin/env node
'use strict';
var semver = require('semver');
var Liftoff = require('liftoff');
var cliPackage = require('../package.json');
var liftoff = new Liftoff({
name: 'bitcore-node',
moduleName: 'bitcore-node',
configName: 'bitcore-node',
processTitle: 'bitcore-node'
}).on('require', function (name, module) {
console.log('Loading:', name);
}).on('requireFail', function (name, err) {
console.log('Unable to load:', name, err);
}).on('respawn', function (flags, child) {
console.log('Detected node flags:', flags);
console.log('Respawned to PID:', child.pid);
});
liftoff.launch({
cwd: process.cwd()
}, function(env){
var bitcorenode;
if (env.modulePackage && env.configPath) {
// use the local version
if (semver.gt(cliPackage.version, env.modulePackage.version)) {
throw new Error(
'Version mismatch, global bitcore-node is ' + cliPackage.version +
' and local bitcore-node is ' + env.modulePackage.version
);
}
bitcorenode = require(env.modulePath);
} else {
// use the global version
bitcorenode = require('..');
}
bitcorenode.cli.main();
});

View File

@ -6,8 +6,8 @@ A Bitcoin full node for building applications and services with Node.js. A node
## Install
```bash
npm install -g bitcore-node@latest
bitcore-node start
npm install -g bitcore
bitcore start
```
Note: For your convenience, we distribute binaries for x86_64 Linux and x86_64 Mac OS X. Upon npm install, the binaries for your platform will be downloaded. For more detailed installation instructions, or if you want to compile the project yourself, then please see the [Build & Install](build.md) documentation to build the project from source.
@ -16,26 +16,26 @@ Note: For your convenience, we distribute binaries for x86_64 Linux and x86_64 M
- Node.js v0.12
- ~100GB of disk storage
- ~1GB of RAM
- ~4GB of RAM
- Mac OS X >= 10.9, Ubuntu >= 12.04 (libc >= 2.15 and libstdc++ >= 6.0.16)
## Configuration
Bitcore Node includes a Command Line Interface (CLI) for managing, configuring and interfacing with your Bitcore Node.
Bitcore includes a Command Line Interface (CLI) for managing, configuring and interfacing with your Bitcore Node.
```bash
bitcore-node create -d <bitcoin-data-dir> mynode "My Node"
bitcore create -d <bitcoin-data-dir> mynode
cd mynode
bitcore-node add <service>
bitcore-node add https://github.com/yourname/helloworld
bitcore install <service>
bitcore install https://github.com/yourname/helloworld
```
This will create a directory with configuration files for your node and install the necessary dependencies. For more information about (and developing) services, please see the [Service Documentation](services.md).
To start bitcore-node as a daemon:
To start bitcore as a daemon:
```bash
bitcore-node start --daemon
bitcore start --daemon
```
## Add-on Services

View File

@ -6,11 +6,7 @@ description: Description of functions for Bitcore Node configuration
A collection of functions for creating, managing, starting, stopping and interacting with a Bitcore Node.
## Create
This function will create a new directory and the initial configuration files/directories, including 'bitcore-node.json', 'package.json', 'bitcoin.conf', install the necessary Node.js modules, and create a data directory.
## Add
## Install
This function will add a service to a node by installing the necessary dependencies and modifying the `bitcore-node.json` configuration.
@ -26,7 +22,7 @@ This function will recursively find a configuration `bitcore-node.json` file in
This function will return a default configuration with the default services based on environment variables, and will default to using the standard `~/.bitcoin` data directory.
## Remove
## Uninstall
This function will remove a service from a node by uninstalling the necessary dependencies and modifying the `bitcore-node.json` configuration.

View File

@ -28,7 +28,7 @@ Services correspond with a Node.js module as described in 'package.json', for ex
```json
{
"dependencies": {
"bitcore": "^0.13.1",
"bitcore-lib": "^0.13.7",
"bitcore-node": "^0.2.0",
"insight-api": "^3.0.0"
}
@ -47,8 +47,8 @@ var bitcore = require('bitcore-node');
//Services
var Address = bitcore.services.Address;
var Bitcoin = bitcore.services.Bitcoin;
var DB = bitcore.services.DB;
var Web = bitcore.services.Web;
var DB = bitcore.services.DB;
var Web = bitcore.services.Web;
var myNode = new bitcore.Node({
datadir: '~/.bitcore',

View File

@ -22,4 +22,7 @@ module.exports.scaffold.findConfig = require('./lib/scaffold/find-config');
module.exports.scaffold.defaultConfig = require('./lib/scaffold/default-config');
module.exports.cli = {};
module.exports.cli.main = require('./cli/main');
module.exports.cli.main = require('./lib/cli/main');
module.exports.cli.daemon = require('./lib/cli/daemon');
module.exports.cli.bitcore = require('./lib/cli/bitcore');
module.exports.cli.bitcored = require('./lib/cli/bitcored');

View File

@ -11,7 +11,7 @@ var p2p = require('bitcore-p2p');
var Peer = p2p.Peer;
var Messages = p2p.Messages;
var chai = require('chai');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var Transaction = bitcore.Transaction;
var BN = bitcore.crypto.BN;
var async = require('async');

View File

@ -16,7 +16,7 @@ if (process.env.BITCORENODE_ENV !== 'test') {
}
var chai = require('chai');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var rimraf = require('rimraf');
var node;

View File

@ -14,7 +14,7 @@ if (process.env.BITCORENODE_ENV !== 'test') {
}
var chai = require('chai');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var BN = bitcore.crypto.BN;
var async = require('async');
var rimraf = require('rimraf');

40
lib/cli/bitcore.js Normal file
View File

@ -0,0 +1,40 @@
'use strict';
var Liftoff = require('liftoff');
function main() {
var liftoff = new Liftoff({
name: 'bitcore',
moduleName: 'bitcore-node',
configName: 'bitcore-node',
processTitle: 'bitcore'
}).on('require', function (name, module) {
console.log('Loading:', name);
}).on('requireFail', function (name, err) {
console.log('Unable to load:', name, err);
}).on('respawn', function (flags, child) {
console.log('Detected node flags:', flags);
console.log('Respawned to PID:', child.pid);
});
liftoff.launch({
cwd: process.cwd()
}, function(env){
var node;
if (env.modulePackage && env.configPath) {
// use the configured version
node = require(env.modulePath);
} else {
// use this version
node = require('..');
}
node.cli.main();
});
}
module.exports = main;

40
lib/cli/bitcored.js Normal file
View File

@ -0,0 +1,40 @@
'use strict';
var Liftoff = require('liftoff');
function main() {
var liftoff = new Liftoff({
name: 'bitcored',
moduleName: 'bitcore-node',
configName: 'bitcore-node',
processTitle: 'bitcored'
}).on('require', function (name, module) {
console.log('Loading:', name);
}).on('requireFail', function (name, err) {
console.log('Unable to load:', name, err);
}).on('respawn', function (flags, child) {
console.log('Detected node flags:', flags);
console.log('Respawned to PID:', child.pid);
});
liftoff.launch({
cwd: process.cwd()
}, function(env){
var node;
if (env.modulePackage && env.configPath) {
// use the configured version
node = require(env.modulePath);
} else {
// use this version
node = require('..');
}
node.cli.daemon();
});
}
module.exports = main;

36
lib/cli/daemon.js Normal file
View File

@ -0,0 +1,36 @@
'use strict';
var program = require('commander');
var path = require('path');
var bitcore = require('..');
function main() {
/* jshint maxstatements: 100 */
var version = bitcore.version;
var start = bitcore.scaffold.start;
var findConfig = bitcore.scaffold.findConfig;
var defaultConfig = bitcore.scaffold.defaultConfig;
program
.version(version)
.description('Start the current node')
.option('-c, --config <dir>', 'Specify the directory with Bitcore Node configuration')
.option('-d, --daemon', 'Make bitcore a daemon (running in the background)');
program.parse(process.argv);
if (program.config) {
program.config = path.resolve(process.cwd(), program.config);
}
var configInfo = findConfig(program.config || process.cwd());
if (!configInfo) {
configInfo = defaultConfig();
}
if(program.daemon) {
configInfo.config.daemon = true;
}
start(configInfo);
}
module.exports = main;

View File

@ -20,17 +20,18 @@ function main() {
.version(version);
program
.command('create <directory> [name]')
.command('create <directory>')
.description('Create a new node')
.option('-d, --datadir <dir>', 'Specify the bitcoin database directory')
.action(function(dirname, name, cmd){
.action(function(dirname, cmd){
console.log('dirname', dirname);
console.log('cmd', cmd);
if (cmd.datadir) {
cmd.datadir = path.resolve(process.cwd(), cmd.datadir);
}
var opts = {
cwd: process.cwd(),
dirname: dirname,
name: name,
datadir: cmd.datadir || './data',
isGlobal: false
};
@ -62,8 +63,8 @@ function main() {
});
program
.command('add <services...>')
.alias('install')
.command('install <services...>')
.alias('add')
.description('Install a service for the current node')
.action(function(services){
var configInfo = findConfig(process.cwd());
@ -89,8 +90,8 @@ function main() {
});
program
.command('remove <services...>')
.alias('uninstall')
.command('uninstall <services...>')
.alias('remove')
.description('Uninstall a service for the current node')
.action(function(services){
var configInfo = findConfig(process.cwd());

View File

@ -3,7 +3,7 @@
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var async = require('async');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var Networks = bitcore.Networks;
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;

View File

@ -4,7 +4,7 @@ var async = require('async');
var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;

View File

@ -1,7 +1,7 @@
'use strict';
var spawn = require('child_process').spawn;
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var async = require('async');
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;

View File

@ -1,6 +1,6 @@
'use strict';
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;
var path = require('path');

View File

@ -5,7 +5,7 @@ var fs = require('fs');
var npm = require('npm');
var path = require('path');
var spawn = require('child_process').spawn;
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;

View File

@ -3,7 +3,7 @@
var path = require('path');
var BitcoreNode = require('../node');
var index = require('../');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var _ = bitcore.deps._;
var $ = bitcore.util.preconditions;
var log = index.log;

View File

@ -1,6 +1,6 @@
'use strict';
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var async = require('async');
var _ = bitcore.deps._;
@ -228,7 +228,7 @@ AddressHistory.prototype.getDetailedInfo = function(txInfo, next) {
height: transaction.__height,
confirmations: self.getConfirmationsDetail(transaction),
timestamp: transaction.__timestamp,
// TODO bitcore should return null instead of throwing error on coinbase
// TODO bitcore-lib should return null instead of throwing error on coinbase
fees: !transaction.isCoinbase() ? transaction.getFee() : null,
tx: transaction
});

View File

@ -7,7 +7,7 @@ var index = require('../../');
var log = index.log;
var errors = index.errors;
var Transaction = require('../../transaction');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var levelup = require('levelup');
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;

View File

@ -4,7 +4,7 @@ var fs = require('fs');
var util = require('util');
var bindings = require('bindings')('bitcoind.node');
var mkdirp = require('mkdirp');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var $ = bitcore.util.preconditions;
var index = require('../');
var log = index.log;

View File

@ -6,7 +6,7 @@ var async = require('async');
var levelup = require('levelup');
var leveldown = require('leveldown');
var mkdirp = require('mkdirp');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var BufferUtil = bitcore.util.buffer;
var Networks = bitcore.Networks;
var Block = bitcore.Block;

View File

@ -2,7 +2,7 @@
var async = require('async');
var levelup = require('levelup');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var Transaction = bitcore.Transaction;
Transaction.prototype.populateInputs = function(db, poolTransactions, callback) {

View File

@ -5,7 +5,6 @@
"version": "0.2.0-dev",
"lastBuild": "0.2.0-beta.11",
"main": "./index.js",
"bin": "./cli/bitcore-node.js",
"repository": "git://github.com/bitpay/bitcore-node.git",
"homepage": "https://github.com/bitpay/bitcore-node.js",
"bugs": {
@ -28,6 +27,9 @@
"email": "patrick@bitpay.com"
}
],
"bin": {
"bitcore-node": "./bin/bitcore-node"
},
"scripts": {
"install": "./bin/install",
"build": "./bin/build",
@ -46,7 +48,7 @@
"dependencies": {
"async": "^1.3.0",
"bindings": "^1.2.1",
"bitcore": "^0.13.0",
"bitcore-lib": "^0.13.7",
"body-parser": "^1.13.3",
"colors": "^1.1.2",
"commander": "^2.8.1",
@ -54,7 +56,7 @@
"express": "^4.13.3",
"leveldown": "^1.4.1",
"levelup": "^1.2.1",
"liftoff": "^2.1.0",
"liftoff": "^2.2.0",
"memdown": "^1.0.0",
"mkdirp": "0.5.0",
"nan": "^2.0.9",
@ -73,7 +75,7 @@
"proxyquire": "^1.3.1",
"rimraf": "^2.4.2",
"sinon": "^1.15.4",
"bitcore-p2p": "^0.15.1"
"bitcore-p2p": "~1.0.0"
},
"engines": {
"node": ">=0.12.0"

View File

@ -2,7 +2,7 @@
var should = require('chai').should();
var sinon = require('sinon');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var Networks = bitcore.Networks;
var proxyquire = require('proxyquire');
var util = require('util');

View File

@ -94,7 +94,7 @@ describe('#add', function() {
var callCount = 0;
var oldPackage = {
dependencies: {
'bitcore': '^v0.13.1',
'bitcore-lib': '^v0.13.7',
'bitcore-node': '^v0.2.0'
}
};

View File

@ -6,7 +6,7 @@ var proxyquire = require('proxyquire');
var bitcorenode = require('../../../');
var AddressService = bitcorenode.services.Address;
var blockData = require('../../data/livenet-345003.json');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var Script = bitcore.Script;
var Address = bitcore.Address;
var Networks = bitcore.Networks;

View File

@ -7,18 +7,17 @@ var proxyquire = require('proxyquire');
var index = require('../../');
var DB = index.services.DB;
var blockData = require('../data/livenet-345003.json');
var bitcore = require('bitcore');
var bitcore = require('bitcore-lib');
var Networks = bitcore.Networks;
var Block = bitcore.Block;
var BufferUtil = bitcore.util.buffer;
var Transaction = bitcore.Transaction;
var transactionData = require('../data/bitcoin-transactions.json');
var chainHashes = require('../data/hashes.json');
var chainData = require('../data/testnet-blocks.json');
var errors = index.errors;
var memdown = require('memdown');
var levelup = require('levelup');
var bitcore = require('bitcore');
var Transaction = bitcore.Transaction;
describe('DB Service', function() {