# Untitled

a guest
Dec 22nd, 2017
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import struct
2. import StringIO
3. import time
4.
5. bl="01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1f02a83304cdd73c5a0801020304050607080d2f6e6f64655374726174756d2fffffffff0201aaa1b4000000001976a914071206342b740094bec1a3d542a7790f81c5beb588ac6716d301000000001976a9143b78a5a18263fe31ae6d2794a3d488c0e13561a888ac00000000"
6.
7. def uint1(stream):
9.
10. def uint2(stream):
12.
13. def uint4(stream):
15.
16. def uint8(stream):
18.
19. def hash256(stream):
20.     return "".join(map(lambda x: "%02x" % ord(x), stream.read(32)))
21.
22. def varint(stream):
24.     if (r <= 252):
25.         return r
26.     elif (r == 253):
27.         return uint2(stream)
28.     elif (r == 254):
29.         return uint4(stream)
30.     else:
31.         return uint8(stream)
32.
33. def varhex(stream, n):
34.     return "".join(map(lambda x: "%02x" % ord(x), stream.read(n)))
35.
36. def serializedint(stream):
38.     r = 0
39.     for i in range(0, n):
40.         r = r + (ord(stream.read(1)) << (8 * i))
41.     return r
42.
43. s = StringIO.StringIO(bl.decode("hex"))
44.
45. ntx = 1
46. print "nTransaction:", ntx
47. for i in range(0, ntx):
48.     hdr = "[Tx%02d] " % i
49.     print hdr, "version:", uint4(s)
50.     tx_in_c = varint(s)
51.     print hdr, "tx_in_count:", tx_in_c
52.     for txi in range(0, tx_in_c):
53.         txhdr = "[In%02d]" % txi
54.         print hdr, txhdr, "previous_output:", varhex(s, 36)
55.         c = varint(s)
56.         print hdr, txhdr, "script_bytes:" , c
57.         scr = varhex(s, c)
58.         print hdr, txhdr, "signature_script:", scr
59.         if txi == 0:
60.             print hdr, txhdr, "  serializedBlockHeight:", serializedint(StringIO.StringIO(scr.decode("hex")))
61.         print hdr, txhdr, "sequence:", "%08x" % uint4(s)
62.
63.     tx_out_c = varint(s)
64.     print hdr, "tx_out_count:", tx_out_c
65.     for txo in range(0, tx_out_c):
66.         txhdr = "[Out%02d]" % txo
67.         print hdr, txhdr, "value:", uint8(s)
68.         c = varint(s)
69.         print hdr, txhdr, "pk_script _bytes:" , c
70.         print hdr, txhdr, "pk_script :", varhex(s, c)
71.
72.     print hdr, "lock_time:", uint4(s)
73.