Transaction: Fix wrong logic on input addition
This commit is contained in:
parent
1f45e88268
commit
e568a8786c
@ -402,10 +402,10 @@ Transaction.prototype._fromMultisigUtxo = function(utxo, pubkeys, threshold) {
|
|||||||
*/
|
*/
|
||||||
Transaction.prototype.addInput = function(input, outputScript, satoshis) {
|
Transaction.prototype.addInput = function(input, outputScript, satoshis) {
|
||||||
$.checkArgumentType(input, Input, 'input');
|
$.checkArgumentType(input, Input, 'input');
|
||||||
if (!input.output || !(input.output instanceof Output) && !outputScript && !satoshis) {
|
if (!input.output && (_.isUndefined(outputScript) || _.isUndefined(satoshis))) {
|
||||||
throw new errors.Transaction.NeedMoreInfo('Need information about the UTXO script and satoshis');
|
throw new errors.Transaction.NeedMoreInfo('Need information about the UTXO script and satoshis');
|
||||||
}
|
}
|
||||||
if (!input.output && outputScript && satoshis) {
|
if (!input.output && outputScript && !_.isUndefined(satoshis)) {
|
||||||
outputScript = outputScript instanceof Script ? outputScript : new Script(outputScript);
|
outputScript = outputScript instanceof Script ? outputScript : new Script(outputScript);
|
||||||
$.checkArgumentType(satoshis, 'number', 'satoshis');
|
$.checkArgumentType(satoshis, 'number', 'satoshis');
|
||||||
input.output = new Output({
|
input.output = new Output({
|
||||||
|
|||||||
@ -329,6 +329,29 @@ describe('Transaction', function() {
|
|||||||
expect(deserialized.inputs[0] instanceof Transaction.Input.MultiSigScriptHash).to.equal(true);
|
expect(deserialized.inputs[0] instanceof Transaction.Input.MultiSigScriptHash).to.equal(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('checks on adding inputs', function() {
|
||||||
|
var transaction = new Transaction();
|
||||||
|
it('fails if no output script is provided', function() {
|
||||||
|
expect(function() {
|
||||||
|
transaction.addInput(new Transaction.Input());
|
||||||
|
}).to.throw(errors.Transaction.NeedMoreInfo);
|
||||||
|
});
|
||||||
|
it('fails if no satoshi amount is provided', function() {
|
||||||
|
var input = new Transaction.Input();
|
||||||
|
expect(function() {
|
||||||
|
transaction.addInput(input);
|
||||||
|
}).to.throw(errors.Transaction.NeedMoreInfo);
|
||||||
|
expect(function() {
|
||||||
|
transaction.addInput(new Transaction.Input(), Script.empty());
|
||||||
|
}).to.throw(errors.Transaction.NeedMoreInfo);
|
||||||
|
});
|
||||||
|
it('allows output and transaction to be feed as arguments', function() {
|
||||||
|
expect(function() {
|
||||||
|
transaction.addInput(new Transaction.Input(), Script.empty(), 0);
|
||||||
|
}).to.not.throw();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var tx_empty_hex = '01000000000000000000';
|
var tx_empty_hex = '01000000000000000000';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user