diff --git a/lib/bcoin/address.js b/lib/bcoin/address.js index 46f73252..34506bd8 100644 --- a/lib/bcoin/address.js +++ b/lib/bcoin/address.js @@ -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 ''; +}; + /** * 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 ''; -}; - module.exports = Address;