fix address.toScript.
This commit is contained in:
parent
a1c200356e
commit
f38350ec14
@ -70,6 +70,44 @@ Address.prototype.toBase58 = function toBase58(network) {
|
||||
return Address.toBase58(this.hash, this.type, this.version, network);
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert the address to an output script.
|
||||
* @returns {Script}
|
||||
*/
|
||||
|
||||
Address.prototype.toScript = function toScript() {
|
||||
if (this.type === 'pubkeyhash')
|
||||
return Script.createPubkeyhash(this.hash);
|
||||
if (this.type === 'scripthash')
|
||||
return Script.createScripthash(this.hash);
|
||||
if (this.version !== -1)
|
||||
return Script.createWitnessProgram(this.version, this.hash);
|
||||
assert(false, 'Bad type.');
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert the Address to a string.
|
||||
* @returns {Base58String}
|
||||
*/
|
||||
|
||||
Address.prototype.toString = function toString() {
|
||||
assert(false, 'Cannot toString an address.');
|
||||
return this.toBase58();
|
||||
};
|
||||
|
||||
/**
|
||||
* Inspect the Address.
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Address.prototype.inspect = function inspect() {
|
||||
return '<Address:'
|
||||
+ ' t=' + this.type
|
||||
+ ' v=' + this.version
|
||||
+ ' b58=' + this.toBase58()
|
||||
+ '>';
|
||||
};
|
||||
|
||||
/**
|
||||
* Compile a hash to an address.
|
||||
* @param {Hash|Buffer} hash
|
||||
@ -381,21 +419,6 @@ Address.fromData = function fromData(data, type, version) {
|
||||
return new Address(Address.parseData(data, type, version));
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert the address to an output script.
|
||||
* @returns {Script}
|
||||
*/
|
||||
|
||||
Address.toScript = function toScript() {
|
||||
if (this.type === 'pubkeyhash')
|
||||
return Script.createPubkeyhash(this.hash);
|
||||
if (this.type === 'scripthash')
|
||||
return Script.createScripthash(this.hash);
|
||||
if (this.version !== -1)
|
||||
return Script.createWitnessProgram(this.version, this.hash);
|
||||
assert(false, 'Bad type.');
|
||||
};
|
||||
|
||||
/**
|
||||
* Validate an address, optionally test against a type.
|
||||
* @param {Base58Address} address
|
||||
@ -444,28 +467,4 @@ Address.getHash = function getHash(data) {
|
||||
|
||||
return hash.toString('hex');
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert the Address to a string.
|
||||
* @returns {Base58String}
|
||||
*/
|
||||
|
||||
Address.prototype.toString = function toString() {
|
||||
assert(false, 'Cannot toString an address.');
|
||||
return this.toBase58();
|
||||
};
|
||||
|
||||
/**
|
||||
* Inspect the Address.
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Address.prototype.inspect = function inspect() {
|
||||
return '<Address:'
|
||||
+ ' t=' + this.type
|
||||
+ ' v=' + this.version
|
||||
+ ' b58=' + this.toBase58()
|
||||
+ '>';
|
||||
};
|
||||
|
||||
module.exports = Address;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user