diff --git a/.github/instructions/*.instructions.md b/.github/instructions/*.instructions.md new file mode 100644 index 00000000..0a7505c0 --- /dev/null +++ b/.github/instructions/*.instructions.md @@ -0,0 +1,92 @@ +import hashlib +import struct +import binascii + +def decode_varint(s): + i = s.read(1)[0] + if i < 0xfd: + return i + elif i == 0xfd: + return struct.unpack(" 93484 sats) +# ScriptLen: 16 (22 bytes) +# Script: 00140ef43d2a1b31bc5a968edb6fe84d2f303291e691 (P2WPKH) +# Witness: +# Item Count: 02 +# Item 1 Size: 46 (70 bytes?) -> 0x46 is 70. +# Item 1: 3043022069b74eb2afb03d4a7c9d31138d629f0f95f63d2a6f2b6895d8af5c25336c4b76021f1748f96644a08cb02d406915f2dcf2ad87dc253fe0b49b2f431462f21bade +# Item 2 Size: 21 (33 bytes) +# Item 2: 03bc78d9e2f73cb46fb1c33469619ab9de8ed1dc909874f0c0907787e81fdd426a +# Locktime: 00000000 + +# Legacy Serialization (for TxID): +# Version (4) + Input Count (varint) + Inputs (PrevHash+Index+ScriptLen+Script+Seq) + Output Count (varint) + Outputs (Amount+ScriptLen+Script) + Locktime (4) +# Version: 02000000 +# InCnt: 01 +# Input: 59f1...42 (Rev PrevHash) + 00000000 + 00 + fdffffff +# OutCnt: 01 +# Output: 2c6d010000000000 + 16 + 00140ef43d2a1b31bc5a968edb6fe84d2f303291e691 +# Locktime: 00000000 + +legacy_hex = "02000000" + "01" + "42c65fa705f326604c6e10cfbc3b553d3ab5a695fc3874d50b87535cb45df159" + "00000000" + "00" + "fdffffff" + "01" + "2c6d010000000000" + "16" + "00140ef43d2a1b31bc5a968edb6fe84d2f303291e691" + "00000000" + +def double_sha256(h): + b = binascii.unhexlify(h) + return hashlib.sha256(hashlib.sha256(b).digest()).hexdigest() + +txid = double_sha256(legacy_hex) +# TxID is little endian in display usually, so reverse it +txid_display = "".join(reversed([txid[i:i+2] for i in range(0, len(txid), 2)])) + +print(f"{txid_display=}")