go from highest timestamp to lowest timestamp
This commit is contained in:
parent
e6b850124c
commit
7e1d433781
|
@ -36,10 +36,10 @@ node.getBlock(blockHash, function(err, block) {
|
|||
Get Block Hashes by Timestamp Range
|
||||
|
||||
```js
|
||||
var time1 = 1441911000; // Notice time is in seconds not milliseconds
|
||||
var time2 = 1441914000;
|
||||
var newest = 1441914000; // Notice time is in seconds not milliseconds
|
||||
var oldest = 1441911000;
|
||||
|
||||
node.getBlockHashesByTimestamp(time1, time2, function(err, hashes) {
|
||||
node.getBlockHashesByTimestamp(newest, oldest, function(err, hashes) {
|
||||
//...
|
||||
});
|
||||
```
|
||||
|
|
|
@ -201,17 +201,18 @@ DB.prototype.getBlock = function(hash, callback) {
|
|||
|
||||
/**
|
||||
* get block hashes between two timestamps
|
||||
* @param {Number} start - first timestamp, in seconds, inclusive
|
||||
* @param {Number} end - second timestamp, in seconds, inclusive
|
||||
* @param {Number} high - high timestamp, in seconds, inclusive
|
||||
* @param {Number} low - low timestamp, in seconds, inclusive
|
||||
* @param {Function} callback
|
||||
*/
|
||||
DB.prototype.getBlockHashesByTimestamp = function(start, end, callback) {
|
||||
DB.prototype.getBlockHashesByTimestamp = function(high, low, callback) {
|
||||
var self = this;
|
||||
var hashes = [];
|
||||
|
||||
var stream = this.store.createReadStream({
|
||||
gte: this._encodeBlockIndexKey(start),
|
||||
lte: this._encodeBlockIndexKey(end),
|
||||
gte: this._encodeBlockIndexKey(low),
|
||||
lte: this._encodeBlockIndexKey(high),
|
||||
reverse: true,
|
||||
valueEncoding: 'binary',
|
||||
keyEncoding: 'binary'
|
||||
});
|
||||
|
|
|
@ -387,22 +387,22 @@ describe('DB Service', function() {
|
|||
timestamp: 1441913112
|
||||
};
|
||||
|
||||
db.getBlockHashesByTimestamp(1441911000, 1441914000, function(err, hashes) {
|
||||
db.getBlockHashesByTimestamp(1441914000, 1441911000, function(err, hashes) {
|
||||
should.not.exist(err);
|
||||
hashes.should.deep.equal([block1.hash, block2.hash]);
|
||||
hashes.should.deep.equal([block2.hash, block1.hash]);
|
||||
done();
|
||||
});
|
||||
|
||||
readStream.emit('data', {
|
||||
key: db._encodeBlockIndexKey(block1.timestamp),
|
||||
value: db._encodeBlockIndexValue(block1.hash)
|
||||
});
|
||||
|
||||
readStream.emit('data', {
|
||||
key: db._encodeBlockIndexKey(block2.timestamp),
|
||||
value: db._encodeBlockIndexValue(block2.hash)
|
||||
});
|
||||
|
||||
readStream.emit('data', {
|
||||
key: db._encodeBlockIndexKey(block1.timestamp),
|
||||
value: db._encodeBlockIndexValue(block1.hash)
|
||||
});
|
||||
|
||||
readStream.emit('close');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue