use blocktime to optimize.
This commit is contained in:
parent
dd2abe4b59
commit
d265cdbd3f
@ -433,6 +433,11 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
|||||||
return record.blockheight > out
|
return record.blockheight > out
|
||||||
? record.blockheight
|
? record.blockheight
|
||||||
: out;
|
: out;
|
||||||
|
}, -1),
|
||||||
|
blocktime: (records || []).reduce(function(out, record) {
|
||||||
|
return record.blocktime > out
|
||||||
|
? record.blocktime
|
||||||
|
: out;
|
||||||
}, -1)
|
}, -1)
|
||||||
};
|
};
|
||||||
return bitcoindjs.getAddrTransactions(options, function(err, addr) {
|
return bitcoindjs.getAddrTransactions(options, function(err, addr) {
|
||||||
@ -442,7 +447,8 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
|||||||
return bitcoin.db.set(address, [{
|
return bitcoin.db.set(address, [{
|
||||||
txid: null,
|
txid: null,
|
||||||
blockhash: null,
|
blockhash: null,
|
||||||
blockheight: null
|
blockheight: null,
|
||||||
|
blocktime: null
|
||||||
}], function() {
|
}], function() {
|
||||||
return callback(null, bitcoin.addr({
|
return callback(null, bitcoin.addr({
|
||||||
address: addr.address,
|
address: addr.address,
|
||||||
@ -458,7 +464,8 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
|||||||
set.push({
|
set.push({
|
||||||
txid: tx.txid,
|
txid: tx.txid,
|
||||||
blockhash: tx.blockhash,
|
blockhash: tx.blockhash,
|
||||||
blockheight: tx.blockheight
|
blockheight: tx.blockheight,
|
||||||
|
blocktime: tx.blocktime
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return bitcoin.db.set(address, set, function() {
|
return bitcoin.db.set(address, set, function() {
|
||||||
|
|||||||
@ -500,6 +500,7 @@ struct async_addrtx_data {
|
|||||||
std::string addr;
|
std::string addr;
|
||||||
ctx_list *ctxs;
|
ctx_list *ctxs;
|
||||||
int64_t blockheight;
|
int64_t blockheight;
|
||||||
|
int64_t blocktime;
|
||||||
Persistent<Function> callback;
|
Persistent<Function> callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -589,7 +590,7 @@ struct async_rescan_data {
|
|||||||
|
|
||||||
#if USE_LDB_ADDR
|
#if USE_LDB_ADDR
|
||||||
static ctx_list *
|
static ctx_list *
|
||||||
read_addr(const std::string addr, const int64_t blockheight);
|
read_addr(const std::string addr, const int64_t blockheight, const int64_t blocktime);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@ -1907,6 +1908,7 @@ NAN_METHOD(GetAddrTransactions) {
|
|||||||
|
|
||||||
std::string addr = "";
|
std::string addr = "";
|
||||||
int64_t blockheight = -1;
|
int64_t blockheight = -1;
|
||||||
|
int64_t blocktime = -1;
|
||||||
|
|
||||||
if (args[0]->IsString()) {
|
if (args[0]->IsString()) {
|
||||||
String::Utf8Value addr_(args[0]->ToString());
|
String::Utf8Value addr_(args[0]->ToString());
|
||||||
@ -1927,6 +1929,12 @@ NAN_METHOD(GetAddrTransactions) {
|
|||||||
if (options->Get(NanNew<String>("blockheight"))->IsNumber()) {
|
if (options->Get(NanNew<String>("blockheight"))->IsNumber()) {
|
||||||
blockheight = options->Get(NanNew<String>("blockheight"))->IntegerValue();
|
blockheight = options->Get(NanNew<String>("blockheight"))->IntegerValue();
|
||||||
}
|
}
|
||||||
|
if (options->Get(NanNew<String>("time"))->IsNumber()) {
|
||||||
|
blocktime = options->Get(NanNew<String>("time"))->IntegerValue();
|
||||||
|
}
|
||||||
|
if (options->Get(NanNew<String>("blocktime"))->IsNumber()) {
|
||||||
|
blocktime = options->Get(NanNew<String>("blocktime"))->IntegerValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Local<Function> callback = Local<Function>::Cast(args[1]);
|
Local<Function> callback = Local<Function>::Cast(args[1]);
|
||||||
@ -1939,6 +1947,7 @@ NAN_METHOD(GetAddrTransactions) {
|
|||||||
data->addr = addr;
|
data->addr = addr;
|
||||||
data->ctxs = NULL;
|
data->ctxs = NULL;
|
||||||
data->blockheight = blockheight;
|
data->blockheight = blockheight;
|
||||||
|
data->blocktime = blocktime;
|
||||||
data->callback = Persistent<Function>::New(callback);
|
data->callback = Persistent<Function>::New(callback);
|
||||||
|
|
||||||
uv_work_t *req = new uv_work_t();
|
uv_work_t *req = new uv_work_t();
|
||||||
@ -2036,7 +2045,7 @@ done:
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
ctx_list *ctxs = read_addr(data->addr, data->blockheight);
|
ctx_list *ctxs = read_addr(data->addr, data->blockheight, data->blocktime);
|
||||||
if (!ctxs->err_msg.empty()) {
|
if (!ctxs->err_msg.empty()) {
|
||||||
data->err_msg = ctxs->err_msg;
|
data->err_msg = ctxs->err_msg;
|
||||||
return;
|
return;
|
||||||
@ -6075,7 +6084,7 @@ jstx_to_ctx(const Local<Object> jstx, CTransaction& ctx_) {
|
|||||||
|
|
||||||
#if USE_LDB_ADDR
|
#if USE_LDB_ADDR
|
||||||
static ctx_list *
|
static ctx_list *
|
||||||
read_addr(const std::string addr, const int64_t blockheight) {
|
read_addr(const std::string addr, const int64_t blockheight, const int64_t blocktime) {
|
||||||
ctx_list *head = new ctx_list();
|
ctx_list *head = new ctx_list();
|
||||||
ctx_list *cur = NULL;
|
ctx_list *cur = NULL;
|
||||||
|
|
||||||
@ -6150,6 +6159,10 @@ read_addr(const std::string addr, const int64_t blockheight) {
|
|||||||
// goto next;
|
// goto next;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
if (blocktime != -1 && index.GetBlockTime() < blocktime) {
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
|
|
||||||
CDiskBlockPos blockPos;
|
CDiskBlockPos blockPos;
|
||||||
blockPos.nFile = index.nFile;
|
blockPos.nFile = index.nFile;
|
||||||
blockPos.nPos = index.nDataPos;
|
blockPos.nPos = index.nDataPos;
|
||||||
@ -6314,8 +6327,8 @@ read_addr(const std::string addr, const int64_t blockheight) {
|
|||||||
next:
|
next:
|
||||||
pcursor->Next();
|
pcursor->Next();
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
pcursor->Next();
|
//pcursor->Next();
|
||||||
continue;
|
//continue;
|
||||||
leveldb::Slice lastKey = pcursor->key();
|
leveldb::Slice lastKey = pcursor->key();
|
||||||
std::string lastKeyHex = HexStr(lastKey.ToString());
|
std::string lastKeyHex = HexStr(lastKey.ToString());
|
||||||
head->err_msg = std::string(e.what()
|
head->err_msg = std::string(e.what()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user