misc fixes.

This commit is contained in:
Christopher Jeffrey 2014-12-08 10:00:53 -08:00
parent 6970f8a593
commit aeb454b52c
2 changed files with 21 additions and 5 deletions

View File

@ -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() {

View File

@ -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<async_block_tx_data*>(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