From 5bd636cab73b12a7e773611adb30ccb3cac8768f Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 19 May 2014 14:14:07 +1000 Subject: [PATCH] Transaction: remove TxIn/TxOut from API --- src/transaction.js | 24 ++++++------------------ test/transaction.js | 18 ------------------ 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index c75b69b..a99dbd2 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -49,18 +49,12 @@ function Transaction(doc) { * * Can be called with any of: * - * - An existing TransactionIn object * - A transaction and an index * - A transaction hash and an index * * Note that this method does not sign the created input. */ Transaction.prototype.addInput = function (tx, outIndex) { - if (arguments[0] instanceof TransactionIn) { - this.ins.push(arguments[0]) - return - } - var hash = typeof tx === "string" ? tx : tx.hash this.ins.push(new TransactionIn({ @@ -77,16 +71,10 @@ Transaction.prototype.addInput = function (tx, outIndex) { * * Can be called with: * - * i) An existing TransactionOut object - * ii) An address object or a string address, and a value - * + * - An address object and a value + * - A base58 address string and a value */ Transaction.prototype.addOutput = function (address, value) { - if (arguments[0] instanceof TransactionOut) { - this.outs.push(arguments[0]) - return - } - if (typeof address === 'string') { address = Address.fromBase58Check(address) } @@ -222,12 +210,12 @@ Transaction.prototype.clone = function () { newTx.version = this.version newTx.locktime = this.locktime - this.ins.forEach(function(txin) { - newTx.addInput(txin.clone()) + newTx.ins = this.ins.map(function(txin) { + return new TransactionIn(txin) }) - this.outs.forEach(function(txout) { - newTx.addOutput(txout.clone()) + newTx.outs = this.outs.map(function(txout) { + return new TransactionOut(txout) }) return newTx diff --git a/test/transaction.js b/test/transaction.js index e76d39c..a00fa2e 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -118,15 +118,6 @@ describe('Transaction', function() { verifyTransactionIn() }) - it('allows a TransactionIn object to be passed in', function() { - var txCopy = tx.clone() - txCopy.addInput(prevTx, 0) - var transactionIn = txCopy.ins[0] - - tx.addInput(transactionIn) - verifyTransactionIn() - }) - function verifyTransactionIn() { assert.equal(tx.ins.length, 1) @@ -151,15 +142,6 @@ describe('Transaction', function() { verifyTransactionOut() }) - it('allows a TransactionOut object to be passed in', function() { - var txCopy = tx.clone() - txCopy.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3", 40000) - var transactionOut = txCopy.outs[0] - - tx.addOutput(transactionOut) - verifyTransactionOut() - }) - it('supports alternative networks', function() { var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'