block test: list of hashes by date
This commit is contained in:
parent
0881b8e538
commit
fe8bb95e28
11
README.md
11
README.md
@ -18,7 +18,6 @@ $ npm install -g bower
|
|||||||
|
|
||||||
## Additional Packages
|
## Additional Packages
|
||||||
* Express - Defined as npm module in the [package.json](package.json) file.
|
* Express - Defined as npm module in the [package.json](package.json) file.
|
||||||
* Mongoose - Defined as npm module in the [package.json](package.json) file.
|
|
||||||
* AngularJS - Defined as bower module in the [bower.json](bower.json) file.
|
* AngularJS - Defined as bower module in the [bower.json](bower.json) file.
|
||||||
* Twitter Bootstrap - Defined as bower module in the [bower.json](bower.json) file.
|
* Twitter Bootstrap - Defined as bower module in the [bower.json](bower.json) file.
|
||||||
* UI Bootstrap - Defined as bower module in the [bower.json](bower.json) file.
|
* UI Bootstrap - Defined as bower module in the [bower.json](bower.json) file.
|
||||||
@ -55,13 +54,15 @@ $ npm install -g bower
|
|||||||
|
|
||||||
http://localhost:3000
|
http://localhost:3000
|
||||||
|
|
||||||
If you get an error, please check the next section "Post-install"
|
|
||||||
|
|
||||||
## Syncing old blockchain data
|
## Syncing old blockchain data
|
||||||
|
|
||||||
Run sync from insight repository (to save old blocks and transactions in MongoDB):
|
Run sync from insight repository (to save old blocks and transactions in
|
||||||
|
LevelDB):
|
||||||
|
|
||||||
$ utils/sync.js
|
Create folders:
|
||||||
|
|
||||||
|
$ mkdir -p db/blocks
|
||||||
|
$ utils/sync.js -S
|
||||||
|
|
||||||
Check utils/sync.js --help for options.
|
Check utils/sync.js --help for options.
|
||||||
|
|
||||||
|
|||||||
@ -129,6 +129,28 @@ function spec() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BlockDb.prototype.getBlocksByDate = function(start_ts, end_ts, cb) {
|
||||||
|
var self = this;
|
||||||
|
var list = [];
|
||||||
|
this.db.createReadStream({
|
||||||
|
start: TIMESTAMP_ROOT + start_ts,
|
||||||
|
end: TIMESTAMP_ROOT + end_ts
|
||||||
|
})
|
||||||
|
.on('data', function (data) {
|
||||||
|
list.push({
|
||||||
|
ts: data.key.replace(TIMESTAMP_ROOT, ''),
|
||||||
|
hash: data.value,
|
||||||
|
info: {}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on('error', function (err) {
|
||||||
|
return cb(err);
|
||||||
|
})
|
||||||
|
.on('end', function () {
|
||||||
|
return cb(null, list);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
BlockDb.blockIndex = function(height, cb) {
|
BlockDb.blockIndex = function(height, cb) {
|
||||||
var rpc = new RpcClient(config.bitcoind);
|
var rpc = new RpcClient(config.bitcoind);
|
||||||
rpc.getBlockHash(height, function(err, bh){
|
rpc.getBlockHash(height, function(err, bh){
|
||||||
|
|||||||
28
test/integration/blocklist.js
Normal file
28
test/integration/blocklist.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
|
var TESTING_BLOCK = '00000000b7cc12abe8a9a604813aab1f2c4f3a242a021065be52393a147a1a86';
|
||||||
|
var START_TS = '1391538611';
|
||||||
|
var END_TS = '1391538638';
|
||||||
|
|
||||||
|
var
|
||||||
|
assert = require('assert'),
|
||||||
|
config = require('../../config/config'),
|
||||||
|
BlockDb = require('../../lib/BlockDb').class();
|
||||||
|
|
||||||
|
describe('BlockDb getHashes', function(){
|
||||||
|
|
||||||
|
var bdb = new BlockDb();
|
||||||
|
it('Get Hash by Date', function(done) {
|
||||||
|
|
||||||
|
bdb.getBlocksByDate(START_TS, END_TS, function(err, list) {
|
||||||
|
if (err) done(err);
|
||||||
|
assert.equal(list[0].ts, START_TS);
|
||||||
|
assert.equal(list[0].hash, TESTING_BLOCK);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user