Preimage of the signature hash, if it exists. Returns either (None, err) to indicate error (which translates to sighash 1), or (msg, None).
(script, txTo, inIdx, hashtype, enable_sighash_rangeproof=True)
| 719 | return CScript(r) |
| 720 | |
| 721 | def LegacySignatureMsg(script, txTo, inIdx, hashtype, enable_sighash_rangeproof=True): |
| 722 | """Preimage of the signature hash, if it exists. |
| 723 | |
| 724 | Returns either (None, err) to indicate error (which translates to sighash 1), |
| 725 | or (msg, None). |
| 726 | """ |
| 727 | |
| 728 | if inIdx >= len(txTo.vin): |
| 729 | return (None, "inIdx %d out of range (%d)" % (inIdx, len(txTo.vin))) |
| 730 | txtmp = CTransaction(txTo) |
| 731 | |
| 732 | for txin in txtmp.vin: |
| 733 | txin.scriptSig = b'' |
| 734 | txtmp.vin[inIdx].scriptSig = FindAndDelete(script, CScript([OP_CODESEPARATOR])) |
| 735 | |
| 736 | if (hashtype & 0x1f) == SIGHASH_NONE: |
| 737 | txtmp.vout = [] |
| 738 | |
| 739 | for i in range(len(txtmp.vin)): |
| 740 | if i != inIdx: |
| 741 | txtmp.vin[i].nSequence = 0 |
| 742 | |
| 743 | elif (hashtype & 0x1f) == SIGHASH_SINGLE: |
| 744 | outIdx = inIdx |
| 745 | if outIdx >= len(txtmp.vout): |
| 746 | return (None, "outIdx %d out of range (%d)" % (outIdx, len(txtmp.vout))) |
| 747 | |
| 748 | tmp = txtmp.vout[outIdx] |
| 749 | txtmp.vout = [] |
| 750 | for _ in range(outIdx): |
| 751 | txtmp.vout.append(CTxOut(nValue=CTxOutValue(), nAsset=CTxOutAsset())) |
| 752 | txtmp.vout.append(tmp) |
| 753 | |
| 754 | for i in range(len(txtmp.vin)): |
| 755 | if i != inIdx: |
| 756 | txtmp.vin[i].nSequence = 0 |
| 757 | |
| 758 | if hashtype & SIGHASH_ANYONECANPAY: |
| 759 | tmp = txtmp.vin[inIdx] |
| 760 | txtmp.vin = [] |
| 761 | txtmp.vin.append(tmp) |
| 762 | |
| 763 | # sighash serialization is different from non-witness serialization |
| 764 | # do manual sighash serialization: |
| 765 | s = b"" |
| 766 | s += struct.pack("<i", txtmp.nVersion) |
| 767 | # ELEMENTS: vin serialization is different from non-witness serialization (pegin/issuance |
| 768 | # flags are not set in the sighash) |
| 769 | s += ser_compact_size(len(txtmp.vin)) |
| 770 | for i in range(len(txtmp.vin)): |
| 771 | s += txtmp.vin[i].prevout.serialize() |
| 772 | s += ser_string(txtmp.vin[i].scriptSig) |
| 773 | s += struct.pack("<I", txtmp.vin[i].nSequence) |
| 774 | if not txtmp.vin[i].assetIssuance.isNull(): |
| 775 | s += txtmp.vin[i].assetIssuance.serialize() |
| 776 | |
| 777 | # If SIGHASH_RANGEPROOF is set, we need to add the rangeproof serialization after each output |
| 778 | if enable_sighash_rangeproof and hashtype & SIGHASH_RANGEPROOF: |
no test coverage detected