fix address.toScript.

This commit is contained in:
Christopher Jeffrey 2016-05-14 16:10:41 -07:00
parent a1c200356e
commit f38350ec14
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -70,6 +70,44 @@ Address.prototype.toBase58 = function toBase58(network) {
return Address.toBase58(this.hash, this.type, this.version, 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. * Compile a hash to an address.
* @param {Hash|Buffer} hash * @param {Hash|Buffer} hash
@ -381,21 +419,6 @@ Address.fromData = function fromData(data, type, version) {
return new Address(Address.parseData(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. * Validate an address, optionally test against a type.
* @param {Base58Address} address * @param {Base58Address} address
@ -444,28 +467,4 @@ Address.getHash = function getHash(data) {
return hash.toString('hex'); 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; module.exports = Address;