|
|
@ -112,6 +112,8 @@ Address.prototype._classifyArguments = function(data, network, type) { |
|
|
|
return Address._transformScript(data, network); |
|
|
|
} else if (typeof(data) === 'string') { |
|
|
|
return Address._transformString(data, network, type); |
|
|
|
} else if (_.isObject(data)) { |
|
|
|
return Address._transformObject(data); |
|
|
|
} else { |
|
|
|
throw new TypeError('First argument is an unrecognized data format.'); |
|
|
|
} |
|
|
@ -139,6 +141,23 @@ Address._transformHash = function(hash){ |
|
|
|
return info; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Deserializes an address serialized through `Address#toObject()` |
|
|
|
* @param {Object} data |
|
|
|
* @param {string} data.hash - the hash that this address encodes |
|
|
|
* @param {string} data.type - either 'pubkeyhash' or 'scripthash' |
|
|
|
* @param {Network=} data.network - the name of the network associated |
|
|
|
* @return {Address} |
|
|
|
*/ |
|
|
|
Address._transformObject = function(data) { |
|
|
|
$.checkArgument(data.hash, 'Must provide a `hash` property'); |
|
|
|
$.checkArgument(data.type, 'Must provide a `type` property'); |
|
|
|
data.hashBuffer = new Buffer(data.hash, 'hex'); |
|
|
|
data.network = Networks.get(data.network) || Networks.defaultNetwork; |
|
|
|
|
|
|
|
return data; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Internal function to discover the network and type based on the first data byte |
|
|
|
* |
|
|
|