Handle transaction amount entered as a float not to be changed by the float implementation
Hi,
I have a bug on a tx (manual and automated) :
Trying to empty the account (141.89) :
silkaj -p g1.cgeek.fr --auth-file --file ~/g1-cotis-master.old/auth_g1cotis/GTsYayS6wkrKUrRhVBR6avybBqSAmu3betnSYojyiskp.auth tx --output HeZJHAc58PB8PjE3aX9NydeALCdQZkECkrmz1ViZjXo4 --amount 141.89
╒════════════════════════════╤══════════════════════════════════════════════╕
│ pubkey’s balance before tx │ 141.89 Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ tx amount (unit) │ 141.89 Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ tx amount (relative) │ 14.0904 UD Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ pubkey’s balance after tx │ 1.8189894035458565e-14 Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ from (pubkey) │ GTsYayS6wkrKUrRhVBR6avybBqSAmu3betnSYojyiskp │
├────────────────────────────┼──────────────────────────────────────────────┤
│ to (pubkey) │ HeZJHAc58PB8PjE3aX9NydeALCdQZkECkrmz1ViZjXo4 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ comment │ │
╘════════════════════════════╧══════════════════════════════════════════════╛
Do you confirm sending this transaction? [yes/no]: yes
Generate Transaction:
- From: GTsYayS6wkrKUrRhVBR6avybBqSAmu3betnSYojyiskp
- To: HeZJHAc58PB8PjE3aX9NydeALCdQZkECkrmz1ViZjXo4
- Amount: 141.89
Traceback (most recent call last):
File "/home/dunitertest/.local/share/virtualenvs/silkaj-EzvhOxyi/bin/silkaj", line 7, in <module>
exec(compile(f.read(), __file__, 'exec'))
File "/home/dunitertest/silkaj/bin/silkaj", line 23, in <module>
cli(obj={})
File "/home/dunitertest/.local/share/virtualenvs/silkaj-EzvhOxyi/lib/python3.7/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/dunitertest/.local/share/virtualenvs/silkaj-EzvhOxyi/lib/python3.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/dunitertest/.local/share/virtualenvs/silkaj-EzvhOxyi/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/dunitertest/.local/share/virtualenvs/silkaj-EzvhOxyi/lib/python3.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/dunitertest/.local/share/virtualenvs/silkaj-EzvhOxyi/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/dunitertest/silkaj/silkaj/tools.py", line 70, in wrapper
return loop.run_until_complete(f(*args, **kwargs))
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete
return future.result()
File "/home/dunitertest/silkaj/silkaj/tx.py", line 99, in send_transaction
key, issuer_pubkey, tx_amount, outputAddresses, comment, outputbackchange
File "/home/dunitertest/silkaj/silkaj/tx.py", line 237, in handle_intermediaries_transactions
OutputbackChange,
File "/home/dunitertest/silkaj/silkaj/tx.py", line 277, in generate_and_send_transaction
OutputbackChange,
File "/home/dunitertest/silkaj/silkaj/tx.py", line 329, in generate_transaction_document
generate_output(listoutput, curentUnitBase, AmountTransfered, outputAddress)
File "/home/dunitertest/silkaj/silkaj/tx.py", line 364, in generate_output
outputAmount = truncBase(rest, unitbase)
File "/home/dunitertest/silkaj/silkaj/tx.py", line 392, in truncBase
return math.trunc(amount / pow) * pow
ZeroDivisionError: float division by zero
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0xb59bcd98>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0xb581c8b8>, 559035.958879131)]']
connector: <aiohttp.connector.TCPConnector object at 0xb58e3a50>
After this, I answer "no" to keep the sources. So I don't know if the tx would work or not.
with --allSources on 0.7.1 :
silkaj -p g1.cgeek.fr --auth-file tx --output HeZJHAc58PB8PjE3aX9NydeALCdQZkECkrmz1ViZjXo4 --allSources
╒════════════════════════════╤══════════════════════════════════════════════╕
│ pubkey’s balance before tx │ 141.89 Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ tx amount (unit) │ 141.89 Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ tx amount (relative) │ 14.0904 UD Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ pubkey’s balance after tx │ 0.0 Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ from (pubkey) │ GTsYayS6wkrKUrRhVBR6avybBqSAmu3betnSYojyiskp │
├────────────────────────────┼──────────────────────────────────────────────┤
│ to (pubkey) │ HeZJHAc58PB8PjE3aX9NydeALCdQZkECkrmz1ViZjXo4 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ comment │ │
╘════════════════════════════╧══════════════════════════════════════════════╛
Do you confirm sending this transaction? [yes/no]: no
I think the tx would work.
tx on a partial amount:
silkaj -p g1.cgeek.fr --auth-file tx --output HeZJHAc58PB8PjE3aX9NydeALCdQZkECkrmz1ViZjXo4 --amount 18
╒════════════════════════════╤══════════════════════════════════════════════╕
│ pubkey’s balance before tx │ 141.89 Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ tx amount (unit) │ 18.0 Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ tx amount (relative) │ 1.7875 UD Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ pubkey’s balance after tx │ 123.89 Ğ1 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ from (pubkey) │ GTsYayS6wkrKUrRhVBR6avybBqSAmu3betnSYojyiskp │
├────────────────────────────┼──────────────────────────────────────────────┤
│ to (pubkey) │ HeZJHAc58PB8PjE3aX9NydeALCdQZkECkrmz1ViZjXo4 │
├────────────────────────────┼──────────────────────────────────────────────┤
│ comment │ │
╘════════════════════════════╧══════════════════════════════════════════════╛
Do you confirm sending this transaction? [yes/no]: no
I've tried with 18, 100, 141,88, the "pubkey's balance after tx" is always correct.
with v0.6.5, total amount :
silkaj -p g1.cgeek.fr --auth-file tx --output HeZJHAc58PB8PjE3aX9NydeALCdQZkECkrmz1ViZjXo4 --amount 141.89
Traceback (most recent call last):
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/bin/silkaj", line 7, in <module>
exec(compile(f.read(), __file__, 'exec'))
File "/home/thomas/silkaj-v0.6.5/bin/silkaj", line 25, in <module>
manage_cmd()
File "/home/thomas/silkaj-v0.6.5/silkaj/cli_tools.py", line 85, in manage_cmd
cli(obj={})
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/thomas/silkaj-v0.6.5/silkaj/cli_tools.py", line 183, in cliTransaction
amount, amountud, allsources, output, comment, outputbackchange, yes
File "/home/thomas/silkaj-v0.6.5/silkaj/tx.py", line 49, in send_transaction
pubkey_amount = get_amount_from_pubkey(issuer_pubkey)[0]
File "/home/thomas/silkaj-v0.6.5/silkaj/money.py", line 96, in get_amount_from_pubkey
listinput, amount = get_sources(pubkey)
File "/home/thomas/silkaj-v0.6.5/silkaj/money.py", line 108, in get_sources
sources = get_request("tx/sources/" + pubkey)["sources"]
File "/home/thomas/silkaj-v0.6.5/silkaj/network_tools.py", line 158, in get_request
ep = EndPoint().ep
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/thomas/silkaj-v0.6.5/silkaj/network_tools.py", line 101, in __init__
ep["domain"], ep["port"] = ctx.obj["PEER"].rsplit(":", 1)
ValueError: not enough values to unpack (expected 2, got 1)
with v0.6.5 and allSources :
silkaj -p g1.cgeek.fr --auth-file tx --output HeZJHAc58PB8PjE3aX9NydeALCdQZkECkrmz1ViZjXo4 --allSources
Traceback (most recent call last):
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/bin/silkaj", line 7, in <module>
exec(compile(f.read(), __file__, 'exec'))
File "/home/thomas/silkaj-v0.6.5/bin/silkaj", line 25, in <module>
manage_cmd()
File "/home/thomas/silkaj-v0.6.5/silkaj/cli_tools.py", line 85, in manage_cmd
cli(obj={})
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/thomas/silkaj-v0.6.5/silkaj/cli_tools.py", line 183, in cliTransaction
amount, amountud, allsources, output, comment, outputbackchange, yes
File "/home/thomas/silkaj-v0.6.5/silkaj/tx.py", line 49, in send_transaction
pubkey_amount = get_amount_from_pubkey(issuer_pubkey)[0]
File "/home/thomas/silkaj-v0.6.5/silkaj/money.py", line 96, in get_amount_from_pubkey
listinput, amount = get_sources(pubkey)
File "/home/thomas/silkaj-v0.6.5/silkaj/money.py", line 108, in get_sources
sources = get_request("tx/sources/" + pubkey)["sources"]
File "/home/thomas/silkaj-v0.6.5/silkaj/network_tools.py", line 158, in get_request
ep = EndPoint().ep
File "/home/thomas/.local/share/virtualenvs/silkaj-v0.6.5-0qDwUMlP/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/thomas/silkaj-v0.6.5/silkaj/network_tools.py", line 101, in __init__
ep["domain"], ep["port"] = ctx.obj["PEER"].rsplit(":", 1)
ValueError: not enough values to unpack (expected 2, got 1)
Edited by Moul