CoolFace
Apppublic

Omnibus-archive/decentral-test-mod

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
utils.py20 linesDownload Raw Back to node
1import json2 3from Crypto.Hash import SHA2564 5 6def calculate_hash(data) -> str:7    if type(data) == str:8        data = bytearray(data, "utf-8")9    h = SHA256.new()10    h.update(data)11    return h.hexdigest()12 13 14def convert_transaction_data_to_bytes(transaction_data: dict):15    new_transaction_data = transaction_data.copy()16    new_transaction_data["sender"] = str(transaction_data["sender"])17    new_transaction_data["receiver"] = str(transaction_data["receiver"])18    new_transaction_data["amount"] = str(transaction_data["amount"])19    return json.dumps(new_transaction_data, indent=2).encode('utf-8')20