TransactionBuilder: flatten inconsistency checks
This commit is contained in:
parent
088f08020e
commit
090b8177d1
1 changed files with 11 additions and 7 deletions
|
@ -462,13 +462,17 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
|
||||||
|
|
||||||
var input = this.inputs[vin]
|
var input = this.inputs[vin]
|
||||||
|
|
||||||
// if redeemScript was provided, enforce consistency
|
// if redeemScript was previously provided, enforce consistency
|
||||||
if (input.redeemScript !== undefined && redeemScript) {
|
if (input.redeemScript !== undefined &&
|
||||||
if (!input.redeemScript.equals(redeemScript)) throw new Error('Inconsistent redeemScript')
|
redeemScript &&
|
||||||
|
!input.redeemScript.equals(redeemScript)) {
|
||||||
|
throw new Error('Inconsistent redeemScript')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.hashType !== undefined) {
|
// if hashType was previously provided, enforce consistency
|
||||||
if (input.hashType !== hashType) throw new Error('Inconsistent hashType')
|
if (input.hashType !== undefined &&
|
||||||
|
input.hashType !== hashType) {
|
||||||
|
throw new Error('Inconsistent hashType')
|
||||||
}
|
}
|
||||||
|
|
||||||
var kpPubKey = keyPair.getPublicKeyBuffer()
|
var kpPubKey = keyPair.getPublicKeyBuffer()
|
||||||
|
@ -483,7 +487,7 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
|
||||||
var signatureHash = this.tx.hashForSignature(vin, hashScript, hashType)
|
var signatureHash = this.tx.hashForSignature(vin, hashScript, hashType)
|
||||||
|
|
||||||
// enforce in order signing of public keys
|
// enforce in order signing of public keys
|
||||||
var valid = input.pubKeys.some(function (pubKey, i) {
|
var signed = input.pubKeys.some(function (pubKey, i) {
|
||||||
if (!kpPubKey.equals(pubKey)) return false
|
if (!kpPubKey.equals(pubKey)) return false
|
||||||
if (input.signatures[i]) throw new Error('Signature already exists')
|
if (input.signatures[i]) throw new Error('Signature already exists')
|
||||||
|
|
||||||
|
@ -491,7 +495,7 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!valid) throw new Error('Key pair cannot sign for this input')
|
if (!signed) throw new Error('Key pair cannot sign for this input')
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionBuilder.prototype.__canModifyInputs = function () {
|
TransactionBuilder.prototype.__canModifyInputs = function () {
|
||||||
|
|
Loading…
Reference in a new issue