bitcoind: handle block height number as string
This commit is contained in:
parent
484b707589
commit
fa6474e85f
@ -1380,9 +1380,10 @@ Bitcoin.prototype.getAddressSummary = function(addressArg, options, callback) {
|
|||||||
|
|
||||||
Bitcoin.prototype._maybeGetBlockHash = function(blockArg, callback) {
|
Bitcoin.prototype._maybeGetBlockHash = function(blockArg, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (_.isNumber(blockArg)) {
|
if (_.isNumber(blockArg) || blockArg.length < 64) {
|
||||||
|
var height = parseInt(blockArg, 10);
|
||||||
self._tryAll(function(done) {
|
self._tryAll(function(done) {
|
||||||
self.client.getBlockHash(blockArg, function(err, response) {
|
self.client.getBlockHash(height, function(err, response) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(self._wrapRPCError(err));
|
return done(self._wrapRPCError(err));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2789,6 +2789,25 @@ describe('Bitcoin Service', function() {
|
|||||||
done();
|
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) {
|
it('will try multiple nodes if one fails', function(done) {
|
||||||
var bitcoind = new BitcoinService(baseConfig);
|
var bitcoind = new BitcoinService(baseConfig);
|
||||||
var getBlockHash = sinon.stub().callsArgWith(1, null, {
|
var getBlockHash = sinon.stub().callsArgWith(1, null, {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user