address: refactor.
This commit is contained in:
parent
8108ff3eb5
commit
fcf6254d29
@ -47,6 +47,13 @@ function Address(options) {
|
||||
this.fromOptions(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Address types.
|
||||
* @enum {Number}
|
||||
*/
|
||||
|
||||
Address.types = scriptTypes;
|
||||
|
||||
/**
|
||||
* Inject properties from options object.
|
||||
* @private
|
||||
@ -129,16 +136,11 @@ Address.prototype.getType = function getType() {
|
||||
*/
|
||||
|
||||
Address.prototype.getSize = function getSize() {
|
||||
var size = 0;
|
||||
|
||||
size += 1;
|
||||
var size = 5 + this.hash.length;
|
||||
|
||||
if (this.version !== -1)
|
||||
size += 2;
|
||||
|
||||
size += this.hash.length;
|
||||
size += 4;
|
||||
|
||||
return size;
|
||||
};
|
||||
|
||||
@ -152,21 +154,17 @@ Address.prototype.getSize = function getSize() {
|
||||
Address.prototype.toRaw = function toRaw(network) {
|
||||
var size = this.getSize();
|
||||
var bw = new StaticWriter(size);
|
||||
var prefix;
|
||||
|
||||
if (!network)
|
||||
network = this.network;
|
||||
|
||||
network = Network.get(network);
|
||||
prefix = Address.getPrefix(this.type, network);
|
||||
var prefix = this.getPrefix(network);
|
||||
|
||||
assert(prefix !== -1, 'Not a valid address prefix.');
|
||||
|
||||
bw.writeU8(prefix);
|
||||
|
||||
if (this.version !== -1) {
|
||||
bw.writeU8(this.version);
|
||||
bw.writeU8(0);
|
||||
}
|
||||
|
||||
bw.writeBytes(this.hash);
|
||||
bw.writeChecksum();
|
||||
|
||||
@ -186,17 +184,11 @@ Address.prototype.toBase58 = function toBase58(network) {
|
||||
|
||||
/**
|
||||
* Convert the Address to a string.
|
||||
* @returns {Base58String}
|
||||
* @returns {Base58Address}
|
||||
*/
|
||||
|
||||
Address.prototype.toString = function toString(enc) {
|
||||
if (enc === 'hex')
|
||||
return this.getHash('hex');
|
||||
|
||||
if (enc === 'base58')
|
||||
enc = null;
|
||||
|
||||
return this.toBase58(enc);
|
||||
Address.prototype.toString = function toString() {
|
||||
return this.toBase58();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user