|
|
@ -754,18 +754,25 @@ Script.fromAddress = function(address) { |
|
|
|
* @return {Address|boolean} |
|
|
|
*/ |
|
|
|
Script.prototype.getAddressInfo = function(opts) { |
|
|
|
var info = this.getOutputAddressInfo(); |
|
|
|
if (!info) { |
|
|
|
return this.getInputAddressInfo(); |
|
|
|
if (this._isInput) { |
|
|
|
return this._getInputAddressInfo(); |
|
|
|
} else if (this._isOutput) { |
|
|
|
return this._getOutputAddressInfo(); |
|
|
|
} else { |
|
|
|
var info = this._getOutputAddressInfo(); |
|
|
|
if (!info) { |
|
|
|
return this._getInputAddressInfo(); |
|
|
|
} |
|
|
|
return info; |
|
|
|
} |
|
|
|
return info; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Will return the associated output scriptPubKey address information object |
|
|
|
* @return {Address|boolean} |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Script.prototype.getOutputAddressInfo = function() { |
|
|
|
Script.prototype._getOutputAddressInfo = function() { |
|
|
|
var info = {}; |
|
|
|
if (this.isScriptHashOut()) { |
|
|
|
info.hashBuffer = this.getData(); |
|
|
@ -782,8 +789,9 @@ Script.prototype.getOutputAddressInfo = function() { |
|
|
|
/** |
|
|
|
* Will return the associated input scriptSig address information object |
|
|
|
* @return {Address|boolean} |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Script.prototype.getInputAddressInfo = function() { |
|
|
|
Script.prototype._getInputAddressInfo = function() { |
|
|
|
var info = {}; |
|
|
|
if (this.isPublicKeyHashIn()) { |
|
|
|
// hash the publickey found in the scriptSig
|
|
|
@ -799,38 +807,17 @@ Script.prototype.getInputAddressInfo = function() { |
|
|
|
return info; |
|
|
|
}; |
|
|
|
|
|
|
|
Script.prototype._toAddress = function(info, network) { |
|
|
|
if (!info) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
info.network = Networks.get(network) || this._network || Networks.defaultNetwork; |
|
|
|
return new Address(info); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @param {Network=} network |
|
|
|
* @return {Address|boolean} the associated address for this script if possible, or false |
|
|
|
*/ |
|
|
|
Script.prototype.toAddress = function(network) { |
|
|
|
return this._toAddress(this.getAddressInfo(), network); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Will get the associated address for an output scriptPubKey |
|
|
|
* @param {Network=} network |
|
|
|
* @return {Address|boolean} |
|
|
|
*/ |
|
|
|
Script.prototype.toOutputAddress = function(network) { |
|
|
|
return this._toAddress(this.getOutputAddressInfo(), network); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Will get the associated address for an input scriptSig |
|
|
|
* @param {Network=} network |
|
|
|
* @return {Address|boolean} |
|
|
|
*/ |
|
|
|
Script.prototype.toInputAddress = function(network) { |
|
|
|
return this._toAddress(this.getInputAddressInfo(), network); |
|
|
|
var info = this.getAddressInfo(); |
|
|
|
if (!info) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
info.network = Networks.get(network) || this._network || Networks.defaultNetwork; |
|
|
|
return new Address(info); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|