|
|
@ -117,30 +117,30 @@ Address._transformHash = function(hash){ |
|
|
|
* @returns {Object} An object with keys: network and type |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Address._discoverMeta = function(buffer){ |
|
|
|
var meta = {}; |
|
|
|
Address._classifyFromVersion = function(buffer){ |
|
|
|
var version = {}; |
|
|
|
switch(buffer[0]){ // the version byte
|
|
|
|
case Networks.livenet.pubkeyhash: |
|
|
|
meta.network = Networks.livenet; |
|
|
|
meta.type = Address.PayToPublicKeyHash; |
|
|
|
version.network = Networks.livenet; |
|
|
|
version.type = Address.PayToPublicKeyHash; |
|
|
|
break; |
|
|
|
|
|
|
|
case Networks.livenet.scripthash: |
|
|
|
meta.network = Networks.livenet; |
|
|
|
meta.type = Address.PayToScriptHash; |
|
|
|
version.network = Networks.livenet; |
|
|
|
version.type = Address.PayToScriptHash; |
|
|
|
break; |
|
|
|
|
|
|
|
case Networks.testnet.pubkeyhash: |
|
|
|
meta.network = Networks.testnet; |
|
|
|
meta.type = Address.PayToPublicKeyHash; |
|
|
|
version.network = Networks.testnet; |
|
|
|
version.type = Address.PayToPublicKeyHash; |
|
|
|
break; |
|
|
|
|
|
|
|
case Networks.testnet.scripthash: |
|
|
|
meta.network = Networks.testnet; |
|
|
|
meta.type = Address.PayToScriptHash; |
|
|
|
version.network = Networks.testnet; |
|
|
|
version.type = Address.PayToScriptHash; |
|
|
|
break; |
|
|
|
} |
|
|
|
return meta; |
|
|
|
return version; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
@ -162,19 +162,19 @@ Address._transformBuffer = function(buffer, network, type){ |
|
|
|
} |
|
|
|
|
|
|
|
network = Networks.get(network); |
|
|
|
var meta = Address._discoverMeta(buffer); |
|
|
|
var bufferVersion = Address._classifyFromVersion(buffer); |
|
|
|
|
|
|
|
if (!meta.network || (network && network !== meta.network)) { |
|
|
|
if (!bufferVersion.network || (network && network !== bufferVersion.network)) { |
|
|
|
throw new TypeError('Address has mismatched network type.'); |
|
|
|
} |
|
|
|
|
|
|
|
if (!meta.type || ( type && type !== meta.type )) { |
|
|
|
if (!bufferVersion.type || ( type && type !== bufferVersion.type )) { |
|
|
|
throw new TypeError('Address has mismatched type.'); |
|
|
|
} |
|
|
|
|
|
|
|
info.hashBuffer = buffer.slice(1); |
|
|
|
info.network = meta.network; |
|
|
|
info.type = meta.type; |
|
|
|
info.network = bufferVersion.network; |
|
|
|
info.type = bufferVersion.type; |
|
|
|
return info; |
|
|
|
}; |
|
|
|
|
|
|
|