Browse Source

Use defaultNetwork in Script.toAddress

patch-2
Yemel Jardi 10 years ago
parent
commit
9deec5e1c2
  1. 4
      lib/script/script.js
  2. 6
      test/script/script.js

4
lib/script/script.js

@ -702,11 +702,11 @@ Script.fromAddress = function(address) {
};
/**
* @param {Network} [network]
* @return {Address} the associated address for this script
*/
Script.prototype.toAddress = function(network) {
network = Networks.get(network);
$.checkArgument(network, 'Must provide a network');
network = Networks.get(network) || Networks.defaultNetwork;
if (this.isPublicKeyHashOut() || this.isScriptHashOut()) {
return new Address(this, network);
}

6
test/script/script.js

@ -592,6 +592,12 @@ describe('Script', function() {
});
describe('toAddress', function() {
it('uses default network', function() {
var stringAddress = '1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14';
var address = new Address(stringAddress);
var script = new Script(address);
script.toAddress().toString().should.equal(stringAddress);
});
it('for a P2PKH address', function() {
var stringAddress = '1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14';
var address = new Address(stringAddress);

Loading…
Cancel
Save