from web3 import Web3
import json
from solc import compile_files, link_code, compile_source
import encriptamiento as ec
import generador_frase as gf

infura_url = "https://mainnet.infura.io/v3/98ef5cb0f48241568905e8bfd41ca55c"

global web3

web3 = Web3(Web3.HTTPProvider(infura_url))

print(web3.isConnected())

def crear_cuenta(password):
    try:
        account = web3.eth.account.create()
        address = account.address
        keystore = account.encrypt(password)
        encrypted_password = ec.hash_password(password)
        frase = gf.generar_frase()
        encrypted_phrase = ec.hash_phrase(frase)
        print(account)
        print(keystore)
        print(encrypted_password)
        datos = {'address': address,'password':encrypted_password, 'phrase': encrypted_phrase,"keystore" :keystore, "violence_images" :[], "no_violence_images" : []}
        resultado = [True, datos, frase]
    except Exception as e:
        resultado = [False, None]
    return resultado
