TxBuilder: re-order to avoid mutation in case of failure
This commit is contained in:
parent
ebe34db8df
commit
ba97b5ee34
2 changed files with 34 additions and 8 deletions
|
@ -253,25 +253,28 @@ TransactionBuilder.prototype.sign = function(index, privKey, redeemScript, hashT
|
|||
hash = this.tx.hashForSignature(index, prevOutScript, hashType)
|
||||
}
|
||||
|
||||
this.prevOutScripts[index] = prevOutScript
|
||||
this.prevOutTypes[index] = prevOutType
|
||||
|
||||
if (!(index in this.signatures)) {
|
||||
this.signatures[index] = {
|
||||
var input = this.signatures[index]
|
||||
if (!input) {
|
||||
input = {
|
||||
hashType: hashType,
|
||||
pubKeys: [],
|
||||
redeemScript: redeemScript,
|
||||
scriptType: scriptType,
|
||||
signatures: []
|
||||
}
|
||||
|
||||
this.signatures[index] = input
|
||||
|
||||
} else {
|
||||
assert.equal(scriptType, 'multisig', scriptType + ' doesn\'t support multiple signatures')
|
||||
assert.equal(input.hashType, hashType, 'Inconsistent hashType')
|
||||
assert.deepEqual(input.redeemScript, redeemScript, 'Inconsistent redeemScript')
|
||||
}
|
||||
|
||||
var input = this.signatures[index]
|
||||
assert.equal(input.hashType, hashType, 'Inconsistent hashType')
|
||||
assert.deepEqual(input.redeemScript, redeemScript, 'Inconsistent redeemScript')
|
||||
this.prevOutScripts[index] = prevOutScript
|
||||
this.prevOutTypes[index] = prevOutType
|
||||
|
||||
// TODO: order signatures for multisig, enforce m < n
|
||||
var signature = privKey.sign(hash)
|
||||
input.pubKeys.push(privKey.pub)
|
||||
input.signatures.push(signature)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue