import calendar
import time
import binascii
from hashlib import sha256

def hash2(a, b):
    # Reverse inputs before and after hashing
    # due to big-endian / little-endian nonsense
    a1 = a.decode('hex')[::-1]
    b1 = b.decode('hex')[::-1]
    h = hashlib.sha256(hashlib.sha256(a1+b1).digest()).digest()
    return h[::-1].encode('hex')

def singleSha256(hex):
   bin = binascii.unhexlify(hex)
   hash = sha256(bin).digest()
   #hash2 = sha256(hash).digest()
   print("Input Hex: "+str(hex,"ascii"))
   print("SHA256:\n   "+str(binascii.hexlify(hash),"ascii"))
   #print("Double-SHA256:\n   "+str(binascii.hexlify(hash2),"ascii"))
   return hash

def doubleSha256(hex):
   bin = binascii.unhexlify(hex)
   hash = sha256(bin).digest()
   hash2 = sha256(hash).digest()
   print("Input Hex: "+str(hex,"ascii"))
   print("SHA256:\n   "+str(binascii.hexlify(hash),"ascii"))
   print("Double-SHA256:\n   "+str(binascii.hexlify(hash2),"ascii"))
   return hash2


#get the current time since epoch
current_time = calendar.timegm(time.gmtime())
#form the set1
list_data1 = ['0000000036dc2ce23cdd934eff4bae120155de8b8712de8489c8870b06e334ff', 'c0ba5ba1c5ba02fb02c4ea93ec16cae7ea1994b5b3f9ef0e293b841081eb3003', str(current_time), str(1.0000), str(124867778)]
print("list_data1: ", list_data1)
# produce string
str1 = ''.join(list_data1)
print("str1: ", str1)

#get the current time since epoch
current_time = calendar.timegm(time.gmtime())
#form the set2
list_data2 = ['00000000d84724559f1691d916b2ed63a44884d495d155197647ce7667116b16', '69a14e6b050d10d6621faee3dac6682809feb0ffa76320b33c5c09f1059f06c7', str(current_time), str(1.0000), str(124867778)]
print("list_data2: ", list_data1)
# produce string
str2 = ''.join(list_data2)
print("str2: ", str2)

hex1 = "b5f60977102f95a9ed855b61acec86e2e434248b38c5f263ccf708a302832f3c"
#print("hex1 is: ",hex1)
#sha_left = singleSha256(hex1)
#print("sha_left is: ", str(binascii.hexlify(sha_left),"ascii"))

hex2 = "e6922d44c520c52dca2cd5300784af55944c11839684e5c1671d9b330f871f55"
#sha_right = singleSha256(hex2)
#print("sha_right is: ", str(binascii.hexlify(sha_right),"ascii"))

#root = singleSha256(str(binascii.hexlify(hex1),"ascii") + binascii.hexlify(hex2),"ascii")
root = hash2(hex1, hex2)

#root = singleSha256(hex1 + hex2)
#print("root is: ", str(binascii.hexlify(root),"ascii"))


