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 - - var args = arguments[0].split(':') - address = args[0] - value = parseInt(args[1]) - } + if (typeof address === 'string') { + if (arguments[0].indexOf(':') >= 0) { + var args = arguments[0].split(':') + address = args[0] + value = parseInt(args[1]) - network = network || Network.bitcoin + network = arguments[1] + } - if (typeof address === 'string') { address = Address.fromBase58Check(address) } + network = network || Network.bitcoin + 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()