diff --git a/src/transaction.js b/src/transaction.js index a99dbd2..a30308b 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -71,18 +71,31 @@ Transaction.prototype.addInput = function (tx, outIndex) { * * Can be called with: * - * - An address object and a value * - A base58 address string and a value + * - An Address object and a value + * - A scriptPubKey Script and a value */ -Transaction.prototype.addOutput = function (address, value) { - if (typeof address === 'string') { - address = Address.fromBase58Check(address) +Transaction.prototype.addOutput = function(scriptPubKey, value) { + // Attempt to get a valid address if it's a base58 address string + if (typeof scriptPubKey === 'string') { + 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, - script: address.toOutputScript(), - address: address // TODO: Remove me + address: addressString })) } diff --git a/test/transaction.js b/test/transaction.js index a00fa2e..54d1e7c 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -142,6 +142,11 @@ describe('Transaction', function() { verifyTransactionOut() }) + it('allows a scriptPubKey and a value to be passed in', function() { + tx.addOutput(Address.fromBase58Check('15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3').toOutputScript(), 40000) + verifyTransactionOut() + }) + it('supports alternative networks', function() { var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'