MCPcopy Create free account
hub / github.com/ElementsProject/elements / SegwitV0SignatureMsg

Function SegwitV0SignatureMsg

test/functional/test_framework/script.py:814–883  ·  view source on GitHub ↗
(script, txTo, inIdx, hashtype, amount, enable_sighash_rangeproof=True)

Source from the content-addressed store, hash-verified

812# Note that this corresponds to sigversion == 1 in EvalScript, which is used
813# for version 0 witnesses.
814def SegwitV0SignatureMsg(script, txTo, inIdx, hashtype, amount, enable_sighash_rangeproof=True):
815
816 hashPrevouts = 0
817 hashSequence = 0
818 hashIssuance = 0
819 hashOutputs = 0
820 hashRangeproofs = 0
821
822 if not (hashtype & SIGHASH_ANYONECANPAY):
823 serialize_prevouts = bytes()
824 for i in txTo.vin:
825 serialize_prevouts += i.prevout.serialize()
826 hashPrevouts = uint256_from_str(hash256(serialize_prevouts))
827
828 if (not (hashtype & SIGHASH_ANYONECANPAY) and (hashtype & 0x1f) != SIGHASH_SINGLE and (hashtype & 0x1f) != SIGHASH_NONE):
829 serialize_sequence = bytes()
830 for i in txTo.vin:
831 serialize_sequence += struct.pack("<I", i.nSequence)
832 hashSequence = uint256_from_str(hash256(serialize_sequence))
833
834 if not (hashtype & SIGHASH_ANYONECANPAY):
835 serialize_issuance = bytes()
836 # TODO actually serialize issuances
837 for inp in txTo.vin:
838 if inp.assetIssuance.isNull():
839 serialize_issuance += b'\x00'
840 else:
841 serialize_issuance += inp.assetIssuance.serialize()
842 hashIssuance = uint256_from_str(hash256(serialize_issuance))
843
844 if ((hashtype & 0x1f) != SIGHASH_SINGLE and (hashtype & 0x1f) != SIGHASH_NONE):
845 serialize_outputs = bytes()
846 for o in txTo.vout:
847 serialize_outputs += o.serialize()
848 hashOutputs = uint256_from_str(hash256(serialize_outputs))
849
850 if enable_sighash_rangeproof and hashtype & SIGHASH_RANGEPROOF:
851 serialize_rangeproofs = bytes()
852 for wit in txTo.wit.vtxoutwit:
853 serialize_rangeproofs += ser_string(wit.vchRangeproof) + ser_string(wit.vchSurjectionproof)
854 hashRangeproofs = uint256_from_str(hash256(serialize_rangeproofs))
855
856 elif ((hashtype & 0x1f) == SIGHASH_SINGLE and inIdx < len(txTo.vout)):
857 serialize_outputs = txTo.vout[inIdx].serialize()
858 hashOutputs = uint256_from_str(hash256(serialize_outputs))
859
860 if enable_sighash_rangeproof and hashtype & SIGHASH_RANGEPROOF:
861 serialize_rangeproofs = b'\x00'
862 if len(txTo.wit.vtxoutwit) > inIdx:
863 wit = txTo.wit.vtxoutwit[inIdx]
864 serialize_rangeproofs = ser_string(wit.vchRangeproof) + ser_string(wit.vchSurjectionproof)
865 hashRangeproofs = uint256_from_str(hash256(serialize_rangeproofs))
866
867 ss = bytes()
868 ss += struct.pack("<i", txTo.nVersion)
869 ss += ser_uint256(hashPrevouts)
870 ss += ser_uint256(hashSequence)
871 ss += ser_uint256(hashIssuance)

Callers 2

default_sigmsgFunction · 0.90
SegwitV0SignatureHashFunction · 0.85

Calls 6

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

Tested by

no test coverage detected