diff --git a/lib/bitcoind.js b/lib/bitcoind.js index d2c82508..31b784f2 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -429,9 +429,9 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) { return bitcoin.db.get(address, function(err, records) { var options = { address: address, - blockindex: (records || []).reduce(function(out, record) { - return record.blockindex > out - ? record.blockindex + blockheight: (records || []).reduce(function(out, record) { + return record.blockheight > out + ? record.blockheight : out; }, -1) }; @@ -442,7 +442,7 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) { return bitcoin.db.set(address, [{ txid: null, blockhash: null, - blockindex: null + blockheight: null }], function() { return callback(null, bitcoin.addr({ address: addr.address, @@ -458,7 +458,7 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) { set.push({ txid: tx.txid, blockhash: tx.blockhash, - blockindex: tx.blockindex + blockheight: tx.blockheight }); }); return bitcoin.db.set(address, set, function() { diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 79622b25..700fb446 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -499,7 +499,7 @@ struct async_addrtx_data { std::string err_msg; std::string addr; ctx_list *ctxs; - int64_t blockindex; + int64_t blockheight; Persistent callback; }; @@ -589,7 +589,7 @@ struct async_rescan_data { #if USE_LDB_ADDR static ctx_list * -read_addr(const std::string addr, const int64_t blockindex); +read_addr(const std::string addr, const int64_t blockheight); #endif static bool @@ -1906,7 +1906,7 @@ NAN_METHOD(GetAddrTransactions) { } std::string addr = ""; - int64_t blockindex = -1; + int64_t blockheight = -1; if (args[0]->IsString()) { String::Utf8Value addr_(args[0]->ToString()); @@ -1921,11 +1921,11 @@ NAN_METHOD(GetAddrTransactions) { String::Utf8Value s_(options->Get(NanNew("addr"))->ToString()); addr = std::string(*s_); } - if (options->Get(NanNew("index"))->IsNumber()) { - blockindex = options->Get(NanNew("index"))->IntegerValue(); + if (options->Get(NanNew("height"))->IsNumber()) { + blockheight = options->Get(NanNew("height"))->IntegerValue(); } - if (options->Get(NanNew("blockindex"))->IsNumber()) { - blockindex = options->Get(NanNew("blockindex"))->IntegerValue(); + if (options->Get(NanNew("blockheight"))->IsNumber()) { + blockheight = options->Get(NanNew("blockheight"))->IntegerValue(); } } @@ -1938,7 +1938,7 @@ NAN_METHOD(GetAddrTransactions) { data->err_msg = std::string(""); data->addr = addr; data->ctxs = NULL; - data->blockindex = blockindex; + data->blockheight = blockheight; data->callback = Persistent::New(callback); uv_work_t *req = new uv_work_t(); @@ -1973,8 +1973,8 @@ async_get_addrtx(uv_work_t *req) { int64_t i = 0; - if (data->blockindex != -1) { - i = data->blockindex; + if (data->blockheight != -1) { + i = data->blockheight; } int64_t height = chainActive.Height(); @@ -2036,7 +2036,7 @@ done: } return; #else - ctx_list *ctxs = read_addr(data->addr, data->blockindex); + ctx_list *ctxs = read_addr(data->addr, data->blockheight); if (!ctxs->err_msg.empty()) { data->err_msg = ctxs->err_msg; return; @@ -5901,8 +5901,11 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { CBlockIndex* pindex = mapBlockIndex[block_hash]; jstx->Set(NanNew("confirmations"), NanNew(pindex->nHeight)); + // XXX Not really index: jstx->Set(NanNew("blockindex"), NanNew(pindex->nHeight)); + jstx->Set(NanNew("blockheight"), + NanNew(pindex->nHeight)); jstx->Set(NanNew("blocktime"), NanNew((int64_t)pindex->GetBlockTime())->ToInteger()); jstx->Set(NanNew("time"), @@ -5911,7 +5914,9 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { NanNew((int64_t)pindex->GetBlockTime())->ToInteger()); } else { jstx->Set(NanNew("confirmations"), NanNew(0)); + // XXX Not really index: jstx->Set(NanNew("blockindex"), NanNew(-1)); + jstx->Set(NanNew("blockheight"), NanNew(-1)); jstx->Set(NanNew("blocktime"), NanNew(0)); jstx->Set(NanNew("time"), NanNew(0)); jstx->Set(NanNew("timereceived"), NanNew(0)); @@ -5936,7 +5941,9 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { jstx->Set(NanNew("confirmations"), NanNew(-1)); jstx->Set(NanNew("generated"), NanNew(false)); jstx->Set(NanNew("blockhash"), NanNew(uint256(0).GetHex())); + // XXX Not really index: jstx->Set(NanNew("blockindex"), NanNew(-1)); + jstx->Set(NanNew("blockheight"), NanNew(-1)); jstx->Set(NanNew("blocktime"), NanNew(0)); jstx->Set(NanNew("walletconflicts"), NanNew()); jstx->Set(NanNew("time"), NanNew(0)); @@ -6068,20 +6075,16 @@ jstx_to_ctx(const Local jstx, CTransaction& ctx_) { #if USE_LDB_ADDR static ctx_list * -read_addr(const std::string addr, const int64_t blockindex) { +read_addr(const std::string addr, const int64_t blockheight) { ctx_list *head = new ctx_list(); ctx_list *cur = NULL; - // XXX Do something with this: - // blockindex - head->err_msg = std::string(""); CScript expectedScriptSig = GetScriptForDestination(CBitcoinAddress(addr).Get()); leveldb::Iterator* pcursor = pblocktree->pdb->NewIterator(pblocktree->iteroptions); - // Seek to blockindex: pcursor->SeekToFirst(); while (pcursor->Valid()) { @@ -6143,14 +6146,14 @@ read_addr(const std::string addr, const int64_t blockindex) { CDiskBlockIndex index; ssValue >> index; + //if (blockheight != -1 && index.nHeight < blockheight) { + // goto next; + //} + CDiskBlockPos blockPos; blockPos.nFile = index.nFile; blockPos.nPos = index.nDataPos; - if (index.nHeight < blockindex) { - goto next; - } - CBlock cblock; if (!ReadBlockFromDisk(cblock, blockPos)) {