From f85792ba22d016478c5ec731301f6f66a1f06ede Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 21 May 2014 11:38:03 +1000 Subject: [PATCH] Transaction: remove address from txOut --- src/transaction.js | 9 +-------- test/transaction.js | 7 ++++--- test/wallet.js | 24 ++++++++++++++++++------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index 90899b9..f7935d9 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -91,21 +91,16 @@ Transaction.prototype.addOutput = function(scriptPubKey, value) { scriptPubKey = Address.fromBase58Check(scriptPubKey) } - // TODO: remove me - var addressString - // Attempt to get a valid script if it's an Address object if (scriptPubKey instanceof Address) { var address = scriptPubKey - addressString = address.toBase58Check() scriptPubKey = address.toOutputScript() } this.outs.push(new TransactionOut({ script: scriptPubKey, value: value, - address: addressString })) } @@ -386,14 +381,12 @@ TransactionIn.prototype.clone = function () { function TransactionOut(data) { this.script = data.script this.value = data.value - this.address = data.address } TransactionOut.prototype.clone = function() { return new TransactionOut({ script: this.script, - value: this.value, - address: this.address + value: this.value }) } diff --git a/test/transaction.js b/test/transaction.js index 9bacec3..f849ade 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -143,12 +143,13 @@ describe('Transaction', function() { }) it('supports alternative networks', function() { - var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR' + var address = Address.fromBase58Check('mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR') + var script = address.toOutputScript() - tx.addOutput(addr, 40000) + tx.addOutput(address, 40000) verifyTransactionOut() - assert.equal(tx.outs[0].address.toString(), addr) + assert.deepEqual(tx.outs[0].script, script) }) function verifyTransactionOut() { diff --git a/test/wallet.js b/test/wallet.js index 7562bc5..ffd75c7 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -455,7 +455,9 @@ describe('Wallet', function() { var tx = wallet.createTx(to, toValue) assert.equal(tx.outs.length, 1) - assert.equal(tx.outs[0].address.toString(), to) + + var outAddress = Address.fromOutputScript(tx.outs[0].script, networks.testnet) + assert.equal(outAddress.toString(), to) assert.equal(tx.outs[0].value, toValue) }) }) @@ -480,10 +482,14 @@ describe('Wallet', function() { var tx = wallet.createTx(to, toValue, fee, changeAddress) assert.equal(tx.outs.length, 2) - assert.equal(tx.outs[0].address.toString(), to) + + var outAddress0 = Address.fromOutputScript(tx.outs[0].script, networks.testnet) + var outAddress1 = Address.fromOutputScript(tx.outs[1].script, networks.testnet) + + assert.equal(outAddress0.toString(), to) assert.equal(tx.outs[0].value, toValue) - assert.equal(tx.outs[1].address.toString(), changeAddress) + assert.equal(outAddress1.toString(), changeAddress) assert.equal(tx.outs[1].value, value - (toValue + fee)) }) }) @@ -494,7 +500,9 @@ describe('Wallet', function() { assert.equal(tx.outs.length, 1) var out = tx.outs[0] - assert.equal(out.address, to) + var outAddress = Address.fromOutputScript(out.script) + + assert.equal(outAddress.toString(), to) assert.equal(out.value, value) }) @@ -507,7 +515,9 @@ describe('Wallet', function() { assert.equal(tx.outs.length, 2) var out = tx.outs[1] - assert.equal(out.address, wallet.changeAddresses[1]) + var outAddress = Address.fromOutputScript(out.script) + + assert.equal(outAddress.toString(), wallet.changeAddresses[1]) assert.equal(out.value, 15000) }) @@ -519,7 +529,9 @@ describe('Wallet', function() { assert.equal(wallet.changeAddresses.length, 1) var out = tx.outs[1] - assert.equal(out.address, wallet.changeAddresses[0]) + var outAddress = Address.fromOutputScript(out.script) + + assert.equal(outAddress.toString(), wallet.changeAddresses[0]) assert.equal(out.value, 15000) })