Merge pull request #27 from braydonf/chainactiveready
Handle case that chainActive at height does not exist.
This commit is contained in:
commit
24885211e9
|
@ -85,6 +85,9 @@ describe('Basic Functionality', function() {
|
||||||
knownHeights.forEach(function(data) {
|
knownHeights.forEach(function(data) {
|
||||||
it('block at height ' + data[0], function(done) {
|
it('block at height ' + data[0], function(done) {
|
||||||
bitcoind.getBlock(data[0], function(err, response) {
|
bitcoind.getBlock(data[0], function(err, response) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
var block = bitcore.Block.fromBuffer(response);
|
var block = bitcore.Block.fromBuffer(response);
|
||||||
block.hash.should.equal(data[1]);
|
block.hash.should.equal(data[1]);
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -743,6 +743,10 @@ async_get_block(uv_work_t *req) {
|
||||||
|
|
||||||
if (data->height != -1) {
|
if (data->height != -1) {
|
||||||
pblockindex = chainActive[data->height];
|
pblockindex = chainActive[data->height];
|
||||||
|
if (pblockindex == NULL) {
|
||||||
|
data->err_msg = std::string("Block not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mapBlockIndex.count(hash) == 0) {
|
if (mapBlockIndex.count(hash) == 0) {
|
||||||
data->err_msg = std::string("Block not found.");
|
data->err_msg = std::string("Block not found.");
|
||||||
|
|
Loading…
Reference in New Issue