hashForSignature method
Create hash for legacy signature
Implementation
hashForSignature(int inIndex, Uint8List prevOutScript, int hashType) {
if (inIndex >= inputs.length) return ONE;
// ignore OP_CODESEPARATOR
final ourScript = bscript.compile(bscript.decompile(prevOutScript).where((x) {
return x != Opcodes.OP_CODESEPARATOR;
}).toList());
final txTmp = Transaction.clone(this);
// SIGHASH_NONE: ignore all outputs? (wildcard payee)
if ((hashType & 0x1f) == SIGHASH_NONE) {
txTmp.outputs = [];
// ignore sequence numbers (except at inIndex)
for (var i = 0; i < txTmp.inputs.length; i++) {
if (i != inIndex) {
txTmp.inputs[i].sequence = 0;
}
}
// SIGHASH_SINGLE: ignore all outputs, except at the same index?
} else if ((hashType & 0x1f) == SIGHASH_SINGLE) {
// https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L60
if (inIndex >= outputs.length) return ONE;
// truncate outputs after
txTmp.outputs.length = inIndex + 1;
// "blank" outputs before
for (var i = 0; i < inIndex; i++) {
txTmp.outputs[i] = BLANK_OUTPUT;
}
// ignore sequence numbers (except at inIndex)
for (var i = 0; i < txTmp.inputs.length; i++) {
if (i != inIndex) {
txTmp.inputs[i].sequence = 0;
}
}
}
}