Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import struct
- import StringIO
- import time
- bl="01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1f02a83304cdd73c5a0801020304050607080d2f6e6f64655374726174756d2fffffffff0201aaa1b4000000001976a914071206342b740094bec1a3d542a7790f81c5beb588ac6716d301000000001976a9143b78a5a18263fe31ae6d2794a3d488c0e13561a888ac00000000"
- def uint1(stream):
- return ord(stream.read(1))
- def uint2(stream):
- return struct.unpack('H', stream.read(2))[0]
- def uint4(stream):
- return struct.unpack('I', stream.read(4))[0]
- def uint8(stream):
- return struct.unpack('Q', stream.read(8))[0]
- def hash256(stream):
- return "".join(map(lambda x: "%02x" % ord(x), stream.read(32)))
- def varint(stream):
- r = ord(stream.read(1))
- if (r <= 252):
- return r
- elif (r == 253):
- return uint2(stream)
- elif (r == 254):
- return uint4(stream)
- else:
- return uint8(stream)
- def varhex(stream, n):
- return "".join(map(lambda x: "%02x" % ord(x), stream.read(n)))
- def serializedint(stream):
- n = ord(stream.read(1))
- r = 0
- for i in range(0, n):
- r = r + (ord(stream.read(1)) << (8 * i))
- return r
- s = StringIO.StringIO(bl.decode("hex"))
- ntx = 1
- print "nTransaction:", ntx
- for i in range(0, ntx):
- hdr = "[Tx%02d] " % i
- print hdr, "version:", uint4(s)
- tx_in_c = varint(s)
- print hdr, "tx_in_count:", tx_in_c
- for txi in range(0, tx_in_c):
- txhdr = "[In%02d]" % txi
- print hdr, txhdr, "previous_output:", varhex(s, 36)
- c = varint(s)
- print hdr, txhdr, "script_bytes:" , c
- scr = varhex(s, c)
- print hdr, txhdr, "signature_script:", scr
- if txi == 0:
- print hdr, txhdr, " serializedBlockHeight:", serializedint(StringIO.StringIO(scr.decode("hex")))
- print hdr, txhdr, "sequence:", "%08x" % uint4(s)
- tx_out_c = varint(s)
- print hdr, "tx_out_count:", tx_out_c
- for txo in range(0, tx_out_c):
- txhdr = "[Out%02d]" % txo
- print hdr, txhdr, "value:", uint8(s)
- c = varint(s)
- print hdr, txhdr, "pk_script _bytes:" , c
- print hdr, txhdr, "pk_script :", varhex(s, c)
- print hdr, "lock_time:", uint4(s)
- rest = s.read()
- print len(rest)
Add Comment
Please, Sign In to add comment