Merge pull request #13 from kleetus/script

Script
This commit is contained in:
Braydon Fuller 2015-07-09 13:23:07 -04:00
commit b9aa8a4d4f
7 changed files with 122 additions and 308 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,53 @@ 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
echo 'libbitcoind ready.' fi
btc_dir="${root_dir}/libbitcoind"
echo "Using BTC directory: ${btc_dir}"
rm -f "${os_dir}/libbitcoind.*"
only_make=false
if [ -d "${root_dir}/libbitcoind" ]; then
echo "Running make inside libbitcoind (assuming you've previously patched and configured libbitcoind)..."
cd "${btc_dir}"
only_make=true
else
echo "Removing cloning, patching, and building libbitcoind..."
fi
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 exit 0
fi fi
rm -rf libbitcoind
rm -f "${os_dir}/libbitcoind.*"
fi
if [ -d "${root_dir}/libbitcoind" ]; then echo "attempting to checkout tag: ${tag} of bitcoin from github..."
read -r -p "libbitcoind (bitcoind repo) exists, would you like to remove it? (Y/n): " choice git clone --depth 1 --branch "${tag}" git://github.com/bitcoin/bitcoin.git libbitcoind
if [ "$choice" = "y" -o "$choice" = "Y" ]; then
rm -rf "${root_dir}/libbitcoind" cd "${btc_dir}"
else
echo "ok you chose not to remove the bitcoin repo, exiting...bu bye!" echo '../patch-bitcoin.sh' "${btc_dir}"
../bin/patch-bitcoin "${btc_dir}"
if ! test -d .git; then
echo 'Please point this script to an upstream bitcoin git repo.'
exit 1
fi fi
fi
#read the PATCH VERSION echo './autogen.sh'
if test -e "${root_dir/PATCH_VERSION}"; then ./autogen.sh
tag=`cat "$root_dir/PATCH_VERSION" | xargs` options=`cat ${root_dir}/bin/config_options.sh`
else full_options="${options}${os_dir} ${debug}"
echo "no tag file found, please create it in the root of the project as so: 'echo \"v0.10.2\" > PATCH_VERSION'" echo "running the configure script with the following options:\n :::[\"${full_options}\"]:::"
exit 0 ${full_options}
fi 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"
echo "Found BTC directory: $btc_dir"
echo './patch-bitcoin.sh' "$btc_dir"
./bin/patch-bitcoin "$btc_dir"
cd "$btc_dir"
if ! test -d .git; then
echo 'Please point this script to an upstream bitcoin git repo.'
exit 1
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
@ -67,9 +66,7 @@ if test -e "${root_dir}/libbitcoind/src/.libs/libbitcoind.${ext}"; then
cp "${root_dir}/libbitcoind/src/.libs/libbitcoind.0.dylib" "${os_dir}/" cp "${root_dir}/libbitcoind/src/.libs/libbitcoind.0.dylib" "${os_dir}/"
cp "${root_dir}/libbitcoind/src/.libs/libbitcoind.dylib" "${os_dir}/" cp "${root_dir}/libbitcoind/src/.libs/libbitcoind.dylib" "${os_dir}/"
else else
cp "${root_dir}/libbitcoind/src/.libs/libbitcoind.so" "${os_dir}/" cp -P "${root_dir}"/libbitcoind/src/.libs/libbitcoind.so* "${os_dir}/"
cp "${root_dir}/libbitcoind/src/.libs/libbitcoind.so.0" "${os_dir}/"
cp "${root_dir}/libbitcoind/src/.libs/libbitcoind.so.0.0.0" "${os_dir}/"
fi fi
fi fi

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

@ -1,27 +1,19 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict';
/** /**
* bitcoind.js example * bitcoind.js example
*/ */
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
*/ */
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: process.env.BITCOINDJS_DIR || '~/.bitcoin'
}); });
bitcoind.on('error', function(err) { bitcoind.on('error', function(err) {
@ -30,149 +22,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

@ -6,7 +6,7 @@
var net = require('net'); var net = require('net');
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
var bitcoindjs = require('../build/Debug/bitcoindjs.node'); var bitcoindjs = require('bindings')('bitcoindjs.node');
var util = require('util'); var util = require('util');
var fs = require('fs'); var fs = require('fs');
var mkdirp = require('mkdirp'); var mkdirp = require('mkdirp');
@ -196,65 +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
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) { [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) {

View File

@ -1,31 +1,45 @@
{ {
"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",
"start": "export LD_LIBRARY_PATH=`./platform/os.sh osdir` && node example" "install": "./bin/build-bindings",
"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",
"bitcoind" "bitcoind"
], ],
"dependencies": { "dependencies": {
"nan": "1.3.0", "bindings": "^1.2.1",
"mkdirp": "0.5.0", "mkdirp": "0.5.0",
"nan": "1.3.0",
"tiny": "0.0.10" "tiny": "0.0.10"
}, },
"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"
} }