Skip to content

Commit 090b817

Browse files
committed
TransactionBuilder: flatten inconsistency checks
1 parent 088f080 commit 090b817

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/transaction_builder.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,17 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
462462

463463
var input = this.inputs[vin]
464464

465-
// if redeemScript was provided, enforce consistency
466-
if (input.redeemScript !== undefined && redeemScript) {
467-
if (!input.redeemScript.equals(redeemScript)) throw new Error('Inconsistent redeemScript')
465+
// if redeemScript was previously provided, enforce consistency
466+
if (input.redeemScript !== undefined &&
467+
redeemScript &&
468+
!input.redeemScript.equals(redeemScript)) {
469+
throw new Error('Inconsistent redeemScript')
468470
}
469471

470-
if (input.hashType !== undefined) {
471-
if (input.hashType !== hashType) throw new Error('Inconsistent hashType')
472+
// if hashType was previously provided, enforce consistency
473+
if (input.hashType !== undefined &&
474+
input.hashType !== hashType) {
475+
throw new Error('Inconsistent hashType')
472476
}
473477

474478
var kpPubKey = keyPair.getPublicKeyBuffer()
@@ -483,15 +487,15 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
483487
var signatureHash = this.tx.hashForSignature(vin, hashScript, hashType)
484488

485489
// enforce in order signing of public keys
486-
var valid = input.pubKeys.some(function (pubKey, i) {
490+
var signed = input.pubKeys.some(function (pubKey, i) {
487491
if (!kpPubKey.equals(pubKey)) return false
488492
if (input.signatures[i]) throw new Error('Signature already exists')
489493

490494
input.signatures[i] = keyPair.sign(signatureHash)
491495
return true
492496
})
493497

494-
if (!valid) throw new Error('Key pair cannot sign for this input')
498+
if (!signed) throw new Error('Key pair cannot sign for this input')
495499
}
496500

497501
TransactionBuilder.prototype.__canModifyInputs = function () {

0 commit comments

Comments
 (0)