Combined bitcoind getBlock with getBlockHeader to centralize height.
This commit is contained in:
parent
61e5d77fea
commit
6d95cd0302
@ -412,12 +412,25 @@ Bitcoin.prototype.getBlock = function(blockArg, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
self._tryAllClients(function(client, done) {
|
self._tryAllClients(function(client, done) {
|
||||||
|
|
||||||
client.getBlock(blockhash, false, function(err, response) {
|
client.getBlock(blockhash, false, function(err, response) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(self._wrapRPCError(err));
|
return done(self._wrapRPCError(err));
|
||||||
}
|
}
|
||||||
var blockObj = bitcore.Block.fromString(response.result);
|
|
||||||
done(null, blockObj);
|
self.getBlockHeader(blockhash, function(err, header) {
|
||||||
|
|
||||||
|
if(err) {
|
||||||
|
return done(self._wrapRPCError(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
var blockObj = bitcore.Block.fromString(response.result);
|
||||||
|
blockObj.__height = header.height;
|
||||||
|
done(null, blockObj);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -319,18 +319,10 @@ DB.prototype.loadTips = function(callback) {
|
|||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.bitcoind.getBlockHeader(hash, function(err, header) {
|
self[tip] = block;
|
||||||
|
log.info('loaded tip, hash: ' + block.hash + ' height: ' + block.__height);
|
||||||
|
next();
|
||||||
|
|
||||||
if(err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
block.__height = header.height;
|
|
||||||
self[tip] = block;
|
|
||||||
log.info('loaded tip, hash: ' + block.hash + ' height: ' + block.__height);
|
|
||||||
next();
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -101,12 +101,16 @@ describe('DB Operations', function() {
|
|||||||
blocks.genesis, //end initChain
|
blocks.genesis, //end initChain
|
||||||
block1.hash,
|
block1.hash,
|
||||||
blocks.block1a,
|
blocks.block1a,
|
||||||
|
{ height: 1, hash: block1.header.hash, previousblockhash: BufferUtil.reverse(block1.header.prevHash).toString('hex') },
|
||||||
block2.hash,
|
block2.hash,
|
||||||
blocks.block1b,
|
blocks.block1b,
|
||||||
{ hash: block1.header.hash, previousblockhash: BufferUtil.reverse(block1.header.prevHash).toString('hex') },
|
{ height: 1, hash: block2.header.hash, previousblockhash: BufferUtil.reverse(block2.header.prevHash).toString('hex') },
|
||||||
{ hash: block2.header.hash, previousblockhash: BufferUtil.reverse(block2.header.prevHash).toString('hex') },
|
{ height: 1, hash: block1.header.hash, previousblockhash: BufferUtil.reverse(block1.header.prevHash).toString('hex') },
|
||||||
|
{ height: 1, hash: block2.header.hash, previousblockhash: BufferUtil.reverse(block2.header.prevHash).toString('hex') },
|
||||||
blocks.genesis,
|
blocks.genesis,
|
||||||
|
{ height: 0, hash: genesis.hash },
|
||||||
blocks.block1b,
|
blocks.block1b,
|
||||||
|
{ height: 1, hash: block1.header.hash, previousblockhash: BufferUtil.reverse(block2.header.prevHash).toString('hex') },
|
||||||
];
|
];
|
||||||
|
|
||||||
after(function(done) {
|
after(function(done) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user