From 2039e4c6dc556f42dfd9ff00428c54a57f6ca510 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Fri, 26 Jun 2015 16:03:43 -0400 Subject: [PATCH] Added some fixes for the bindings.gyp file. --- benchmarks/index.js | 91 +++++++++++++++++++++++++++++++++++++++++++-- binding.gyp | 11 ++++-- example/index.js | 4 +- lib/bitcoind.js | 5 --- package.json | 4 +- platform/os.sh | 21 ++++++----- src/bitcoindjs.cc | 6 ++- src/bitcoindjs.h | 1 - 8 files changed, 115 insertions(+), 28 deletions(-) diff --git a/benchmarks/index.js b/benchmarks/index.js index 0ba87fcb..778f23c0 100644 --- a/benchmarks/index.js +++ b/benchmarks/index.js @@ -1,10 +1,93 @@ 'use strict' +var assert = require('assert'); +var benchmark = require('benchmark'); +var bitcoinconsensus = require('../'); +var bitcoin = require('bitcoin'); +var async = require('async'); + +var maxTime = 10; + +console.log('Benchmarking Bitcoind.js native interface versus Bitcoind JSON RPC interface'); +console.log('----------------------------------------------------------------------'); // The primary methods needed are: -// getInfo -// getRawTransaction -// sendRawTransaction -// getTransaction +// getInfo === works +// getRawTransactioni === getrawtransaction "txid" ( verbose ) +// sendRawTransaction === sendrawtransaction "hexstring" ( allowhighfees ) +// getTransaction === either I need txindex turned on -or- the wallet turned on // Wallet functionality isn't needed, and libbitcoind.so could be compiled with the --disable-wallet flag. +var fixtureData = { + transactions: [ + '5523b432c1bd6c101bee704ad6c560fd09aefc483f8a4998df6741feaa74e6eb', + 'ff48393e7731507c789cfa9cbfae045b10e023ce34ace699a63cdad88c8b43f8', + '5d35c5eebf704877badd0a131b0a86588041997d40dbee8ccff21ca5b7e5e333', + '88842f2cf9d8659c3434f6bc0c515e22d87f33e864e504d2d7117163a572a3aa', + ] +} + +var bitcoind = require('../')({ + directory: '~/.libbitcoind-example' +}); + +bitcoind.on('error', function(err) { + bitcoind.log('error="%s"', err.message); +}); + +bitcoind.on('open', function(status) { + bitcoind.log('status="%s"', status); + var client = new bitcoin.Client({ + host: 'localhost', + port: 18332, + user: 'bitpaytest', + pass: 'local321' + }); + + async.series([ + function(next) { + + function bitcoindJsonRpc() { + + client.getInfo(); +// var item = Math.floor((Math.random() * fixtures.length)); +// var data = fixtureData.transactions[item]; +// +// client.getTransaction(data, function(err, tx) { +// assert.equal(err, null); +// }); + } + + function bitcoindNative() { + + bitcoind.getInfo(); +// var item = Math.floor((Math.random() * fixtures.length)); +// var data = fixtureData.transaction[item]; +// +// bitcoind.getTransaction(data, function(err, tx) { +// assert.equal(err, null); +// }); + } + + var suite = new benchmark.Suite(); + + suite.add('bitcoind json rpc', bitcoindJsonRpc, { maxTime: maxTime }); + suite.add('bitcoind native', bitcoindNative, { maxTime: maxTime }); + + suite + .on('cycle', function(event) { + console.log(String(event.target)); + }) + .on('complete', function() { + console.log('Fastest is ' + this.filter('fastest').pluck('name')); + console.log('----------------------------------------------------------------------'); + next(); + }) + .run(); + } + ], function(err) { + console.log('Finished'); + bitcoind.stop(); + process.exit(); + }); +}); diff --git a/binding.gyp b/binding.gyp index deb6f147..3b78dfda 100644 --- a/binding.gyp +++ b/binding.gyp @@ -20,7 +20,6 @@ '<(BOOST_INCLUDE)', '<(LEVELDB_INCLUDE)', '<(BITCOIN_DIR)/src', - '/usr/local/Cellar/openssl/1.0.2a-1/include', './libbitcoind/src/secp256k1/include', './libbitcoind/src/leveldb/helpers/memenv', ' /dev/null -if test x"$1" = x'btcdir'; then - if test -n "$BITCOIN_DIR"; then - echo "$BITCOIND_DIR" - elif test -d "$(pwd)/libbitcoind"; then - echo "$(pwd)/libbitcoind" +btcdir() { + if test -d "$(pwd)/libbitcoind"; then + BITCOIN_DIR="$(pwd)/libbitcoind" elif test -d "${HOME}/bitcoin"; then - echo "${HOME}/bitcoin" + BITCOIN_DIR="${HOME}/bitcoin" fi +} + +if test x"$1" = x'btcdir'; then + btcdir + echo $BITCOIN_DIR exit 0 fi @@ -66,10 +69,10 @@ if test x"$1" = x'osdir'; then echo -n "$(pwd)/platform/${os}" exit 0 fi -echo $ext if test -z "$1" -o x"$1" = x'lib'; then - if test -n "$BITCOIN_DIR" -a -e "${BITCOIN_DIR}/src/.libs/libbitcoind.${ext}"; then - echo -n "$(pwd)/libbitcoind/src/.libs/libbitcoind.${ext}" + btcdir + if test -n "${BITCOIN_DIR}" -a -e "${BITCOIN_DIR}/src/.libs/libbitcoind.${ext}"; then + echo -n "${BITCOIN_DIR}/src/.libs/libbitcoind.${ext}" else echo -n "$(pwd)/platform/${os}/libbitcoind.${ext}" fi diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 2a682aaa..82bd1cb5 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -6,10 +6,8 @@ * A bitcoind node.js binding. */ - #include "bitcoindjs.h" - using namespace std; using namespace boost; using namespace node; @@ -536,7 +534,9 @@ start_node_thread(void) { detectShutdownThread = new boost::thread( boost::bind(&DetectShutdownThread, &threadGroup)); + fRet = AppInit2(threadGroup); + } catch (std::exception& e) { if (set_cooked()) { fprintf(stderr, "bitcoind.js: AppInit(): std::exception\n"); @@ -572,6 +572,7 @@ start_node_thread(void) { */ NAN_METHOD(StopBitcoind) { + fprintf(stderr, "Stopping Bitcoind please wait!"); Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); @@ -746,6 +747,7 @@ async_get_block(uv_work_t *req) { std::string strHash = data->hash; uint256 hash(strHash); CBlock cblock; + CBlockIndex* pblockindex = mapBlockIndex[hash]; if (ReadBlockFromDisk(cblock, pblockindex)) { diff --git a/src/bitcoindjs.h b/src/bitcoindjs.h index 83f8f108..12d22391 100644 --- a/src/bitcoindjs.h +++ b/src/bitcoindjs.h @@ -159,7 +159,6 @@ #define USE_LDB_ADDR 0 #define USE_LDB_TX 0 -#define SHUTTING_DOWN() (ShutdownRequested() || shutdown_complete) /** * Node.js Exposed Function Templates