Address: remove Address.Error
By removing Address.Error, we remove a code smell. This part of the code base was also not under any form of test. Test data and tests have therefore been added verifying its behaviour in both Wallet and Address tests.
This commit is contained in:
parent
4332c9e3d4
commit
8514bbfabd
5 changed files with 52 additions and 20 deletions
|
@ -26,13 +26,6 @@ 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)
|
||||
|
@ -53,7 +46,7 @@ Address.fromScriptPubKey = function(script, network) {
|
|||
return new Address(new Buffer(script.chunks[1]), network.scriptHash)
|
||||
}
|
||||
|
||||
throw new Address.Error(type + ' has no matching Address')
|
||||
assert(false, type + ' has no matching Address')
|
||||
}
|
||||
|
||||
// Export functions
|
||||
|
@ -72,7 +65,7 @@ Address.prototype.toScriptPubKey = function() {
|
|||
return Script.createP2SHScriptPubKey(this.hash)
|
||||
}
|
||||
|
||||
throw new Address.Error(this + ' has no matching script')
|
||||
assert(false, this.toString() + ' has no matching script')
|
||||
}
|
||||
|
||||
Address.prototype.toString = Address.prototype.toBase58Check
|
||||
|
|
|
@ -155,7 +155,7 @@ function Wallet(seed, options) {
|
|||
try {
|
||||
address = Address.fromScriptPubKey(txOut.script, networks[network]).toString()
|
||||
} catch(e) {
|
||||
if (!(e instanceof Address.Error)) throw e
|
||||
if (!(e.message.match(/has no matching Address/))) throw e
|
||||
}
|
||||
|
||||
if (isMyAddress(address)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue