mirror of
https://github.com/bitcoin/bips.git
synced 2024-11-19 01:40:05 +01:00
[BIP-119] Clarify Endianness of serializations
This commit is contained in:
parent
c8c8e27c2c
commit
ec3688a610
@ -217,7 +217,8 @@ def get_default_check_template_precomputed_data(self):
|
||||
# If there are no scriptSigs we do not need to precompute a hash
|
||||
if any(inp.scriptSig for inp in self.vin):
|
||||
result["scriptSigs"] = sha256(b"".join(ser_string(inp.scriptSig) for inp in self.vin))
|
||||
# The same value is also pre-computed for and defined in BIP-341 and can be shared
|
||||
# The same value is also pre-computed for and defined in BIP-341 and can be shared.
|
||||
# each nSequence is packed as 4 byte unsigned integer (little endian)
|
||||
result["sequences"] = sha256(b"".join(struct.pack("<I", inp.nSequence) for inp in self.vin))
|
||||
# The same value is also pre-computed for and defined in BIP-341 and can be shared
|
||||
result["outputs"] = sha256(b"".join(out.serialize() for out in self.vout))
|
||||
@ -228,21 +229,21 @@ def get_default_check_template_hash(self, nIn, precomputed = None):
|
||||
if precomputed == None:
|
||||
precomputed = self.get_default_check_template_precomputed_data()
|
||||
r = b""
|
||||
# pack as 4 byte signed integer
|
||||
# pack as 4 byte signed integer (little endian)
|
||||
r += struct.pack("<i", self.nVersion)
|
||||
# pack as 4 byte unsigned integer
|
||||
# pack as 4 byte unsigned integer (little endian)
|
||||
r += struct.pack("<I", self.nLockTime)
|
||||
# we do not include the hash in the case where there is no
|
||||
# scriptSigs
|
||||
if "scriptSigs" in precomputed:
|
||||
r += precomputed["scriptSigs"]
|
||||
# pack as 4 byte unsigned integer
|
||||
# pack as 4 byte unsigned integer (little endian)
|
||||
r += struct.pack("<I", len(self.vin))
|
||||
r += precomputed["sequences"]
|
||||
# pack as 4 byte unsigned integer
|
||||
# pack as 4 byte unsigned integer (little endian)
|
||||
r += struct.pack("<I", len(self.vout))
|
||||
r += precomputed["outputs"]
|
||||
# pack as 4 byte unsigned integer
|
||||
# pack as 4 byte unsigned integer (little endian)
|
||||
r += struct.pack("<I", nIn)
|
||||
return sha256(r)
|
||||
</source>
|
||||
|
Loading…
Reference in New Issue
Block a user