1. Changed build script libbitcoind to support debug builds as well as release builds

2. Added node binding.gyp build script
3. Adjust authors and removed unneeded npm modules
4. Removed unneeded polling of hook packets every 50ms in bitcoind.js
5. Removed hard-coded path to --prefix
This commit is contained in:
Chris Kleeschulte 2015-07-08 14:24:26 -04:00
parent 0a3337933e
commit 36c9f44050
7 changed files with 120 additions and 297 deletions

14
bin/build-bindings Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
set -e
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
cd "${root_dir}"
debug=
if test x"$1" = x'debug'; then
debug=--d
fi
node-gyp ${debug} rebuild

View File

@ -9,54 +9,64 @@ os_dir=$(./platform/os.sh osdir)
#set the LD_LIBRARY_PATH for the linux clients. #set the LD_LIBRARY_PATH for the linux clients.
export LD_LIBRARY_PATH="${root_dir}/libbitcoind/src/leveldb":"${os_dir}":$LD_LIBRARY_PATH export LD_LIBRARY_PATH="${root_dir}/libbitcoind/src/leveldb":"${os_dir}":$LD_LIBRARY_PATH
if test -e "${os_dir}/libbitcoind.so" || test -e "${os_dir}/libbitcoind.dylib"; then debug=
read -r -p 'libbitcoind already built. Rebuild? (Y/n): ' choice if test x"$1" = x'debug'; then
if test x"$choice" != x'y' -a x"$choice" != x'Y'; then debug=--enable-debug
fi
only_make=false
libbitcoind=`find "${os_dir}" -iname "libbitcoind*"`
if [ "$libbitcoind" != "" ]; then
read -r -p 'libbitcoind already built. Remove and reinstall/Re-make only/Do Nothing? (r/m/D): ' choice
if test x"$choice" = x'r' -o x"$choice" = x'R'; then
echo "Removing libbitcoind and recloning, patching, and building..."
rm -rf "${root_dir}/libbitcoind"
rm -f "${os_dir}/libbitcoind.*"
elif test x"$choice" = x'm' -o x"$choice" = x'M'; then
echo "Running make inside libbitcoind..."
rm -f "${os_dir}/libbitcoind.*"
if [ -d "${root_dir}/libbitcoind" ]; then
only_make=true
else
echo "can not seem to find the build directory, we must do the whole shebang, bummer..."
fi
else
echo 'libbitcoind ready.' echo 'libbitcoind ready.'
exit 0 exit 0
fi fi
rm -rf libbitcoind
rm -f "${os_dir}/libbitcoind.*"
fi fi
if [ -d "${root_dir}/libbitcoind" ]; then
read -r -p "libbitcoind (bitcoind repo) exists, would you like to remove it? (Y/n): " choice
if [ "$choice" = "y" -o "$choice" = "Y" ]; then
rm -rf "${root_dir}/libbitcoind"
else
echo "ok you chose not to remove the bitcoin repo, exiting...bu bye!"
fi
fi
#read the PATCH VERSION
if test -e "${root_dir/PATCH_VERSION}"; then
tag=`cat "$root_dir/PATCH_VERSION" | xargs`
else
echo "no tag file found, please create it in the root of the project as so: 'echo \"v0.10.2\" > PATCH_VERSION'"
exit 0
fi
echo "attempting to checkout tag: $tag of bitcoin from github..."
git clone --depth 1 --branch "${tag}" git://github.com/bitcoin/bitcoin.git libbitcoind
btc_dir="${root_dir}/libbitcoind" btc_dir="${root_dir}/libbitcoind"
echo "Found BTC directory: ${btc_dir}"
cd "${btc_dir}"
echo "Found BTC directory: $btc_dir" if [ "${only_make}" = false ]; then
if test -e "${root_dir/PATCH_VERSION}"; then
tag=`cat "${root_dir}/PATCH_VERSION" | xargs`
else
echo "no tag file found, please create it in the root of the project as so: 'echo \"v0.10.2\" > PATCH_VERSION'"
exit 0
fi
echo './patch-bitcoin.sh' "$btc_dir" echo "attempting to checkout tag: ${tag} of bitcoin from github..."
./bin/patch-bitcoin "$btc_dir" git clone --depth 1 --branch "${tag}" git://github.com/bitcoin/bitcoin.git libbitcoind
cd "$btc_dir" echo './patch-bitcoin.sh' "${btc_dir}"
./bin/patch-bitcoin "${btc_dir}"
if ! test -d .git; then if ! test -d .git; then
echo 'Please point this script to an upstream bitcoin git repo.' echo 'Please point this script to an upstream bitcoin git repo.'
exit 1 exit 1
fi
echo './autogen.sh'
./autogen.sh
options=`cat ${root_dir}/bin/config_options.sh`
full_options="${options}${os_dir} ${debug}"
echo "running the configure script with the following options:\n :::[\"${full_options}\"]:::"
${full_options}
fi fi
echo './autogen.sh'
./autogen.sh
options=`cat ${root_dir}/bin/config_options.sh`
full_options="${options}${os_dir}"
echo "running the configure script with the following options:\n :::[\"${full_options}\"]:::"
$full_options
echo 'make V=1' echo 'make V=1'
make V=1 make V=1

View File

@ -1,2 +1,2 @@
./configure --enable-tests=no --enable-daemonlib --with-gui=no --without-qt --without-miniupnpc --without-bdb --enable-debug --disable-wallet --without-utils --prefix= ./configure --enable-tests=no --enable-daemonlib --with-gui=no --without-qt --without-miniupnpc --without-bdb --disable-wallet --without-utils --prefix=

View File

@ -20,7 +20,7 @@ index 0000000..9623c59
--- /dev/null --- /dev/null
+++ b/config_me.sh +++ b/config_me.sh
@@ -0,0 +1 @@ @@ -0,0 +1 @@
+./configure --enable-tests=no --enable-daemonlib --with-gui=no --without-qt --without-miniupnpc --without-bdb --enable-debug --disable-wallet --without-utils --prefix=/home/k/source/bitcoind.js/platform/debian +./configure --enable-tests=no --enable-daemonlib --with-gui=no --without-qt --without-miniupnpc --without-bdb --enable-debug --disable-wallet --without-utils
diff --git a/configure.ac b/configure.ac diff --git a/configure.ac b/configure.ac
index 579035f..cd20489 100644 index 579035f..cd20489 100644
--- a/configure.ac --- a/configure.ac

View File

@ -6,19 +6,10 @@
process.title = 'bitcoind.js'; process.title = 'bitcoind.js';
var util = require('util');
var fs = require('fs');
var argv = require('optimist').argv;
var rimraf = require('rimraf');
var assert = require('assert');
/** /**
* bitcoind * bitcoind
*/ */
var bitcoindjsConf = process.env('BITCOINDJS_DIR');
if (fs.existsSync(process.env.HOME + '/.libbitcoind-example')) {
rimraf.sync(process.env.HOME + '/.libbitcoind-example');
}
var bitcoind = require('../')({ var bitcoind = require('../')({
directory: '~/.libbitcoind-example' directory: '~/.libbitcoind-example'
@ -30,149 +21,4 @@ bitcoind.on('error', function(err) {
bitcoind.on('open', function(status) { bitcoind.on('open', function(status) {
bitcoind.log('status="%s"', status); bitcoind.log('status="%s"', status);
if (argv.list) {
return;
}
if (argv.blocks) {
return getBlocks(bitcoind);
}
function assertHex(obj) {
// Hash
if (obj.txid) {
assert.equal(obj.hash, obj.getHash('hex'));
} else {
assert.equal(obj.hash, obj.getHash('hex'));
}
// Hex
if (obj.txid) {
assert.equal(obj.hex, obj.toHex());
} else {
assert.equal(obj.hex, obj.toHex());
}
}
if (argv['on-block']) {
return bitcoind.on('block', function callee(block) {
if (block.tx.length === 1) return;
bitcoind.log('Found Block:');
bitcoind.log(block);
return assertHex(block);
});
}
if (argv['on-tx']) {
bitcoind.on('tx', function(tx) {
bitcoind.log('Found TX:');
bitcoind.log(tx);
return assertHex(tx);
});
bitcoind.on('mptx', function(mptx) {
bitcoind.log('Found mempool TX:');
bitcoind.log(mptx);
return assertHex(mptx);
});
return;
}
if (argv.broadcast) {
// Help propagate transactions
return bitcoind.once('tx', function(tx) {
bitcoind.log('Broadcasting TX...');
return tx.broadcast(function(err, hash, tx) {
if (err) throw err;
bitcoind.log('TX Hash: %s', hash);
return bitcoind.log(tx);
});
});
}
// Test fromHex:
if (argv['from-hex']) {
var block = bitcoind.block(testBlock);
assert.equal(block.hash, '0000000000013b8ab2cd513b0261a14096412195a72a0c4827d229dcc7e0f7af');
assert.equal(block.merkleroot, '2fda58e5959b0ee53c5253da9b9f3c0c739422ae04946966991cf55895287552');
bitcoind.log('Block:');
bitcoind.log(block);
var tx = bitcoind.tx(testTx);
assert.equal(tx.txid, 'b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b');
bitcoind.log('Transaction:');
bitcoind.log(tx);
return;
}
// Test all digest packets:
if (argv['packets']) {
bitcoind.on('digest', function(packet) {
return bitcoind.log(packet);
});
return;
}
argv['on-block'] = true;
setTimeout(function() {
bitcoind.on('block', function callee(block) {
if (!argv['on-block']) {
return bitcoind.removeListener('block', callee);
}
bitcoind.log('Found Block:');
bitcoind.log(block);
return assertHex(block);
});
bitcoind.once('block', function(block) {
setTimeout(function() {
argv['on-block'] = false;
bitcoind.log(bitcoind.getInfo());
bitcoind.log(bitcoind.getPeerInfo());
bitcoind.once('version', function(version) {
bitcoind.log('VERSION packet:');
bitcoind.log(version);
});
bitcoind.once('addr', function(addr) {
bitcoind.log('ADDR packet:');
bitcoind.log(addr);
});
}, 8000);
});
}, 2000);
return;
}); });
/**
* Helpers
*/
function getBlocks(bitcoind) {
return setTimeout(function() {
return (function next(hash) {
return bitcoind.getBlock(hash, function(err, block) {
if (err) return bitcoind.log(err.message);
bitcoind.log(block);
if (argv['get-tx'] && block.tx.length && block.tx[0].txid) {
var txid = block.tx[0].txid;
// XXX Dies with a segfault
// bitcoind.getTx(txid, hash, function(err, tx) {
bitcoind.getTx(txid, function(err, tx) {
if (err) return bitcoind.log(err.message);
bitcoind.log('TX -----------------------------------------------------');
bitcoind.log(tx);
bitcoind.log('/TX ----------------------------------------------------');
});
}
if (block.nextblockhash) {
setTimeout(next.bind(null, block.nextblockhash), 500);
}
});
})(genesisBlock);
}, 1000);
}

View File

@ -196,66 +196,7 @@ Bitcoin.prototype.start = function(options, callback) {
bitcoindjs.start(options, function(err, status) { bitcoindjs.start(options, function(err, status) {
self._started = true; self._started = true;
// Poll for queued packets // Poll for queued packet [sigint, sighup, sigquit].forEach(function(signal) {
setInterval(function() {
var packets = bitcoindjs.hookPackets();
if (!packets) {
if (self.debug) {
self.error('Error polling packet queue.');
}
return;
}
if (!packets.length) {
return;
}
self.emit('_packets', packets);
packets.forEach(function(packet) {
setImmediate(function() {
self.emit('raw:' + packet.name, packet);
self.emit('raw', packet);
if (packet.name === 'addr') {
self.emit(packet.name, packet.addresses);
self.emit('digest', packet.addresses);
return;
}
if (packet.name === 'block') {
var block = self.block(packet.block);
self.emit(packet.name, block);
self.emit('digest', block);
block.tx.forEach(function(tx) {
setImmediate(function() {
tx = self.tx(tx);
self.emit('tx', tx);
self.emit('digest', tx);
});
});
return;
}
if (packet.name === 'tx') {
var tx = self.tx(packet.tx);
var name = packet.name;
if (!packet.tx.blockhash) {
name = 'mptx';
}
self.emit(name, tx);
self.emit('digest', tx);
return;
}
self.emit(packet.name, packet);
self.emit('digest', packet);
});
});
}, 50);
[sigint, sighup, sigquit].forEach(function(signal) {
process.on(signal.name, signal.listener = function() { process.on(signal.name, signal.listener = function() {
if (process.listeners(signal.name).length > 1) { if (process.listeners(signal.name).length > 1) {
return; return;

View File

@ -1,17 +1,31 @@
{ {
"name": "bitcoind.js", "name": "bitcoind.js",
"description": "Node binding for bitcoind", "description": "Node binding for bitcoind",
"author": "Christopher Jeffrey", "author": "BitPay <dev@bitpay.com>",
"version": "0.0.8", "version": "0.0.8",
"main": "./index.js", "main": "./index.js",
"repository": "git://github.com/chjj/bitcoind.js.git", "repository": "git://github.com/bitpay/bitcoind.js.git",
"homepage": "https://github.com/chjj/bitcoind.js", "homepage": "https://github.com/bitpay/bitcoind.js",
"bugs": { "bugs": {
"url": "https://github.com/chjj/bitcoind.js/issues" "url": "https://github.com/bitpay/bitcoind.js/issues"
}, },
"contributors": [
{
"name": "Christopher Jeffrey"
},
{
"name": "Braydon Fuller",
"email": "braydon@bitpay.com"
},
{
"name": "Chris Kleeschulte",
"email": "chrisk@bitpay.com"
}
],
"scripts": { "scripts": {
"preinstall": "./bin/build-libbitcoind remote", "preinstall": "./bin/build-libbitcoind && ./bin/build-bindings",
"start": "export LD_LIBRARY_PATH=`./platform/os.sh osdir` && node example" "start": "export LD_LIBRARY_PATH=`./platform/os.sh osdir` && node example",
"debug_install": "./bin/build-libbitcoind debug && ./bin/build-bindings debug"
}, },
"tags": [ "tags": [
"bitcoin", "bitcoin",
@ -24,8 +38,6 @@
}, },
"devDependencies": { "devDependencies": {
"mocha": "~1.16.2", "mocha": "~1.16.2",
"optimist": "0.6.0",
"rimraf": "2.2.8",
"async": "1.2.1", "async": "1.2.1",
"benchmark": "1.0.0" "benchmark": "1.0.0"
} }