bitcore-node-zcash/README.md

113 lines
4.9 KiB
Markdown
Raw Normal View History

2014-08-12 12:03:04 -07:00
# bitcoind.js
2015-07-09 06:35:42 -07:00
A Node.js module that adds a native interface to Bitcoin Core for querying information about the bitcoin blockchain. Bindings are linked to Bitcore Core compiled as a shared library.
2014-08-20 14:51:07 -07:00
2015-07-09 06:35:42 -07:00
## Example Usage
2014-09-26 15:50:05 -07:00
``` js
2014-10-20 09:38:35 -07:00
var bitcoind = require('bitcoind.js')({
2014-12-07 00:21:24 -08:00
directory: '~/.libbitcoind-example',
testnet: false,
rpc: false
2014-10-20 09:38:35 -07:00
});
2014-12-07 00:21:24 -08:00
2015-07-09 06:35:42 -07:00
bitcoind.getBlock(blockHash, function(err, block) {
// block is a node buffer
}
2014-09-26 15:50:05 -07:00
```
2015-07-09 06:35:42 -07:00
You can log output from the daemon using:
2014-09-26 15:50:05 -07:00
``` bash
2015-07-09 06:35:42 -07:00
$ tail -f ~/.libbitcoind-example/debug.log
2014-09-26 15:50:05 -07:00
```
2015-07-09 06:35:42 -07:00
^C (SIGINT) will call `StartShutdown()` in bitcoind on the node thread pool.
## Documentation
2015-07-09 06:35:42 -07:00
- `Bitcoin::start([options], [callback])` - Start the javascript bitcoin node.
- `Bitcoin::getBlock(blockHash, callback)` - Get any block asynchronously by reading it from disk.
- `Bitcoin::getTransaction(txid, blockhash, callback)` - Get any tx asynchronously by reading it from disk.
- `Bitcoin::log(), Bitcoin::info()` -Log to standard output.
- `Bitcoin::error()` - Log to stderr.
- `Bitcoin::close` - Stop the javascript bitcoin node safely. This will be done automatically on `process.exit` also. It also takes the bitcoin node off the libuv event loop. If the bitcoin object is the only thing on the event loop. Node will simply close.
2015-07-09 06:35:42 -07:00
## Building
2015-07-09 06:35:42 -07:00
There are two main parts of build, compiling Bitcoin Core and the Node.js bindings.
2015-07-09 06:35:42 -07:00
### Node.js Bindings
2015-07-09 06:35:42 -07:00
```bash
$ node-gyp rebuild
```
2015-07-09 06:35:42 -07:00
And then with debug:
2015-07-09 06:35:42 -07:00
```bash
$ node-gyp -d rebuild
```
2015-07-09 06:35:42 -07:00
To be able to debug you'll need to have `gdb` and `node` compiled for debugging, and you can then run:
2015-07-09 06:35:42 -07:00
```bash
$ gdb --args node path/to/example.js
```
2015-07-09 06:35:42 -07:00
### Bitcoin Core
2015-07-09 06:35:42 -07:00
#### Dependencies
2015-07-09 06:35:42 -07:00
All of the dependencies for building Bitcoin Core are needed, for more information please see the build notes for [Unix](https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md) and [Mac OS X](https://github.com/bitcoin/bitcoin/blob/master/doc/build-osx.md).
2015-07-09 06:35:42 -07:00
- Boost
- Boost Header Files (`/usr/include/boost`)
- The Boost header files can be from your distro (like Debian or Ubuntu), just be sure to install the "-dev" versions of Boost.
2015-07-09 06:35:42 -07:00
- OpenSSL headers and libraries (-lcrypto and -lssl), this is used to compile Bitcoin.
2015-07-09 06:35:42 -07:00
- If target platform is Mac OS X, then OS X >= 10.9, Clang and associated linker.
2015-07-09 06:35:42 -07:00
#### Shared Library Patch
2015-07-09 06:35:42 -07:00
To provide native bindings to JavaScript *(or any other language for that matter)*, Bitcoin code, itself, must be linkable. Currently, Bitcoin Core achieves this by providing an JSON RPC interface to bitcoind as well as a shared library for script validation *(and hopefully more)* called libbitcoinconsensus. There is also a node module, ([node-libbitcoinconsensus](https://github.com/bitpay/node-libbitcoinconsensus), that exposes these methods. While these interfaces are useful for several use cases, there are additional use cases that are not fulfilled, and being able to implement customized interfaces is necessary. To be able to do this a few simple changes that need to be made to Bitcoin Core to compile as a shared library.
2015-07-09 06:35:42 -07:00
You can view the patch at: `etc/bitcoin.patch`
2015-07-09 06:35:42 -07:00
Every effort will be made to ensure that this patch stays up-to-date with the latest release of Bitcoin. At the very least, this project began supporting Bitcoin Core v0.10.2.
2015-07-09 06:35:42 -07:00
#### Building
2015-07-09 06:35:42 -07:00
There is a build script that will download Bitcoin Core v10.2 and apply the necessary patch (`/etc/bitcoin.patch`), compile `libbitcoind.{so|dylib}`. Unix/Linux use the file extension "so" whereas Mac OSX uses "dylib" *(bitcoind compiled as a shared library)* and copy into `platform/<os_dir>`. *Note:* This script will run automatically with `npm install`.
2015-07-09 06:35:42 -07:00
```bash
$ cd /path/to/bitcoind.js
$ ./bin/build-libbitcoind
```
2015-07-09 06:35:42 -07:00
The first argument can also be a bitcoin repo directory you already have on your disk, otherwise it will check for ~/bitcoin by default. The `PATCH_VERSION` file dictates what version/tag the patch goes clean against.
2015-07-09 06:35:42 -07:00
`--enable-daemonlib` will compile all object files with `-fPIC` (Position Independent Code - needed to create a shared object).
2015-07-09 06:35:42 -07:00
`make` will then compile `./src/libbitcoind.{so|dylib}` (with `-shared -fPIC`), linking to all the freshly compiled PIC object files. This will completely ignore compiling tests, QT object files and the wallet features in bitcoind/libbitcoind.{so|dylib}.
2015-07-09 06:35:42 -07:00
Without `--enable-daemonlib`, the Makefile with compile bitcoind with -fPIE (Position Independent for Executable), this allows compiling of bitcoind.
2015-07-09 06:35:42 -07:00
Or you can also manually compile using:
```bash
$ cd libbitcoind
$ ./configure --enable-tests=no --enable-daemonlib --with-gui=no --without-qt --without-miniupnpc --without-bdb --enable-debug --disable-wallet --without-utils --prefix=
$ make
$ cp src/libs/libbitcoind.so* ../platform/<os_dir>
```
2014-08-12 12:03:04 -07:00
2015-07-09 06:35:42 -07:00
## License
2014-08-12 12:03:04 -07:00
2015-07-09 06:35:42 -07:00
Code released under [the MIT license](https://github.com/bitpay/bitcoind.js/blob/master/LICENSE).
2015-07-09 06:35:42 -07:00
Copyright 2013-2015 BitPay, Inc.
2014-08-12 12:03:04 -07:00
- bitcoin: Copyright (c) 2009-2015 Bitcoin Core Developers (MIT License)
- bcoin (some code borrowed temporarily): Copyright Fedor Indutny, 2014.