Added bindings for getNextBlockHash

This commit is contained in:
Braydon Fuller 2015-09-21 14:37:13 -04:00
parent 4b1b929cff
commit b49f1505eb
2 changed files with 25 additions and 29 deletions

View File

@ -37,7 +37,7 @@ BlockController.prototype.block = function(req, res, next, hash) {
BlockController.prototype.transformBlock = function(block, info) {
var blockObj = block.toObject();
var transactionIds = blockObj.transactions.map(function(tx) {
return tx.hash
return tx.hash;
});
return {
hash: block.hash,
@ -53,7 +53,7 @@ BlockController.prototype.transformBlock = function(block, info) {
difficulty: block.header.getDifficulty(),
chainwork: info.chainWork,
previousblockhash: blockObj.header.prevHash,
nextblockhash: null, // placeholder
nextblockhash: this.node.services.bitcoind.getNextBlockHash(block.hash),
reward: this.getBlockReward(info.height) / 1e8,
isMainChain: info.isMainChain
};
@ -202,4 +202,4 @@ BlockController.prototype.getBlockReward = function(height) {
return parseInt(subsidy.toString(10));
};
module.exports = BlockController;
module.exports = BlockController;

View File

@ -42,38 +42,35 @@ var blockIndexes = {
describe('Blocks', function() {
describe('/blocks/:blockHash route', function() {
var insight = {
"hash": "0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7",
"confirmations": 119,
"size": 1011,
"height": 533974,
"version": 536870919,
"merkleroot": "b06437355844b8178173f3e18ca141472e4b0861daa81ef0f701cf9e51f0283e",
"tx": [
"25a988e54b02e0e5df146a0f8fa7b9db56210533a9f04bdfda5f4ceb6f77aadd",
"b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0",
"2e01c7a4a0e335112236b711c4aaddd02e8dc59ba2cda416e8f80ff06dddd7e1"
'hash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7',
'confirmations': 119,
'size': 1011,
'height': 533974,
'version': 536870919,
'merkleroot': 'b06437355844b8178173f3e18ca141472e4b0861daa81ef0f701cf9e51f0283e',
'tx': [
'25a988e54b02e0e5df146a0f8fa7b9db56210533a9f04bdfda5f4ceb6f77aadd',
'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0',
'2e01c7a4a0e335112236b711c4aaddd02e8dc59ba2cda416e8f80ff06dddd7e1'
],
"time": 1440987503,
"nonce": 1868753784,
"bits": "1a0cf267",
"difficulty": 1295829.93087696,
"chainwork": "0000000000000000000000000000000000000000000000054626b1839ade284a",
"previousblockhash": "00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4",
"nextblockhash": "000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d",
"reward": 12.5,
"isMainChain": true
'time': 1440987503,
'nonce': 1868753784,
'bits': '1a0cf267',
'difficulty': 1295829.93087696,
'chainwork': '0000000000000000000000000000000000000000000000054626b1839ade284a',
'previousblockhash': '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4',
'nextblockhash': '000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d',
'reward': 12.5,
'isMainChain': true
};
var bitcoreBlock = bitcore.Block.fromBuffer(new Buffer(blocks['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7'], 'hex'));
var todos = {
nextblockhash: '000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d'
};
var node = {
getBlock: sinon.stub().callsArgWith(1, null, bitcoreBlock),
services: {
bitcoind: {
getNextBlockHash: sinon.stub().returns('000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d'),
getBlockIndex: sinon.stub().returns(blockIndexes['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7']),
isMainChain: sinon.stub().returns(true)
},
@ -85,14 +82,13 @@ describe('Blocks', function() {
}
};
it('block data should be correct', function(done) {
var blocks = new BlockController(node);
var req = {};
var res = {};
var next = function() {
should.exist(req.block);
var block = _.extend(req.block, todos);
var block = req.block;
should(block).eql(insight);
done();
};
@ -225,4 +221,4 @@ describe('Blocks', function() {
blocks.getBlockReward(500000).should.equal(12.5 * 1e8);
});
});
});
});