bitcoind: bug with getting block hash from address
Fixes an issue where passing an address as the blockArg would get the blockhash for the parsed integer of the address. `parseInt` would parse the address as an integer and then get the block hash for 1. A regular expression now checks that the string is numeric with only 0-9 and the length is less than 40, the size of a ripemd160, and also less than the length of a sha256 hash.
This commit is contained in:
parent
c7ec2dcc89
commit
e8a35e2bb5
@ -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));
|
||||
}
|
||||
|
||||
@ -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, {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user