fix anyonecanpay.

This commit is contained in:
Christopher Jeffrey 2016-01-13 20:05:25 -08:00
parent 8ade973b31
commit 018d534c47

View File

@ -588,6 +588,7 @@ TX.prototype.getSubscript = function getSubscript(index) {
TX.prototype.signatureHash = function signatureHash(index, s, type) {
var copy = this.clone();
var inputIndex = index;
var msg, hash;
if (typeof index !== 'number')
@ -599,28 +600,34 @@ TX.prototype.signatureHash = function signatureHash(index, s, type) {
assert(type != null);
assert(index < copy.inputs.length)
// bitcoind used to return 1 as an error code:
// it ended up being treated like a hash.
// if (index >= copy.inputs.length)
// return constants.oneHash.slice();
if (type & constants.hashType.anyonecanpay) {
copy.inputs = [copy.inputs[inputIndex]];
inputIndex = 0;
}
copy.inputs.forEach(function(input, i) {
input.script = i === index ? s : [];
input.script = i === inputIndex ? s : [];
});
if ((type & 0x1f) === constants.hashType.all) {
;
} else if ((type & 0x1f) === constants.hashType.none) {
copy.outputs = [];
copy.inputs.forEach(function(input, i) {
if (i !== index)
if (i !== inputIndex)
input.seq = 0;
});
copy.outputs = [];
} else if ((type & 0x1f) === constants.hashType.single) {
// bitcoind sighash_single bug:
// Bitcoind used to return 1 as an error code:
// it ended up being treated like a hash.
if (index >= copy.outputs.length)
return constants.oneHash.slice();
copy.inputs.forEach(function(input, i) {
if (i !== inputIndex)
input.seq = 0;
});
while (copy.outputs.length < index + 1)
copy.outputs.push({});
@ -633,20 +640,10 @@ TX.prototype.signatureHash = function signatureHash(index, s, type) {
output.value = new bn('ffffffffffffffff', 'hex');
}
});
copy.inputs.forEach(function(input, i) {
if (i !== index)
input.seq = 0;
});
} else {
assert(false);
}
if (type & constants.hashType.anyonecanpay) {
copy.inputs.length = 1;
copy.inputs[0].script = s;
}
msg = copy.render(true);
utils.writeU32(msg, type, msg.length);