From 99db72ba90565c2899035bbd2d8c258e2784ab26 Mon Sep 17 00:00:00 2001 From: Esteban Ordano Date: Fri, 19 Dec 2014 10:30:20 -0300 Subject: [PATCH] Add `uncheckedAddInput` function * For internal usage: for example, testing Script.Interpreter --- lib/transaction/transaction.js | 16 +++++++++++++++- test/script/interpreter.js | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index e9680e41d..535fb694a 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -414,9 +414,23 @@ Transaction.prototype.addInput = function(input, outputScript, satoshis) { satoshis: satoshis }); } + return this.uncheckedAddInput(input); +}; + +/** + * Add an input to this transaction, without checking that the input has information about + * the output that it's spending. + * + * @param {Input} input + * @return Transaction this, for chaining + */ +Transaction.prototype.uncheckedAddInput = function(input) { + $.checkArgumentType(input, Input, 'input'); this._changeSetup = false; this.inputs.push(input); - this._inputAmount += input.output.satoshis; + if (input.output) { + this._inputAmount += input.output.satoshis; + } return this; }; diff --git a/test/script/interpreter.js b/test/script/interpreter.js index 97f79f24d..7be035e3a 100644 --- a/test/script/interpreter.js +++ b/test/script/interpreter.js @@ -202,7 +202,7 @@ describe('Interpreter', function() { var hashbuf = new Buffer(32); hashbuf.fill(0); var credtx = Transaction(); - credtx.inputs.push(new Transaction.Input({ + credtx.uncheckedAddInput(new Transaction.Input({ prevTxId: '0000000000000000000000000000000000000000000000000000000000000000', outputIndex: 0xffffffff, sequenceNumber: 0xffffffff, @@ -215,7 +215,7 @@ describe('Interpreter', function() { var idbuf = credtx.id; var spendtx = Transaction(); - spendtx.inputs.push(new Transaction.Input({ + spendtx.uncheckedAddInput(new Transaction.Input({ prevTxId: idbuf.toString('hex'), outputIndex: 0, sequenceNumber: 0xffffffff,