Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

fix: decimal precision issue with balance shell command #80

Merged
merged 5 commits into from
Apr 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix precision issue
mvadari committed Apr 14, 2022
commit c4a34848ce6ac5a4d8f0c050b900451573280cf5
1 change: 1 addition & 0 deletions slk/repl/repl.py
Original file line number Diff line number Diff line change
@@ -362,6 +362,7 @@ def do_balance(self: SidechainRepl, line: str) -> None:
assert arg_index == len(args)

result = get_balances_data(chains, chain_names, account_ids, assets, in_drops)
print(result)
print(
tabulate(
result,
6 changes: 5 additions & 1 deletion slk/repl/repl_functionality.py
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ def get_pending_tx_info(
for t in pending:
amt = t["amount"]
if is_xrp(amt):
amt = drops_to_xrp(amt)
amt = format(drops_to_xrp(amt), ",.6f")
if not verbose:
pending_info = {
"chain": short_chain_name,
@@ -304,14 +304,18 @@ def get_balances_data(
result = []
for chain, chain_name, acc, asset in zip(chains, chain_names, account_ids, assets):
chain_result = chain.get_balances(acc, asset)
print(chain_result)
for chain_res in chain_result:
chain.substitute_nicknames(chain_res)
if not in_drops and chain_res["currency"] == "XRP":
print(chain_res["balance"], drops_to_xrp(chain_res["balance"]))
chain_res["balance"] = drops_to_xrp(chain_res["balance"])
chain_res["balance"] = format(chain_res["balance"], ",.6f")
else:
try:
chain_res["balance"] = int(chain_res["balance"])
except ValueError:
print(chain_res["balance"], float(chain_res["balance"]))
chain_res["balance"] = float(chain_res["balance"])
chain_short_name = "main" if chain_name == "mainchain" else "side"
chain_res["account"] = chain_short_name + " " + chain_res["account"]