|
|
@ -750,11 +750,22 @@ Script.fromAddress = function(address) { |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @param {Network=} network |
|
|
|
* @return {Address|boolean} the associated address information object |
|
|
|
* for this script if any, or false |
|
|
|
* Will return the associated address information object |
|
|
|
* @return {Address|boolean} |
|
|
|
*/ |
|
|
|
Script.prototype.getAddressInfo = function(opts) { |
|
|
|
var info = this.getOutputAddressInfo(); |
|
|
|
if (!info) { |
|
|
|
return this.getInputAddressInfo(); |
|
|
|
} |
|
|
|
return info; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Will return the associated output scriptPubKey address information object |
|
|
|
* @return {Address|boolean} |
|
|
|
*/ |
|
|
|
Script.prototype.getAddressInfo = function() { |
|
|
|
Script.prototype.getOutputAddressInfo = function() { |
|
|
|
var info = {}; |
|
|
|
if (this.isScriptHashOut()) { |
|
|
|
info.hashBuffer = this.getData(); |
|
|
@ -762,7 +773,19 @@ Script.prototype.getAddressInfo = function() { |
|
|
|
} else if (this.isPublicKeyHashOut()) { |
|
|
|
info.hashBuffer = this.getData(); |
|
|
|
info.type = Address.PayToPublicKeyHash; |
|
|
|
} else if (this.isPublicKeyHashIn()) { |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return info; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Will return the associated input scriptSig address information object |
|
|
|
* @return {Address|boolean} |
|
|
|
*/ |
|
|
|
Script.prototype.getInputAddressInfo = function() { |
|
|
|
var info = {}; |
|
|
|
if (this.isPublicKeyHashIn()) { |
|
|
|
// hash the publickey found in the scriptSig
|
|
|
|
info.hashBuffer = Hash.sha256ripemd160(this.chunks[1].buf); |
|
|
|
info.type = Address.PayToPublicKeyHash; |
|
|
@ -775,12 +798,8 @@ Script.prototype.getAddressInfo = function() { |
|
|
|
} |
|
|
|
return info; |
|
|
|
}; |
|
|
|
/** |
|
|
|
* @param {Network=} network |
|
|
|
* @return {Address|boolean} the associated address for this script if possible, or false |
|
|
|
*/ |
|
|
|
Script.prototype.toAddress = function(network) { |
|
|
|
var info = this.getAddressInfo(); |
|
|
|
|
|
|
|
Script.prototype._toAddress = function(info, network) { |
|
|
|
if (!info) { |
|
|
|
return false; |
|
|
|
} |
|
|
@ -788,6 +807,32 @@ Script.prototype.toAddress = function(network) { |
|
|
|
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); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Analagous to bitcoind's FindAndDelete. Find and delete equivalent chunks, |
|
|
|
* typically used with push data chunks. Note that this will find and delete |
|
|
|