Browse Source

p2sh -> scripthash

more appealing and memorable name
patch-2
Ryan X. Charles 11 years ago
parent
commit
6a26813955
  1. 12
      lib/address.js
  2. 4
      lib/constants.js
  3. 10
      test/address.js

12
lib/address.js

@ -32,15 +32,15 @@ Address.prototype.fromString = function(str) {
if (version === constants['mainnet']['pubkeyhash']) { if (version === constants['mainnet']['pubkeyhash']) {
this.networkstr = 'mainnet'; this.networkstr = 'mainnet';
this.typestr = 'pubkeyhash'; this.typestr = 'pubkeyhash';
} else if (version === constants['mainnet']['p2sh']) { } else if (version === constants['mainnet']['scripthash']) {
this.networkstr = 'mainnet'; this.networkstr = 'mainnet';
this.typestr = 'p2sh'; this.typestr = 'scripthash';
} else if (version === constants['testnet']['pubkeyhash']) { } else if (version === constants['testnet']['pubkeyhash']) {
this.networkstr = 'testnet'; this.networkstr = 'testnet';
this.typestr = 'pubkeyhash'; this.typestr = 'pubkeyhash';
} else if (version === constants['testnet']['p2sh']) { } else if (version === constants['testnet']['scripthash']) {
this.networkstr = 'testnet'; this.networkstr = 'testnet';
this.typestr = 'p2sh'; this.typestr = 'scripthash';
} else { } else {
this.networkstr = 'unknown'; this.networkstr = 'unknown';
this.typestr = 'unknown'; this.typestr = 'unknown';
@ -84,8 +84,8 @@ Address.prototype.validate = function() {
throw new Error('hash must be a buffer of 20 bytes'); throw new Error('hash must be a buffer of 20 bytes');
if (this.networkstr !== 'mainnet' && this.networkstr !== 'testnet') if (this.networkstr !== 'mainnet' && this.networkstr !== 'testnet')
throw new Error('networkstr must be "mainnet" or "testnet"'); throw new Error('networkstr must be "mainnet" or "testnet"');
if (this.typestr !== 'pubkeyhash' && this.typestr !== 'p2sh') if (this.typestr !== 'pubkeyhash' && this.typestr !== 'scripthash')
throw new Error('typestr must be "pubkeyhash" or "p2sh"'); throw new Error('typestr must be "pubkeyhash" or "scripthash"');
return this; return this;
}; };

4
lib/constants.js

@ -1,7 +1,7 @@
exports.mainnet = { exports.mainnet = {
pubkeyhash: 0x00, pubkeyhash: 0x00,
privkey: 0x80, privkey: 0x80,
p2sh: 0x05, scripthash: 0x05,
bip32pubkey: 0x0488b21e, bip32pubkey: 0x0488b21e,
bip32privkey: 0x0488ade4, bip32privkey: 0x0488ade4,
}; };
@ -9,7 +9,7 @@ exports.mainnet = {
exports.testnet = { exports.testnet = {
pubkeyhash: 0x6f, pubkeyhash: 0x6f,
privkey: 0xef, privkey: 0xef,
p2sh: 0xc4, scripthash: 0xc4,
bip32pubkey: 0x043587cf, bip32pubkey: 0x043587cf,
bip32privkey: 0x04358394, bip32privkey: 0x04358394,
}; };

10
test/address.js

@ -61,20 +61,20 @@ describe('Address', function() {
address.toString().should.equal('mm1X5M2QWyHVjn7txrF7mmtZDpjCXzoa98'); address.toString().should.equal('mm1X5M2QWyHVjn7txrF7mmtZDpjCXzoa98');
}); });
it('should derive from this known address string mainnet p2sh', function() { it('should derive from this known address string mainnet scripthash', function() {
var address = new Address(); var address = new Address();
address.fromString(str); address.fromString(str);
address.networkstr = 'mainnet'; address.networkstr = 'mainnet';
address.typestr = 'p2sh'; address.typestr = 'scripthash';
address.fromString(address.toString()); address.fromString(address.toString());
address.toString().should.equal('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo'); address.toString().should.equal('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo');
}); });
it('should derive from this known address string testnet p2sh', function() { it('should derive from this known address string testnet scripthash', function() {
var address = new Address(); var address = new Address();
address.fromString(str); address.fromString(str);
address.networkstr = 'testnet'; address.networkstr = 'testnet';
address.typestr = 'p2sh'; address.typestr = 'scripthash';
address.fromString(address.toString()); address.fromString(address.toString());
address.toString().should.equal('2MxjnmaMtsJfyFcyG3WZCzS2RihdNuWqeX4'); address.toString().should.equal('2MxjnmaMtsJfyFcyG3WZCzS2RihdNuWqeX4');
}); });
@ -148,7 +148,7 @@ describe('Address', function() {
address.typestr = 'unknown'; address.typestr = 'unknown';
(function() { (function() {
address.validate(); address.validate();
}).should.throw('typestr must be "pubkeyhash" or "p2sh"'); }).should.throw('typestr must be "pubkeyhash" or "scripthash"');
}); });
}); });

Loading…
Cancel
Save