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