Guest User

Untitled

a guest
Dec 22nd, 2017
121
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="04000000ad43cd48e6c354714066b299cd7809309894ef211b04decc3705ac2c0cb52f8c9bdbbccb4dd6fa58a3d68d8f75ec502cbd9748987b9e41c5751093921270de57d5ff3c5aca3f781d2aaaf00c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1f02483404d4ff3c5a0808000000000000000d2f6e6f64655374726174756d2fffffffff02df26d1b6000000001976a914071206342b740094bec1a3d542a7790f81c5beb588ac29bdd801000000001976a9143b78a5a18263fe31ae6d2794a3d488c0e13561a888ac00000000"
  6.  
  7. def uint1(stream):
  8.     return ord(stream.read(1))
  9. def uint2(stream):
  10.     return struct.unpack('H', stream.read(2))[0]
  11.  
  12. def uint4(stream):
  13.     return struct.unpack('I', stream.read(4))[0]
  14.  
  15. def uint8(stream):
  16.     return struct.unpack('Q', stream.read(8))[0]
  17.  
  18. def hash256(stream):
  19.     return "".join(map(lambda x: "%02x" % ord(x), stream.read(32)))
  20.  
  21. def varint(stream):
  22.     r = ord(stream.read(1))
  23.     if (r <= 252):
  24.         return r
  25.     elif (r == 253):
  26.         return uint2(stream)
  27.     elif (r == 254):
  28.         return uint4(stream)
  29.     else:
  30.         return uint8(stream)
  31.  
  32. def varhex(stream, n):
  33.     return "".join(map(lambda x: "%02x" % ord(x), stream.read(n)))
  34.  
  35. def serializedint(stream):
  36.     n = ord(stream.read(1))
  37.     r = 0
  38.     for i in range(0, n):
  39.         r = r + (ord(stream.read(1)) << (8 * i))
  40.     return r
  41.  
  42. s = StringIO.StringIO(bl.decode("hex"))
  43.  
  44. print "[BlockHeader]"
  45. print "Version:", "%s" % uint4(s)
  46. print "hashPrevBlock:", hash256(s)
  47. print "hashMerkleRoot:", hash256(s)
  48. t = uint4(s)
  49. print "Time:", t, time.strftime("%b %d %Y %H:%M:%S", time.localtime(t))
  50. print "Bits:", "%08x" % uint4(s)
  51. print "Nonce:", "%08x" % uint4(s)
  52.  
  53. print "------------------------"
  54. ntx = uint1(s)
  55. print "nTransaction:", ntx
  56. for i in range(0, ntx):
  57.     hdr = "[Tx%02d] " % i
  58.     print hdr, "version:", uint4(s)
  59.     tx_in_c = varint(s)
  60.     print hdr, "tx_in_count:", tx_in_c
  61.     for txi in range(0, tx_in_c):
  62.         txhdr = "[In%02d]" % txi
  63.         print hdr, txhdr, "previous_output:", varhex(s, 36)
  64.         c = varint(s)
  65.         print hdr, txhdr, "script_bytes:" , c
  66.         scr = varhex(s, c)
  67.         print hdr, txhdr, "signature_script:", scr
  68.         if txi == 0:
  69.             print hdr, txhdr, "  serializedBlockHeight:", serializedint(StringIO.StringIO(scr.decode("hex")))
  70.         print hdr, txhdr, "sequence:", "%08x" % uint4(s)
  71.  
  72.     tx_out_c = varint(s)
  73.     print hdr, "tx_out_count:", tx_out_c
  74.     for txo in range(0, tx_out_c):
  75.         txhdr = "[Out%02d]" % txo
  76.         print hdr, txhdr, "value:", uint8(s)
  77.         c = varint(s)
  78.         print hdr, txhdr, "pk_script _bytes:" , c
  79.         print hdr, txhdr, "pk_script :", varhex(s, c)
  80.  
  81.     print hdr, "lock_time:", uint4(s)
  82.  
  83. rest = s.read()
  84. print len(rest)
RAW Paste Data