From 17b1bf15abc8a1ab0b10f3e6c1e7117a59a6fbc3 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 17 Aug 2015 14:16:43 -0400 Subject: [PATCH] Start of module architecture and CLI for node configuration. --- README.md | 51 +++++++++++++++++++++++++++++++++++++----- cli/bitcore-node.js | 54 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 3 files changed, 101 insertions(+), 6 deletions(-) create mode 100755 cli/bitcore-node.js diff --git a/README.md b/README.md index 6f71a8d5..2e80207d 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,57 @@ Bitcore Node A Node.js module that adds a native interface to Bitcoin Core for querying information about the Bitcoin blockchain. Bindings are linked to Bitcoin Core compiled as a static library. -## Install +## Getting Started + +Bitcore Node includes a Command Line Interface (CLI) for managing, configuring and interfacing with your Bitcore Node. At the minimum, your node can function with all of the features from Bitcoin Core running as a full node. However you can enable additional features to make your node more useful such as exposing new APIs, adding new indexes for addresses, running a block explorer and more. + +Here is how you can you install and start your node: ```bash -git clone https://github.com/bitpay/bitcore-node.git -cd bitcore-node -npm install +npm install -g bitcore-node@0.2.0-beta.4 +bitcore-node create mynode "My Node" +cd mynode +bitcore-node start ``` -Note: For 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. This greatly speeds up the process of using this project. If you don't want to compile the project for yourself, then please skip down to "Example Usage" section for next steps. Please see detailed instructions below for complete build details and dependencies needed for installation if you choose to build the project from source. + +This will install bitcore-node globally and add a `bitcore-node` command to your path and will provide the functionality for configuring your full node, including adding additional features. + +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. If you want to compile the project yourself, then please see the [Build & Install](#build--install) for full detailed instructions to build the project from source. + +To install additional features, you can use the bitcore-node command "add": + +```bash +bitcore-node stop +bitcore-node add address +bitcore-node start +``` + +This will configure your node with the necessary modules, and create the proper configuration file necessary for running your node. The above example will add the address module bitcore-node, and will then start running on start. Please be aware that in some cases adding a module will mean that a reindex is required that will take several hours as each block is analyzed and a database is created. Any module that requires such will prompt before installation. + +Third party modules can also be specified by using a git repository: + +```bash +bitcore-node add https://github.com/yourname/helloworld +``` + +Please see the [directory](doc/modules.md) for a partial list of modules for Bitcore Node. If you're interested in developing a module, please see the [Module Development Guide](doc/modules-development.md). + +## Using your Node + +Your node should be able to respond to commands via a command line utility. For example, with the address module added, you should be able to query for unspent outputs for any address: + +```bash +bitcore-node call getunspentoutputs "1HTxCVrXuthad6YW5895K98XmVsdMvvBSw" +bitcore-node call getbalance "1HTxCVrXuthad6YW5895K98XmVsdMvvBSw" +bitcore-node call sendtransaction "" +bitcore-node call help +``` + +The above are a few common examples of commands that can be run, however there are many more. Every module that is added can extend the interface to include new commands. Running `bitcore-node call help` will list all of the available commands that can be run against your node. ## Build & Install -There are two main parts of the build, compiling Bitcoin Core as a static library and the Node.js bindings. +This includes a detailed instructions for compiling. There are two main parts of the build, compiling Bitcoin Core as a static library and the Node.js bindings. ### Ubuntu 14.04 (Unix/Linux) diff --git a/cli/bitcore-node.js b/cli/bitcore-node.js new file mode 100755 index 00000000..fd285967 --- /dev/null +++ b/cli/bitcore-node.js @@ -0,0 +1,54 @@ +'use strict'; + +var program = require('commander'); +var version = require(__dirname + '/../package.json').version; + +program + .version(version) + .option('-d, --datadir', 'Database and configuration directory') + .option('-t, --testnet', 'Enable testnet network'); + +program + .command('create [name]') + .description('Create a new node') + .action(function(directory, name){ + console.log(directory, name); + }); + +program + .command('add ') + .alias('install') + .description('Install a module for the current node') + .action(function(module){ + console.log(module); + }).on('--help', function() { + console.log(' Examples:'); + console.log(); + console.log(' $ bitcore-node add wallet-service'); + console.log(' $ bitcore-node add insight-api'); + console.log(); + }); + +program + .command('start') + .option('-b', '--background', 'Will start in the background') + .description('Start the current node') + .action(function(){ + console.log('start'); + }); + +program + .command('stop') + .description('Stop the current node') + .action(function(){ + console.log('stop'); + }); + +program + .command('*') + .description('') + .action(function(env){ + program.help(); + }); + +program.parse(process.argv); diff --git a/package.json b/package.json index 1c264d86..955eea47 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "author": "BitPay ", "version": "0.2.0-dev", "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": { @@ -46,6 +47,7 @@ "bindings": "^1.2.1", "bitcore": "^0.13.0", "chainlib": "^0.2.0", + "commander": "^2.8.1", "errno": "^0.1.2", "memdown": "^1.0.0", "mkdirp": "0.5.0",