Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

switched network and addressType

  • Loading branch information...
commit 5a946a3a9964d38b14ea5c1c4c28eaaee9c650f9 1 parent 399a6c7
@sidazhang sidazhang authored
Showing with 14 additions and 14 deletions.
  1. +6 −6 lib/address.js
  2. +8 −8 test/address.test.js
View
12 lib/address.js
@@ -26,9 +26,9 @@ var versionBytes = {
}
};
-function Address(bytes, network, addressType) {
+function Address(bytes, addressType, network) {
if (typeof bytes === 'string') {
- this.decodeString(bytes, network, addressType);
+ this.decodeString(bytes, network);
} else {
this.hash = bytes;
// default to pubkeyhash
@@ -57,13 +57,13 @@ Address.prototype.toString = function() {
return base58.encode(bytes);
};
-Address.validateType = function(version, network, addressType) {
+Address.validateType = function(version, addressType, network) {
return (version === addressTypes[addressType][network || Address.defaultNetwork])
}
-Address.validate = function(string, network, addressType) {
+Address.validate = function(string, addressType, network) {
try {
- new Address(string, network, addressType)
+ new Address(string, addressType, network)
} catch (err) {
return false
}
@@ -93,7 +93,7 @@ Address.prototype.decodeString = function(string, network) {
var version = hash.shift();
var addressType = versionBytes[network || Address.defaultNetwork][version]
- if (!Address.validateType(version, network, addressType)) {
+ if (!Address.validateType(version, addressType, network)) {
throw new Error('Address version (' + version + ') not supported: ' + string +
' for ' + addressType);
}
View
16 test/address.test.js
@@ -9,30 +9,30 @@ describe('Address', function() {
var hash160 = "3c176e659bea0f29a3e9bf7880c112b1b31b4dc8"
var address = new Address(binConv(hash160, { in : 'hex',
out: 'bytes'
- }), 'mainnet', 'pubkeyhash') //'testnet is also valid'
+ }), 'pubkeyhash', 'mainnet') //'testnet is also valid'
EQ(address.toString(), "16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS")
})
})
describe(' - Address.validate()', function() {
- it(' > supports pubkey hash addresses', function() {
+ it(' > supports pubkeyhash addresses', function() {
// default to mainnet
// addresses for hash160: 0000000000000000000000000000000000000000
T(Address.validate('1111111111111111111114oLvT2'))
- F(Address.validate('1111111111111111111114oLvT2', 'testnet'))
+ F(Address.validate('1111111111111111111114oLvT2', undefined, 'testnet'))
F(Address.validate('mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8'))
- T(Address.validate('mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8', 'testnet'))
+ T(Address.validate('mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8', undefined, 'testnet'))
})
it(' > supports Scripthash addresses', function() {
// default to mainnet
// addresses for hash160: 0000000000000000000000000000000000000000
T(Address.validate('31h1vYVSYuKP6AhS86fbRdMw9XHieotbST'))
- F(Address.validate('31h1vYVSYuKP6AhS86fbRdMw9XHieotbST', 'testnet'))
+ F(Address.validate('31h1vYVSYuKP6AhS86fbRdMw9XHieotbST', undefined, 'testnet'))
F(Address.validate('2MsFDzHRUAMpjHxKyoEHU3aMCMsVtMqs1PV'))
- T(Address.validate('2MsFDzHRUAMpjHxKyoEHU3aMCMsVtMqs1PV', 'testnet'))
+ T(Address.validate('2MsFDzHRUAMpjHxKyoEHU3aMCMsVtMqs1PV', undefined, 'testnet'))
})
})
@@ -40,14 +40,14 @@ describe('Address', function() {
it(' > supports pubkeyhash addresses', function() {
var address = new Address('1111111111111111111114oLvT2')
EQ(address.getType(), 'pubkeyhash')
- var address = new Address('mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8', 'testnet')
+ var address = new Address('mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8', undefined, 'testnet')
EQ(address.getType('testnet'), 'pubkeyhash')
})
it(' > supports Scripthash addresses', function() {
var address = new Address('31h1vYVSYuKP6AhS86fbRdMw9XHieotbST')
EQ(address.getType(), 'scripthash')
- var address = new Address('2MsFDzHRUAMpjHxKyoEHU3aMCMsVtMqs1PV', 'testnet')
+ var address = new Address('2MsFDzHRUAMpjHxKyoEHU3aMCMsVtMqs1PV', undefined, 'testnet')
EQ(address.getType('testnet'), 'scripthash')
})
})
Please sign in to comment.
Something went wrong with that request. Please try again.