Add `uncheckedAddInput` function

* For internal usage: for example, testing Script.Interpreter
This commit is contained in:
Esteban Ordano 2014-12-19 10:30:20 -03:00
parent 9a73338c91
commit 99db72ba90
2 changed files with 17 additions and 3 deletions

View File

@ -414,9 +414,23 @@ Transaction.prototype.addInput = function(input, outputScript, satoshis) {
satoshis: 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._changeSetup = false;
this.inputs.push(input); this.inputs.push(input);
this._inputAmount += input.output.satoshis; if (input.output) {
this._inputAmount += input.output.satoshis;
}
return this; return this;
}; };

View File

@ -202,7 +202,7 @@ describe('Interpreter', function() {
var hashbuf = new Buffer(32); var hashbuf = new Buffer(32);
hashbuf.fill(0); hashbuf.fill(0);
var credtx = Transaction(); var credtx = Transaction();
credtx.inputs.push(new Transaction.Input({ credtx.uncheckedAddInput(new Transaction.Input({
prevTxId: '0000000000000000000000000000000000000000000000000000000000000000', prevTxId: '0000000000000000000000000000000000000000000000000000000000000000',
outputIndex: 0xffffffff, outputIndex: 0xffffffff,
sequenceNumber: 0xffffffff, sequenceNumber: 0xffffffff,
@ -215,7 +215,7 @@ describe('Interpreter', function() {
var idbuf = credtx.id; var idbuf = credtx.id;
var spendtx = Transaction(); var spendtx = Transaction();
spendtx.inputs.push(new Transaction.Input({ spendtx.uncheckedAddInput(new Transaction.Input({
prevTxId: idbuf.toString('hex'), prevTxId: idbuf.toString('hex'),
outputIndex: 0, outputIndex: 0,
sequenceNumber: 0xffffffff, sequenceNumber: 0xffffffff,