fix issue with strange TX

This commit is contained in:
Matias Alejo Garcia 2014-01-10 15:51:19 -03:00
parent 9c7239e740
commit 2082f66938
3 changed files with 21 additions and 6 deletions

View File

@ -66,7 +66,7 @@ module.exports = function(grunt) {
options: {
file: 'server.js',
args: [],
ignoredFiles: ['public/**', 'test/**'],
ignoredFiles: ['public/**', 'test/**','util/**'],
watchedExtensions: ['js'],
// nodeArgs: ['--debug'],
delayTime: 1,

View File

@ -171,11 +171,14 @@ TransactionSchema.methods.queryInfo = function (next) {
var scriptSig = i.getScript();
var pubKey = scriptSig.simpleInPubKey();
var pubKeyHash = util.sha256ripe160(pubKey);
var addr = new Address(network.addressPubkey, pubKeyHash);
var addrStr = addr.toString();
that.info.vin[c].addr = addrStr;
// We check for pubKey in case a broken / strange TX.
if (pubKey) {
var pubKeyHash = util.sha256ripe160(pubKey);
var addr = new Address(network.addressPubkey, pubKeyHash);
var addrStr = addr.toString();
that.info.vin[c].addr = addrStr;
}
c++;
});

View File

@ -49,7 +49,7 @@ describe('Transaction fromIdWithInfo', function(){
});
});
it('test a coinbase TX', function(done) {
it('test a coinbase TX 2a104bab1782e9b6445583296d4a0ecc8af304e4769ceb64b890e8219c562399', function(done) {
var test_txid2 = '2a104bab1782e9b6445583296d4a0ecc8af304e4769ceb64b890e8219c562399';
Transaction.fromIdWithInfo(test_txid2, function(err, tx) {
if (err) done(err);
@ -59,6 +59,18 @@ describe('Transaction fromIdWithInfo', function(){
done();
});
});
it('test a broken TX 64496d005faee77ac5a18866f50af6b8dd1f60107d6795df34c402747af98608', function(done) {
var test_txid2 = '64496d005faee77ac5a18866f50af6b8dd1f60107d6795df34c402747af98608';
Transaction.fromIdWithInfo(test_txid2, function(err, tx) {
if (err) done(err);
assert.equal(tx.info.txid, test_txid2);
assert.equal(tx.info.vin[0].addr, null);
done();
});
});
});