Added bindings for getNextBlockHash
This commit is contained in:
parent
4b1b929cff
commit
b49f1505eb
@ -37,7 +37,7 @@ BlockController.prototype.block = function(req, res, next, hash) {
|
|||||||
BlockController.prototype.transformBlock = function(block, info) {
|
BlockController.prototype.transformBlock = function(block, info) {
|
||||||
var blockObj = block.toObject();
|
var blockObj = block.toObject();
|
||||||
var transactionIds = blockObj.transactions.map(function(tx) {
|
var transactionIds = blockObj.transactions.map(function(tx) {
|
||||||
return tx.hash
|
return tx.hash;
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
hash: block.hash,
|
hash: block.hash,
|
||||||
@ -53,7 +53,7 @@ BlockController.prototype.transformBlock = function(block, info) {
|
|||||||
difficulty: block.header.getDifficulty(),
|
difficulty: block.header.getDifficulty(),
|
||||||
chainwork: info.chainWork,
|
chainwork: info.chainWork,
|
||||||
previousblockhash: blockObj.header.prevHash,
|
previousblockhash: blockObj.header.prevHash,
|
||||||
nextblockhash: null, // placeholder
|
nextblockhash: this.node.services.bitcoind.getNextBlockHash(block.hash),
|
||||||
reward: this.getBlockReward(info.height) / 1e8,
|
reward: this.getBlockReward(info.height) / 1e8,
|
||||||
isMainChain: info.isMainChain
|
isMainChain: info.isMainChain
|
||||||
};
|
};
|
||||||
|
|||||||
@ -42,38 +42,35 @@ var blockIndexes = {
|
|||||||
describe('Blocks', function() {
|
describe('Blocks', function() {
|
||||||
describe('/blocks/:blockHash route', function() {
|
describe('/blocks/:blockHash route', function() {
|
||||||
var insight = {
|
var insight = {
|
||||||
"hash": "0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7",
|
'hash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7',
|
||||||
"confirmations": 119,
|
'confirmations': 119,
|
||||||
"size": 1011,
|
'size': 1011,
|
||||||
"height": 533974,
|
'height': 533974,
|
||||||
"version": 536870919,
|
'version': 536870919,
|
||||||
"merkleroot": "b06437355844b8178173f3e18ca141472e4b0861daa81ef0f701cf9e51f0283e",
|
'merkleroot': 'b06437355844b8178173f3e18ca141472e4b0861daa81ef0f701cf9e51f0283e',
|
||||||
"tx": [
|
'tx': [
|
||||||
"25a988e54b02e0e5df146a0f8fa7b9db56210533a9f04bdfda5f4ceb6f77aadd",
|
'25a988e54b02e0e5df146a0f8fa7b9db56210533a9f04bdfda5f4ceb6f77aadd',
|
||||||
"b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0",
|
'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0',
|
||||||
"2e01c7a4a0e335112236b711c4aaddd02e8dc59ba2cda416e8f80ff06dddd7e1"
|
'2e01c7a4a0e335112236b711c4aaddd02e8dc59ba2cda416e8f80ff06dddd7e1'
|
||||||
],
|
],
|
||||||
"time": 1440987503,
|
'time': 1440987503,
|
||||||
"nonce": 1868753784,
|
'nonce': 1868753784,
|
||||||
"bits": "1a0cf267",
|
'bits': '1a0cf267',
|
||||||
"difficulty": 1295829.93087696,
|
'difficulty': 1295829.93087696,
|
||||||
"chainwork": "0000000000000000000000000000000000000000000000054626b1839ade284a",
|
'chainwork': '0000000000000000000000000000000000000000000000054626b1839ade284a',
|
||||||
"previousblockhash": "00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4",
|
'previousblockhash': '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4',
|
||||||
"nextblockhash": "000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d",
|
'nextblockhash': '000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d',
|
||||||
"reward": 12.5,
|
'reward': 12.5,
|
||||||
"isMainChain": true
|
'isMainChain': true
|
||||||
};
|
};
|
||||||
|
|
||||||
var bitcoreBlock = bitcore.Block.fromBuffer(new Buffer(blocks['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7'], 'hex'));
|
var bitcoreBlock = bitcore.Block.fromBuffer(new Buffer(blocks['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7'], 'hex'));
|
||||||
|
|
||||||
var todos = {
|
|
||||||
nextblockhash: '000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d'
|
|
||||||
};
|
|
||||||
|
|
||||||
var node = {
|
var node = {
|
||||||
getBlock: sinon.stub().callsArgWith(1, null, bitcoreBlock),
|
getBlock: sinon.stub().callsArgWith(1, null, bitcoreBlock),
|
||||||
services: {
|
services: {
|
||||||
bitcoind: {
|
bitcoind: {
|
||||||
|
getNextBlockHash: sinon.stub().returns('000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d'),
|
||||||
getBlockIndex: sinon.stub().returns(blockIndexes['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7']),
|
getBlockIndex: sinon.stub().returns(blockIndexes['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7']),
|
||||||
isMainChain: sinon.stub().returns(true)
|
isMainChain: sinon.stub().returns(true)
|
||||||
},
|
},
|
||||||
@ -85,14 +82,13 @@ describe('Blocks', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
it('block data should be correct', function(done) {
|
it('block data should be correct', function(done) {
|
||||||
var blocks = new BlockController(node);
|
var blocks = new BlockController(node);
|
||||||
var req = {};
|
var req = {};
|
||||||
var res = {};
|
var res = {};
|
||||||
var next = function() {
|
var next = function() {
|
||||||
should.exist(req.block);
|
should.exist(req.block);
|
||||||
var block = _.extend(req.block, todos);
|
var block = req.block;
|
||||||
should(block).eql(insight);
|
should(block).eql(insight);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user