Ejemplo n.º 1
0
def generate_hashes_from_block(data_block, algorithm):
  sha256_hash = hashlib.sha256(hashlib.sha256(data_block).digest()).digest()[::-1]
  header_hash = ""
  if algorithm == 'scrypt':
    header_hash = scrypt.hash(data_block,data_block,1024,1,1,32)[::-1] 
  elif algorithm == 'SHA256':
    header_hash = sha256_hash
  elif algorithm == 'X11':
    try:
      exec('import %s' % "xcoin_hash")
    except ImportError:
      sys.exit("Cannot run X11 algorithm: module xcoin_hash not found")
    header_hash = xcoin_hash.getPoWHash(data_block)[::-1]
  elif algorithm == 'X13':
    try:
      exec('import %s' % "x13_hash")
    except ImportError:
      sys.exit("Cannot run X13 algorithm: module x13_hash not found")
    header_hash = x13_hash.getPoWHash(data_block)[::-1]
  elif algorithm == 'X15':
    try:
      exec('import %s' % "x15_hash")
    except ImportError:
      sys.exit("Cannot run X15 algorithm: module x15_hash not found")
    header_hash = x15_hash.getPoWHash(data_block)[::-1]
  elif algorithm == 'tribus':
    try:
      exec('import %s' % "tribus_hash")
    except ImportError:
      sys.exit("Cannot run tribus algorithm: module tribus_hash not found")
    header_hash = tribus_hash.getPoWHash(data_block)[::-1]
  return sha256_hash, header_hash
Ejemplo n.º 2
0
 def header_hash(cls, header):
     '''Given a header return the hash.'''
     import tribus_hash
     return tribus_hash.getPoWHash(header)
Ejemplo n.º 3
0
global PUBKEY_ADDRESS
global SCRIPT_ADDRESS
PUBKEY_ADDRESS = 30
SCRIPT_ADDRESS = 90


def rev_hex(s):
    return s.decode('hex')[::-1].encode('hex')


Hash = lambda x: hashlib.sha256(hashlib.sha256(x).digest()).digest()

#HashScrypt = lambda x: scrypt.hash(x, x, 1024, 1, 1, 32)

# Denarius PoW Tribus Hash
HashTribus = lambda x: tribus_hash.getPoWHash(x)

hash_encode = lambda x: x[::-1].encode('hex')

hash_decode = lambda x: x.decode('hex')[::-1]


def header_to_string(res):
    pbh = res.get('prev_block_hash')
    if pbh is None:
        pbh = '0' * 64

    return int_to_hex4(res.get('version')) \
           + rev_hex(pbh) \
           + rev_hex(res.get('merkle_root')) \
           + int_to_hex4(int(res.get('timestamp'))) \
Ejemplo n.º 4
0
 def pow_hash_header(self, header):
     return rev_hex(
         getPoWHash(
             self.serialize_header(header).decode('hex')).encode('hex'))