From 4012b82bec0c0f3e1d6cf7ee6e0b90ecf9079c7a Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 5 May 2014 15:48:44 +1000 Subject: [PATCH] Fixes Transaction.addOutput(Address, Number) --- src/transaction.js | 18 +++++++++--------- test/transaction.js | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index 12f0f38..f4d78ce 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -96,20 +96,20 @@ Transaction.prototype.addOutput = function (address, value, network) { return } - if (arguments[0].indexOf(':') >= 0) { - network = value + if (typeof address === 'string') { + if (arguments[0].indexOf(':') >= 0) { + var args = arguments[0].split(':') + address = args[0] + value = parseInt(args[1]) - var args = arguments[0].split(':') - address = args[0] - value = parseInt(args[1]) + network = arguments[1] + } + + address = Address.fromBase58Check(address) } network = network || Network.bitcoin - if (typeof address === 'string') { - address = Address.fromBase58Check(address) - } - this.outs.push(new TransactionOut({ value: value, script: Script.createOutputScript(address, network) diff --git a/test/transaction.js b/test/transaction.js index a9e5ef7..616135c 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -154,6 +154,11 @@ describe('Transaction', function() { verifyTransactionOut() }) + it('allows an Address object and value to be passed in', function(){ + tx.addOutput(Address.fromBase58Check('15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3'), 40000) + verifyTransactionOut() + }) + it('allows a string in the form of address:index to be passed in', function(){ tx.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3:40000") verifyTransactionOut()