diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index 10fccc47..4e79fcd6 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -1516,10 +1516,9 @@ Bitcoin.prototype.getAddressSummary = function(addressArg, options, callback) { Bitcoin.prototype._maybeGetBlockHash = function(blockArg, callback) { var self = this; - if (_.isNumber(blockArg) || blockArg.length < 64) { - var height = parseInt(blockArg, 10); + if (_.isNumber(blockArg) || (blockArg.length < 40 && /^[0-9]+$/.test(blockArg))) { self._tryAll(function(done) { - self.client.getBlockHash(height, function(err, response) { + self.client.getBlockHash(blockArg, function(err, response) { if (err) { return done(self._wrapRPCError(err)); } diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 40a0392d..29a29a23 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -3831,6 +3831,57 @@ describe('Bitcoin Service', function() { }); describe('#_maybeGetBlockHash', function() { + it('will not get block hash with an address', function(done) { + var bitcoind = new BitcoinService(baseConfig); + var getBlockHash = sinon.stub(); + bitcoind.nodes.push({ + client: { + getBlockHash: getBlockHash + } + }); + bitcoind._maybeGetBlockHash('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br', function(err, hash) { + if (err) { + return done(err); + } + getBlockHash.callCount.should.equal(0); + hash.should.equal('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'); + done(); + }); + }); + it('will not get block hash with non zero-nine numeric string', function(done) { + var bitcoind = new BitcoinService(baseConfig); + var getBlockHash = sinon.stub(); + bitcoind.nodes.push({ + client: { + getBlockHash: getBlockHash + } + }); + bitcoind._maybeGetBlockHash('109a', function(err, hash) { + if (err) { + return done(err); + } + getBlockHash.callCount.should.equal(0); + hash.should.equal('109a'); + done(); + }); + }); + it('will not get block hash with an address', function(done) { + var bitcoind = new BitcoinService(baseConfig); + var getBlockHash = sinon.stub(); + bitcoind.nodes.push({ + client: { + getBlockHash: getBlockHash + } + }); + bitcoind._maybeGetBlockHash('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br', function(err, hash) { + if (err) { + return done(err); + } + getBlockHash.callCount.should.equal(0); + hash.should.equal('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'); + done(); + }); + }); it('will get the block hash if argument is a number', function(done) { var bitcoind = new BitcoinService(baseConfig); var getBlockHash = sinon.stub().callsArgWith(1, null, {