diff --git a/Gruntfile.js b/Gruntfile.js index bd6d921e..32cf0550 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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, diff --git a/app/models/Transaction.js b/app/models/Transaction.js index 64007892..37d55f33 100644 --- a/app/models/Transaction.js +++ b/app/models/Transaction.js @@ -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++; }); diff --git a/test/model/transaction.js b/test/model/transaction.js index 7c51ec71..0b3e18d0 100644 --- a/test/model/transaction.js +++ b/test/model/transaction.js @@ -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(); + }); + }); + });