txdb: refactor range queries.

This commit is contained in:
Christopher Jeffrey 2016-10-09 08:39:54 -07:00
parent 8a158bbe41
commit 4e5ec39cc9
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1310,21 +1310,21 @@ TXDB.prototype.getLocked = function getLocked() {
*/
TXDB.prototype.getHistoryHashes = function getHistoryHashes(account) {
return this.keys({
gte: account != null
? layout.T(account, constants.NULL_HASH)
: layout.t(constants.NULL_HASH),
lte: account != null
? layout.T(account, constants.HIGH_HASH)
: layout.t(constants.HIGH_HASH),
parse: function(key) {
if (account != null) {
if (acount != null) {
return this.keys({
gte: layout.T(account, constants.NULL_HASH),
lte: layout.T(account, constants.HIGH_HASH),
parse: function(key) {
key = layout.Tt(key);
return key[1];
}
key = layout.tt(key);
return key;
}
});
}
return this.keys({
gte: layout.t(constants.NULL_HASH),
lte: layout.t(constants.HIGH_HASH),
parse: layout.tt
});
};
@ -1335,21 +1335,21 @@ TXDB.prototype.getHistoryHashes = function getHistoryHashes(account) {
*/
TXDB.prototype.getUnconfirmedHashes = function getUnconfirmedHashes(account) {
return this.keys({
gte: account != null
? layout.P(account, constants.NULL_HASH)
: layout.p(constants.NULL_HASH),
lte: account != null
? layout.P(account, constants.HIGH_HASH)
: layout.p(constants.HIGH_HASH),
parse: function(key) {
if (account != null) {
if (acount != null) {
return this.keys({
gte: layout.P(account, constants.NULL_HASH),
lte: layout.P(account, constants.HIGH_HASH),
parse: function(key) {
key = layout.Pp(key);
return key[1];
}
key = layout.pp(key);
return key;
}
});
}
return this.keys({
gte: layout.p(constants.NULL_HASH),
lte: layout.p(constants.HIGH_HASH),
parse: layout.pp
});
};
@ -1360,18 +1360,21 @@ TXDB.prototype.getUnconfirmedHashes = function getUnconfirmedHashes(account) {
*/
TXDB.prototype.getOutpoints = function getOutpoints(account) {
return this.keys({
gte: account != null
? layout.C(account, constants.NULL_HASH, 0)
: layout.c(constants.NULL_HASH, 0),
lte: account != null
? layout.C(account, constants.HIGH_HASH, 0xffffffff)
: layout.c(constants.HIGH_HASH, 0xffffffff),
parse: function(key) {
if (account != null) {
if (account != null) {
return this.keys({
gte: layout.C(account, constants.NULL_HASH, 0),
lte: layout.C(account, constants.HIGH_HASH, 0xffffffff),
parse: function(key) {
key = layout.Cc(key);
return new Outpoint(key[1], key[2]);
}
});
}
return this.keys({
gte: layout.c(constants.NULL_HASH, 0),
lte: layout.c(constants.HIGH_HASH, 0xffffffff),
parse: function(key) {
key = layout.cc(key);
return new Outpoint(key[0], key[1]);
}
@ -1400,20 +1403,25 @@ TXDB.prototype.getHeightRangeHashes = function getHeightRangeHashes(account, opt
start = options.start || 0;
end = options.end || 0xffffffff;
return this.keys({
gte: account != null
? layout.H(account, start, constants.NULL_HASH)
: layout.h(start, constants.NULL_HASH),
lte: account != null
? layout.H(account, end, constants.HIGH_HASH)
: layout.h(end, constants.HIGH_HASH),
limit: options.limit,
reverse: options.reverse,
parse: function(key) {
if (account != null) {
if (account != null) {
return this.keys({
gte: layout.H(account, start, constants.NULL_HASH),
lte: layout.H(account, end, constants.HIGH_HASH),
limit: options.limit,
reverse: options.reverse,
parse: function(key) {
key = layout.Hh(key);
return key[2];
}
});
}
return this.keys({
gte: layout.h(start, constants.NULL_HASH),
lte: layout.h(end, constants.HIGH_HASH),
limit: options.limit,
reverse: options.reverse,
parse: function(key) {
key = layout.hh(key);
return key[1];
}
@ -1452,20 +1460,25 @@ TXDB.prototype.getRangeHashes = function getRangeHashes(account, options) {
start = options.start || 0;
end = options.end || 0xffffffff;
return this.keys({
gte: account != null
? layout.M(account, start, constants.NULL_HASH)
: layout.m(start, constants.NULL_HASH),
lte: account != null
? layout.M(account, end, constants.HIGH_HASH)
: layout.m(end, constants.HIGH_HASH),
limit: options.limit,
reverse: options.reverse,
parse: function(key) {
if (account != null) {
if (account != null) {
return this.keys({
gte: layout.M(account, start, constants.NULL_HASH),
lte: layout.M(account, end, constants.HIGH_HASH),
limit: options.limit,
reverse: options.reverse,
parse: function(key) {
key = layout.Mm(key);
return key[2];
}
});
}
return this.keys({
gte: layout.m(start, constants.NULL_HASH),
lte: layout.m(end, constants.HIGH_HASH),
limit: options.limit,
reverse: options.reverse,
parse: function(key) {
key = layout.mm(key);
return key[1];
}