From 1490b17f9a3cb233574610d3456fc6a4f076492f Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Thu, 1 Oct 2015 00:21:14 -0400 Subject: [PATCH] Fix bug with getting a block index with unknown height. --- integration/regtest.js | 13 +++++++++++++ src/libbitcoind.cc | 1 + 2 files changed, 14 insertions(+) diff --git a/integration/regtest.js b/integration/regtest.js index e734bfcc..20dbb43b 100644 --- a/integration/regtest.js +++ b/integration/regtest.js @@ -184,6 +184,14 @@ describe('Daemon Binding Functionality', function() { }); }); }); + + it('will get error with number greater than tip', function(done) { + bitcoind.getBlock(1000000000, function(err, response) { + should.exist(err); + done(); + }); + }); + }); describe('get transactions by hash', function() { @@ -254,6 +262,11 @@ describe('Daemon Binding Functionality', function() { blockIndex.height.should.equal(i); }); }); + it('will get null with number greater than tip', function(done) { + var index = bitcoind.getBlockIndex(100000); + should.equal(index, null); + done(); + }); }); describe('isMainChain', function() { diff --git a/src/libbitcoind.cc b/src/libbitcoind.cc index 9dc68d83..8a5328ca 100644 --- a/src/libbitcoind.cc +++ b/src/libbitcoind.cc @@ -1267,6 +1267,7 @@ NAN_METHOD(GetBlockIndex) { if (blockIndex == NULL) { info.GetReturnValue().Set(Null()); + return; } } else {