From fa6474e85fa78458e5bd3f24242420e0990c2ee3 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 16 May 2016 18:01:12 -0400 Subject: [PATCH] bitcoind: handle block height number as string --- lib/services/bitcoind.js | 5 +++-- test/services/bitcoind.unit.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index 921fa59d..632b7a12 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -1380,9 +1380,10 @@ Bitcoin.prototype.getAddressSummary = function(addressArg, options, callback) { Bitcoin.prototype._maybeGetBlockHash = function(blockArg, callback) { var self = this; - if (_.isNumber(blockArg)) { + if (_.isNumber(blockArg) || blockArg.length < 64) { + var height = parseInt(blockArg, 10); self._tryAll(function(done) { - self.client.getBlockHash(blockArg, function(err, response) { + self.client.getBlockHash(height, 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 87ff5abb..c36c3756 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -2789,6 +2789,25 @@ describe('Bitcoin Service', function() { done(); }); }); + it('will get the block hash if argument is a number (as string)', function(done) { + var bitcoind = new BitcoinService(baseConfig); + var getBlockHash = sinon.stub().callsArgWith(1, null, { + result: 'blockhash' + }); + bitcoind.nodes.push({ + client: { + getBlockHash: getBlockHash + } + }); + bitcoind._maybeGetBlockHash('10', function(err, hash) { + if (err) { + return done(err); + } + hash.should.equal('blockhash'); + getBlockHash.callCount.should.equal(1); + done(); + }); + }); it('will try multiple nodes if one fails', function(done) { var bitcoind = new BitcoinService(baseConfig); var getBlockHash = sinon.stub().callsArgWith(1, null, {