def det_hash(x): """Deterministically takes sha256 of dict, list, int, or string.""" #def det_list(l): return '[%s]' % ','.join(map(det, sorted(l))) #def det_dict(x): # list_=map(lambda p: det(p[0]) + ':' + det(p[1]), sorted(x.items())) # return '{%s}' % ','.join(list_) #def det(x): return {list: det_list, dict: det_dict}.get(type(x), str)(x) return hash_(package(x, sort_keys=True))
def det_hash(x): # deterministically takes sha256 of dict, list, int, or string def det_list(l): return '[%s]' % ','.join(map(det, sorted(l))) def det_dict(x): list_ = map(lambda p: det(p[0]) + ':' + det(p[1]), sorted(x.items())) return '{%s}' % ','.join(list_) def det(x): return {list: det_list, dict: det_dict}.get(type(x), str)(x) return hashlib.sha256(det(unpackage(package(x)))).hexdigest()
def det_hash(x): # deterministically takes sha256 of dict, list, int, or string def det_list(l): return "[%s]" % ",".join(map(det, sorted(l))) def det_dict(x): list_ = map(lambda p: det(p[0]) + ":" + det(p[1]), sorted(x.items())) return "{%s}" % ",".join(list_) def det(x): return {list: det_list, dict: det_dict}.get(type(x), str)(x) return custom.hash_(det(unpackage(package(x))))
def det_hash(x): #deterministically takes sha256 of dict, list, int, or string def det_list(l): return '[%s]' % ','.join(map(det, sorted(l))) def det_dict(x): list_ = map(lambda p: det(p[0]) + ':' + det(p[1]), sorted(x.items())) return '{%s}' % ','.join(list_) def det(x): return {list: det_list, dict: det_dict}.get(type(x), str)(x) return custom.hash_(det(unpackage(package(x))))
def pretty(dic): """Pretty print a json-compatible dictionary.""" print package(dic, sort_keys=True, indent=4)
def hash_(x): return hashlib.sha256(package(x, sort_keys=True)).hexdigest()
def db_put(key, dic, DB={}): dic = unpackage(package(dic)) #keeps it deterministic. return s_to_db({'type': 'put', 'args': [str(key), dic]})
def det_hash(x): """Deterministically takes sha256 of dict, list, int, or string.""" #x=unpackage(package(x)) #log('in det hash: ' +str(package(x, sort_keys=True))) return hash_(package(x, sort_keys=True))
def pretty(dic): print_(package(dic, sort_keys=True, indent=4))
def det_hash(x): """Deterministically takes sha256 of dict, list, int, or string.""" return hash_(package(x, sort_keys=True))
def raw_write_page(file, txt): with open('db/' + file, 'w') as myfile: myfile.write(package(txt))
def hash_(x): return hashlib.sha256(package(x, sort_keys=True)).hexdigest() def guess(n):
def raw_write_page(file, txt): with open('db/'+file, 'w') as myfile: myfile.write(package(txt))
def db_put(key, dic, DB): return DB['db'].Put(str(key), package(dic))
def det_hash(x):#deterministically hash def det(x): return {list: (lambda l: '[%s]' % ','.join(map(det, sorted(l)))), dict:(lambda x: '{%s}' % ','.join(map(lambda p: det(p[0]) + ':' + det(p[1]), sorted(x.items()))))}.get(type(x), str)(x) return hashlib.sha256(det(unpackage(package(x)))).hexdigest()
def put(key, val): return state.update(key, rlp.encode(package(val))) def delete(key): return state.delete(key)
def pretty(dic): print package(dic, sort_keys=True, indent=4)
def db_put(key, dic, DB={}): dic=unpackage(package(dic))#keeps it deterministic. return s_to_db({'type':'put', 'args':[str(key), dic]})
def put(key, val): return state.update(key, rlp.encode(package(val)))