Consensus-correct SignatureHash Returns (hash, err) to precisely match the consensus-critical behavior of the SIGHASH_SINGLE bug. (inIdx is *not* checked for validity) If you're just writing wallet software you probably want SignatureHash() instead.
(script, txTo, inIdx, hashtype)
| 918 | |
| 919 | |
| 920 | def RawSignatureHash(script, txTo, inIdx, hashtype): |
| 921 | """Consensus-correct SignatureHash |
| 922 | |
| 923 | Returns (hash, err) to precisely match the consensus-critical behavior of |
| 924 | the SIGHASH_SINGLE bug. (inIdx is *not* checked for validity) |
| 925 | |
| 926 | If you're just writing wallet software you probably want SignatureHash() |
| 927 | instead. |
| 928 | """ |
| 929 | HASH_ONE = b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
| 930 | |
| 931 | if inIdx >= len(txTo.vin): |
| 932 | return (HASH_ONE, "inIdx %d out of range (%d)" % (inIdx, len(txTo.vin))) |
| 933 | txtmp = bitcoin.core.CMutableTransaction.from_tx(txTo) |
| 934 | |
| 935 | for txin in txtmp.vin: |
| 936 | txin.scriptSig = b'' |
| 937 | txtmp.vin[inIdx].scriptSig = FindAndDelete(script, CScript([OP_CODESEPARATOR])) |
| 938 | |
| 939 | if (hashtype & 0x1f) == SIGHASH_NONE: |
| 940 | txtmp.vout = [] |
| 941 | |
| 942 | for i in range(len(txtmp.vin)): |
| 943 | if i != inIdx: |
| 944 | txtmp.vin[i].nSequence = 0 |
| 945 | |
| 946 | elif (hashtype & 0x1f) == SIGHASH_SINGLE: |
| 947 | outIdx = inIdx |
| 948 | if outIdx >= len(txtmp.vout): |
| 949 | return (HASH_ONE, "outIdx %d out of range (%d)" % (outIdx, len(txtmp.vout))) |
| 950 | |
| 951 | tmp = txtmp.vout[outIdx] |
| 952 | txtmp.vout = [] |
| 953 | for i in range(outIdx): |
| 954 | txtmp.vout.append(bitcoin.core.CTxOut()) |
| 955 | txtmp.vout.append(tmp) |
| 956 | |
| 957 | for i in range(len(txtmp.vin)): |
| 958 | if i != inIdx: |
| 959 | txtmp.vin[i].nSequence = 0 |
| 960 | |
| 961 | if hashtype & SIGHASH_ANYONECANPAY: |
| 962 | tmp = txtmp.vin[inIdx] |
| 963 | txtmp.vin = [] |
| 964 | txtmp.vin.append(tmp) |
| 965 | |
| 966 | txtmp.wit = bitcoin.core.CTxWitness() |
| 967 | s = txtmp.serialize() |
| 968 | s += struct.pack(b"<i", hashtype) |
| 969 | |
| 970 | hash = bitcoin.core.Hash(s) |
| 971 | |
| 972 | return (hash, None) |
| 973 | |
| 974 | SIGVERSION_BASE = 0 |
| 975 | SIGVERSION_WITNESS_V0 = 1 |
no test coverage detected