From 0601ed29d91b0786fc42b772087cb8421777e5e3 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Thu, 16 Jul 2015 13:43:51 -0400 Subject: [PATCH] 1. Added a way to check if the genesis block is ready in chainActive before sending the ready event. We think that once chainActive[0] is not returning NULL, we should be ready to query the local blockchain. 2. Added the env variable BITCOINDJS_DIR support in the integration tests. --- integration/index.js | 9 +++-- src/bitcoindjs.cc | 83 ++------------------------------------------ 2 files changed, 9 insertions(+), 83 deletions(-) diff --git a/integration/index.js b/integration/index.js index e42fad3d..b018f3c1 100644 --- a/integration/index.js +++ b/integration/index.js @@ -23,7 +23,7 @@ describe('Basic Functionality', function() { before(function(done) { this.timeout(30000); bitcoind = require('../')({ - directory: '~/.bitcoin', + directory: process.env.BITCOINDJS_DIR || '~/.bitcoin', }); bitcoind.on('error', function(err) { @@ -55,13 +55,16 @@ describe('Basic Functionality', function() { tx.fromString(data); it('for tx ' + tx.hash, function(done) { bitcoind.getTransaction(tx.hash, function(err, response) { + if (err) { + throw err; + } assert(response.toString('hex') === data, 'incorrect tx data for ' + tx.hash); done(); }); }); }); }); - + describe('determine if outpoint is unspent/spent', function() { spentData.forEach(function(data) { it('for spent txid ' + data.txid + ' and output ' + data.outputIndex, function() { @@ -79,7 +82,7 @@ describe('Basic Functionality', function() { }); describe('get blocks by hash', function() { - + blockData.forEach(function(data) { var block = bitcore.Block.fromString(data); it('block ' + block.hash, function(done) { diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index d4b34ae2..b4fb8467 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -64,9 +64,6 @@ async_get_tx(uv_work_t *req); static void async_get_tx_after(uv_work_t *req); -static int -get_tx(uint256 txid, uint256& blockhash, CTransaction& ctx); - extern "C" void init(Handle); @@ -139,83 +136,6 @@ struct async_tx_data { Eternal callback; }; -/** - * async_block_tx_data - */ - -struct async_block_tx_data { - std::string err_msg; - std::string txid; - CBlock cblock; - CBlockIndex* cblock_index; - CTransaction ctx; - Eternal callback; -}; - -/** - * async_block_time_data - */ - -typedef struct _cblocks_list { - CBlock cblock; - CBlockIndex* cblock_index; - struct _cblocks_list *next; - std::string err_msg; -} cblocks_list; - -struct async_block_time_data { - std::string err_msg; - uint32_t gte; - uint32_t lte; - int64_t limit; - cblocks_list *cblocks; - Eternal callback; -}; - -/** - * async_addrtx_data - */ - -typedef struct _ctx_list { - CTransaction ctx; - uint256 blockhash; - struct _ctx_list *next; - std::string err_msg; -} ctx_list; - -struct async_addrtx_data { - std::string err_msg; - std::string addr; - ctx_list *ctxs; - int64_t blockheight; - int64_t blocktime; - Eternal callback; -}; - -/** - * async_broadcast_tx_data - */ - -struct async_broadcast_tx_data { - std::string err_msg; - Eternal jstx; - CTransaction ctx; - std::string txid; - bool override_fees; - bool own_only; - Eternal callback; -}; - -/** - * async_from_tx_data - */ - -struct async_from_tx_data { - std::string err_msg; - std::string txid; - ctx_list *ctxs; - Eternal callback; -}; /** * Helpers @@ -276,6 +196,9 @@ async_blocks_ready(uv_work_t *req) { usleep(1E6); } + while(chainActive[0] == NULL) { + usleep(1E6); + } } static void