Skip to content

Commit f1f0a27

Browse files
committed
added command
1 parent a5541b5 commit f1f0a27

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/communex/cli/balance.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import re
2-
from typing import Optional
2+
from typing import Optional, cast
33

44
import typer
55
from typer import Context
66

77
from communex._common import IPFS_REGEX, BalanceUnit, format_balance
8-
from communex.balance import to_nano
8+
from communex.balance import from_nano, to_nano
99
from communex.cli._common import (
1010
make_custom_context,
1111
print_table_from_plain_dict,
1212
)
13+
from communex.compat.key import local_key_addresses
1314
from communex.errors import ChainTransactionError
1415
from communex.faucet.powv2 import solve_for_difficulty_fast
1516

@@ -339,3 +340,32 @@ def bridge_withdraw(
339340
context.error(f"Failed to withdraw {amount} tokens: {e}")
340341
else:
341342
context.info(f"Withdrew {amount}$j successfully")
343+
344+
345+
@balance_app.command()
346+
def bridged_balance(
347+
ctx: Context,
348+
key: Optional[str] = None,
349+
):
350+
context = make_custom_context(ctx)
351+
client = context.com_client()
352+
with context.progress_status("Getting bridged balance..."):
353+
bridge_map = client.query_map(
354+
"Bridged", params=[], extract_value=False
355+
)["Bridged"]
356+
bridge_map = cast(dict[str, int], bridge_map)
357+
if key is None:
358+
local_keys = local_key_addresses(context.password_manager)
359+
local_bridge_map = {
360+
address: from_nano(ammount)
361+
for address, ammount in bridge_map.items()
362+
if address in local_keys.values()
363+
}
364+
else:
365+
key = cast(str, context.resolve_key_ss58(key, None))
366+
bridged_amount = from_nano(bridge_map.get(key, 0))
367+
local_bridge_map = {key: bridged_amount}
368+
369+
print_table_from_plain_dict(
370+
local_bridge_map, ["Address", "Amount"], context.console
371+
)

0 commit comments

Comments
 (0)