Address: use Address.Error instead

This change is necessary for instanceof comparison when attempting to
rethrow.  Callbacks may be a better solution to introduce later.
This commit is contained in:
Daniel Cousens 2014-05-06 18:33:00 +10:00
parent 5e0d38ba54
commit 4207a0df99

View file

@ -14,8 +14,6 @@ function findScriptTypeByVersion(queryVersion) {
}
}
}
throw new Error('Version has no corresponding network')
}
function Address(hash, version) {
@ -27,6 +25,13 @@ function Address(hash, version) {
this.version = version
}
Address.Error = function(message) {
this.name = 'AddressError'
this.message = message
}
Address.Error.prototype = new Error()
Address.Error.prototype.constructor = Address.Error
// Import functions
Address.fromBase58Check = function(string) {
var decode = base58check.decode(string)
@ -49,7 +54,7 @@ Address.fromScriptPubKey = function(script, network) {
return new Address(new Buffer(script.chunks[1]), network.scriptHash)
}
throw new Error('Could not derive address from script')
throw new Address.Error(type + ' has no matching Address')
}
// Export functions
@ -70,7 +75,7 @@ Address.prototype.toScriptPubKey = function() {
return Script.createP2SHScriptPubKey(this.hash)
}
throw new Error('Address has no matching script')
throw new Address.Error(this + ' has no matching script')
}
Address.prototype.toString = Address.prototype.toBase58Check