diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 1480b684..171967e6 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -374,7 +374,10 @@ Bitcoin.prototype.getTx = function(txHash, blockHash, callback) { } if (typeof blockHash !== 'string') { if (blockHash) { - blockHash = blockHash.hash || blockHash.blockhash || ''; + blockHash = blockHash.hash + || blockHash.blockhash + || (blockHash.getHash && blockHash.getHash()) + || ''; } else { blockHash = ''; } @@ -490,12 +493,20 @@ Bitcoin.prototype.__defineGetter__('chainHeight', function() { Bitcoin.prototype.getBlockByTxid = Bitcoin.prototype.getBlockByTx = function(txid, callback) { - return bitcoindjs.getBlockByTx(txid, callback); + return bitcoindjs.getBlockByTx(txid, function(err, block) { + if (err) return callback(err); + return callback(null, bitcoin.block(block)); + }); }; Bitcoin.prototype.getBlocksByDate = Bitcoin.prototype.getBlocksByTime = function(options, callback) { - return bitcoindjs.getBlocksByTime(options, callback); + return bitcoindjs.getBlocksByTime(options, function(err, blocks) { + if (err) return callback(err); + return callback(null, blocks.map(function(block) { + return bitcoin.block(block) + })); + }); }; Bitcoin.prototype.getLastFileIndex = function() { diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 14f0e7fa..46708cc1 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -188,6 +188,7 @@ using namespace v8; // LevelDB options #define USE_LDB_ADDR 0 +#define USE_LDB_TX 1 /** * Node.js Exposed Function Templates @@ -2188,10 +2189,10 @@ NAN_METHOD(GetBlockByTx) { static void async_block_tx(uv_work_t *req) { async_block_tx_data* data = static_cast(req->data); - CBlock cblock; - CBlockIndex *cblock_index; +#if USE_LDB_TX if (!g_txindex) { parse: +#endif int64_t i = 0; int64_t height = chainActive.Height(); for (; i <= height; i++) { @@ -2209,13 +2210,17 @@ parse: } data->err_msg = std::string("Block not found."); return; +#if USE_LDB_TX } + CBlock cblock; + CBlockIndex *cblock_index; if (get_block_by_tx(data->txid, cblock, &cblock_index)) { data->cblock = cblock; data->cblock_index = cblock_index; } else { goto parse; } +#endif } static void