Skip to content

Commit 2ecf2f1

Browse files
authored
Add: price details when creating flows (instance create cmd), full price details (instance list cmd), available amount (account balance cmd) (#266)
1 parent 98f1f07 commit 2ecf2f1

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/aleph_client/commands/account.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,15 @@ async def balance(
148148
response = await session.get(uri)
149149
if response.status == 200:
150150
balance_data = await response.json()
151+
balance_data["available_amount"] = balance_data["balance"] - balance_data["locked_amount"]
151152
typer.echo(
152153
"\n"
153-
+ "\n".join([f"{k.capitalize().replace('_', ' ')}: {v}" for k, v in balance_data.items()])
154+
+ f"Address: {balance_data['address']}\n"
155+
+ f"Balance: {balance_data['balance']:.2f}".rstrip("0").rstrip(".")
156+
+ "\n"
157+
+ f" - Locked: {balance_data['locked_amount']:.2f}".rstrip("0").rstrip(".")
158+
+ "\n"
159+
+ f" - Available: {balance_data['available_amount']:.2f}".rstrip("0").rstrip(".")
154160
+ "\n"
155161
)
156162
else:

src/aleph_client/commands/instance/__init__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def validate_ssh_pubkey_file(file: Union[str, Path]) -> Path:
402402
await wait_for_confirmed_flow(account, message.content.payment.receiver)
403403
if flow_hash:
404404
echo(
405-
f"Flow {flow_hash} has been created:\n\t- price/sec: {price.required_tokens:.7f} ALEPH\n\t- receiver: {crn.stream_reward_address}"
405+
f"Flow {flow_hash} has been created:\n - Aleph cost summary:\n {price.required_tokens:.7f}/sec | {3600*price.required_tokens:.2f}/hour | {86400*price.required_tokens:.2f}/day | {2592000*price.required_tokens:.2f}/month\n - CRN receiver address: {crn.stream_reward_address}"
406406
)
407407

408408
# Notify CRN
@@ -556,21 +556,41 @@ async def _show_instances(messages: List[InstanceMessage], node_list: NodeInfo):
556556
link = f"https://explorer.aleph.im/address/ETH/{message.sender}/message/INSTANCE/{message.item_hash}"
557557
# link = f"{settings.API_HOST}/api/v0/messages/{message.item_hash}"
558558
item_hash_link = Text.from_markup(f"[link={link}]{message.item_hash}[/link]", style="bright_cyan")
559+
is_hold = str(info["payment"]).startswith("hold")
559560
payment = Text.assemble(
560561
"Payment: ",
561562
Text(
562563
str(info["payment"]).capitalize(),
563-
style="red" if str(info["payment"]).startswith("hold") else "orange3",
564+
style="red" if is_hold else "orange3",
564565
),
565566
)
567+
cost: Text | str = ""
568+
if not is_hold:
569+
async with AlephHttpClient(api_server=settings.API_HOST) as client:
570+
price: PriceResponse = await client.get_program_price(message.item_hash)
571+
psec = Text(f"{price.required_tokens:.7f}/sec", style="bright_magenta")
572+
phour = Text(f"{3600*price.required_tokens:.2f}/hour", style="bright_magenta")
573+
pday = Text(f"{86400*price.required_tokens:.2f}/day", style="bright_magenta")
574+
pmonth = Text(f"{2592000*price.required_tokens:.2f}/month", style="bright_magenta")
575+
cost = Text.assemble("Aleph cost: ", psec, " | ", phour, " | ", pday, " | ", pmonth, "\n")
566576
confidential = (
567577
Text.assemble("Type: ", Text("Confidential", style="green"))
568578
if info["confidential"]
569579
else Text.assemble("Type: ", Text("Regular", style="grey50"))
570580
)
571581
chain = Text.assemble("Chain: ", Text(str(info["chain"]), style="cyan"))
572582
instance = Text.assemble(
573-
"Item Hash ↓\t Name: ", name, "\n", item_hash_link, "\n", payment, " ", confidential, "\n", chain
583+
"Item Hash ↓\t Name: ",
584+
name,
585+
"\n",
586+
item_hash_link,
587+
"\n",
588+
payment,
589+
" ",
590+
confidential,
591+
"\n",
592+
cost,
593+
chain,
574594
)
575595
specifications = (
576596
f"vCPUs: {message.content.resources.vcpus}\n"

0 commit comments

Comments
 (0)