import pickle
import hashlib
import os
from helpers import BlockHelper as blockHelper


def computeHash(data):
    hash = hashlib.sha256()
    data = str(data).encode()
    hash.update(data)
    return hash.hexdigest()

def clearScreen():
    os.system('cls' if os.name == 'nt' else 'clear')

def createFile(fileloc):
    try:
        savefile = open(fileloc, "xb")
        savefile.close()
        return True
    except:
        return False

def saveFile(fileloc, data):
    savefile = open(fileloc, "ab")
    pickle.dump(data, savefile)
    savefile.close()

def resetFile(fileloc):
    savefile = open(fileloc, "wb")
    savefile.close()

def loadFile(fileloc):
    loadfile = open(fileloc ,"rb")

    objs = []
    while True:
        try:
            objs.append(pickle.load(loadfile))
        except EOFError:
            break

    return objs

def loginStartup(self):
    # TODO - check if there are unvalidated blocks
    blockHelper.validateMinedBlock(self)
    # TODO - check if there are any notifcations

    