Merge pull request #502 from felipecsl/master

Fixes unhandled exceptions in Transaction
This commit is contained in:
Manuel Aráoz 2014-10-27 10:43:07 -03:00
commit c996f08040
2 changed files with 15 additions and 4 deletions

View File

@ -189,7 +189,13 @@ Address.fromPubkeyHashScriptSig = function(scriptSig, network) {
//extract an address from scriptSig //extract an address from scriptSig
Address.fromScriptSig = function(scriptSig, network) { Address.fromScriptSig = function(scriptSig, network) {
if (typeof scriptSig === 'string') { if (typeof scriptSig === 'string') {
scriptSig = new Script(new Buffer(scriptSig, 'hex')); try {
var scriptSigBuf = new Buffer(scriptSig, 'hex')
} catch(err) {
// Error: Invalid public key
return null;
}
scriptSig = new Script(scriptSigBuf);
} }
if (!network) if (!network)
network = 'livenet'; network = 'livenet';

View File

@ -633,14 +633,19 @@ Transaction.prototype.getReceivingAddresses = function(networkName) {
ret = []; ret = [];
for (var i = 0; i<this.outs.length; i++) { for (var i = 0; i<this.outs.length; i++) {
var o = this.outs[i]; var o = this.outs[i];
var addr = Address.fromScriptPubKey(o.getScript(), networkName)[0].toString(); var addrs = Address.fromScriptPubKey(o.getScript(), networkName);
ret.push(addr); if (typeof addrs[0] !== 'undefined') {
ret.push(addrs[0].toString());
} else {
ret.push(null);
}
} }
return ret; return ret;
}; };
Transaction.prototype.getSendingAddresses = function(networkName) { Transaction.prototype.getSendingAddresses = function(networkName) {
var ret = [];
if (!networkName) networkName = 'livenet'; if (!networkName) networkName = 'livenet';
var ret = [];
for (var i = 0; i<this.ins.length; i++) { for (var i = 0; i<this.ins.length; i++) {
var input = this.ins[i]; var input = this.ins[i];
var scriptSig = input.getScript(); var scriptSig = input.getScript();