Cuando hago por ejemplo print(10 * (10**18))
no hay problema, pero cuando cambio el primer numero por una variable, por ejemplo print(amount * (10 ** 18))
obtengo un error de memoria, aunque amount
valga 1
.
Codigo:
Funcion 1:
currencies = {'bnb': 18, 'urub': 8}
def to_wei(amount:int, currency:str):
decimals = currencies[currency.lower()]
return amount * (10 ** decimals)
La funcion 1 es llamdada dentro de la funcion 2:
async def transfer_bnb(_from=None, to=None, key=None, amount=0):
print(uwutils.to_wei(amount, "BNB"))
try:
estimated_gas = w3.eth.estimate_gas({
'nonce': w3.eth.get_transaction_count(_from),
'gasPrice': w3.eth.gas_price,
'to': to,
'from': _from,
'value': uwutils.to_wei(amount, "BNB")
})
signed_txt = w3.eth.account.sign_transaction({
'nonce': w3.eth.get_transaction_count(_from),
'gasPrice': w3.eth.gas_price,
'gas': estimated_gas,
'to': to,
'from': _from,
'value': uwutils.to_wei(amount, "BNB")
}, key)
w3.eth.send_raw_transaction(signed_txt.rawTransaction)
return {'error': False}
except ValueError:
return {'error': True, 'message':'Not enough funds'}
La funcion 2 es llamada dentro de una funcion asincrona:
async def routine(check_var, amount_entry, address_entry, account):
currency = check_var.get()
if currency == 'NONE':
pass
elif currency == 'BNB':
amount = amount_entry.get()
reciever = address_entry.get()
if w3.toChecksumAddress(reciever):
print(await tx.transfer_bnb(_from=account.public_key, to=reciever, key=account.private_key,
amount=amount))
else:
showerror("Error", "Wrong address")
elif currency == 'URUB':
amount = amount_entry.get()
reciever = address_entry.get()
if w3.toChecksumAddress(reciever):
print(await tx.transfer_urub(_from=account.public_key, to=reciever, key=account.private_key,
amount=amount))
else:
showerror("Error", "Wrong address")
check_var es una variable string de tkinter, y las entradas son entradas comunes de tkinter tambien.
Por ultimo la rutina se ejecuta en un evento de button:
def send_button_click():
loop = asyncio.get_event_loop()
loop.run_until_complete(routine(check_var=check_var, amount_entry=amount_entry, address_entry=address_entry, account=account))
currencies
?