Merge pull request #873 from eordano/fix/isFullySigned
transaction: better errors for signature methods
This commit is contained in:
commit
9a5193d8e9
|
@ -58,6 +58,9 @@ module.exports = [{
|
||||||
}, {
|
}, {
|
||||||
name: 'NeedMoreInfo',
|
name: 'NeedMoreInfo',
|
||||||
message: format('{0}')
|
message: format('{0}')
|
||||||
|
}, {
|
||||||
|
name: 'UnableToVerifySignature',
|
||||||
|
message: format('Unable to verify signature: {0}')
|
||||||
}, {
|
}, {
|
||||||
name: 'FeeError',
|
name: 'FeeError',
|
||||||
message: format('Fees are not correctly set {0}'),
|
message: format('Fees are not correctly set {0}'),
|
||||||
|
|
|
@ -657,6 +657,14 @@ Transaction.prototype.applySignature = function(signature) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Transaction.prototype.isFullySigned = function() {
|
Transaction.prototype.isFullySigned = function() {
|
||||||
|
_.each(this.inputs, function(input) {
|
||||||
|
if (input.isFullySigned === Input.prototype.isFullySigned) {
|
||||||
|
throw new errors.Transaction.UnableToVerifySignature(
|
||||||
|
'Unrecognized script kind, or not enough information to execute script.' +
|
||||||
|
'This usually happens when creating a transaction from a serialized transaction'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
return _.all(_.map(this.inputs, function(input) {
|
return _.all(_.map(this.inputs, function(input) {
|
||||||
return input.isFullySigned();
|
return input.isFullySigned();
|
||||||
}));
|
}));
|
||||||
|
@ -664,6 +672,12 @@ Transaction.prototype.isFullySigned = function() {
|
||||||
|
|
||||||
Transaction.prototype.isValidSignature = function(signature) {
|
Transaction.prototype.isValidSignature = function(signature) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
if (this.inputs[signature.inputIndex].isValidSignature === Input.prototype.isValidSignature) {
|
||||||
|
throw new errors.Transaction.UnableToVerifySignature(
|
||||||
|
'Unrecognized script kind, or not enough information to execute script.' +
|
||||||
|
'This usually happens when creating a transaction from a serialized transaction'
|
||||||
|
);
|
||||||
|
}
|
||||||
return this.inputs[signature.inputIndex].isValidSignature(self, signature);
|
return this.inputs[signature.inputIndex].isValidSignature(self, signature);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,22 @@ describe('Transaction', function() {
|
||||||
satoshis: 1e8
|
satoshis: 1e8
|
||||||
};
|
};
|
||||||
|
|
||||||
|
describe('not enough information errors', function() {
|
||||||
|
it('fails when Inputs are not subclassed and isFullySigned is called', function() {
|
||||||
|
var tx = new Transaction(tx_1_hex);
|
||||||
|
expect(function() {
|
||||||
|
return tx.isFullySigned();
|
||||||
|
}).to.throw(errors.Transaction.UnableToVerifySignature);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails when Inputs are not subclassed and verifySignature is called', function() {
|
||||||
|
var tx = new Transaction(tx_1_hex);
|
||||||
|
expect(function() {
|
||||||
|
return tx.isValidSignature({inputIndex: 0});
|
||||||
|
}).to.throw(errors.Transaction.UnableToVerifySignature);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('checked serialize', function() {
|
describe('checked serialize', function() {
|
||||||
it('fails if no change address was set', function() {
|
it('fails if no change address was set', function() {
|
||||||
var transaction = new Transaction()
|
var transaction = new Transaction()
|
||||||
|
|
Loading…
Reference in New Issue