MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / SegwitVersion1SignatureHash

Function SegwitVersion1SignatureHash

test/functional/test_framework/script.py:650–692  ·  view source on GitHub ↗
(script, txTo, inIdx, hashtype, amount)

Source from the content-addressed store, hash-verified

648# Note that this corresponds to sigversion == 1 in EvalScript, which is used
649# for version 0 witnesses and all the FORKID transactions.
650def SegwitVersion1SignatureHash(script, txTo, inIdx, hashtype, amount):
651
652 hashPrevouts = 0
653 hashSequence = 0
654 hashOutputs = 0
655
656 if not (hashtype & SIGHASH_ANYONECANPAY):
657 serialize_prevouts = bytes()
658 for i in txTo.vin:
659 serialize_prevouts += i.prevout.serialize()
660 hashPrevouts = uint256_from_str(hash256(serialize_prevouts))
661
662 if (not (hashtype & SIGHASH_ANYONECANPAY) and (hashtype & 0x1f) != SIGHASH_SINGLE and (hashtype & 0x1f) != SIGHASH_NONE):
663 serialize_sequence = bytes()
664 for i in txTo.vin:
665 serialize_sequence += struct.pack("<I", i.nSequence)
666 hashSequence = uint256_from_str(hash256(serialize_sequence))
667
668 if ((hashtype & 0x1f) != SIGHASH_SINGLE and (hashtype & 0x1f) != SIGHASH_NONE):
669 serialize_outputs = bytes()
670 for o in txTo.vout:
671 serialize_outputs += o.serialize()
672 hashOutputs = uint256_from_str(hash256(serialize_outputs))
673 elif ((hashtype & 0x1f) == SIGHASH_SINGLE and inIdx < len(txTo.vout)):
674 serialize_outputs = txTo.vout[inIdx].serialize()
675 hashOutputs = uint256_from_str(hash256(serialize_outputs))
676
677 if hashtype & SIGHASH_FORKID:
678 hashtype |= FORKID_BTG << 8
679
680 ss = bytes()
681 ss += struct.pack("<i", txTo.nVersion)
682 ss += ser_uint256(hashPrevouts)
683 ss += ser_uint256(hashSequence)
684 ss += txTo.vin[inIdx].prevout.serialize()
685 ss += ser_string(script)
686 ss += struct.pack("<q", amount)
687 ss += struct.pack("<I", txTo.vin[inIdx].nSequence)
688 ss += ser_uint256(hashOutputs)
689 ss += struct.pack("<i", txTo.nLockTime)
690 ss += struct.pack("<I", hashtype)
691
692 return hash256(ss)

Callers 3

sign_p2pk_witness_inputFunction · 0.90

Calls 5

uint256_from_strFunction · 0.85
ser_uint256Function · 0.85
ser_stringFunction · 0.85
hash256Function · 0.70
serializeMethod · 0.45

Tested by 2