chain: remove chain.byTime.
This commit is contained in:
parent
fd2f158169
commit
07414f5fd3
@ -1621,44 +1621,6 @@ Chain.prototype.seen = function seen(hash) {
|
|||||||
return this.db.hasCache(hash);
|
return this.db.hasCache(hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a block entry by timestamp.
|
|
||||||
* @param {Number} ts - Timestamp.
|
|
||||||
* @returns {Promise} - Returns {@link ChainEntry}.
|
|
||||||
*/
|
|
||||||
|
|
||||||
Chain.prototype.byTime = co(function* byTime(ts) {
|
|
||||||
var start = 0;
|
|
||||||
var end = this.height;
|
|
||||||
var pos, delta, entry;
|
|
||||||
|
|
||||||
if (ts >= this.tip.ts)
|
|
||||||
return this.tip;
|
|
||||||
|
|
||||||
// Do a binary search for a block
|
|
||||||
// mined within an hour of the
|
|
||||||
// timestamp.
|
|
||||||
while (start < end) {
|
|
||||||
pos = (start + end) >>> 1;
|
|
||||||
entry = yield this.db.getEntry(pos);
|
|
||||||
|
|
||||||
if (!entry)
|
|
||||||
return;
|
|
||||||
|
|
||||||
delta = Math.abs(ts - entry.ts);
|
|
||||||
|
|
||||||
if (delta <= 60 * 60)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (ts < entry.ts)
|
|
||||||
end = pos - 1;
|
|
||||||
else
|
|
||||||
start = pos + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the chain to see if it contains a block.
|
* Test the chain to see if it contains a block.
|
||||||
* @param {Hash} hash
|
* @param {Hash} hash
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user