Skip to content

Commit

Permalink
Add: price details when creating flows (instance create cmd), full pr…
Browse files Browse the repository at this point in the history
…ice details (instance list cmd), available amount (account balance cmd) (#266)
  • Loading branch information
philogicae authored Sep 5, 2024
1 parent 98f1f07 commit 2ecf2f1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/aleph_client/commands/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,15 @@ async def balance(
response = await session.get(uri)
if response.status == 200:
balance_data = await response.json()
balance_data["available_amount"] = balance_data["balance"] - balance_data["locked_amount"]
typer.echo(
"\n"
+ "\n".join([f"{k.capitalize().replace('_', ' ')}: {v}" for k, v in balance_data.items()])
+ f"Address: {balance_data['address']}\n"
+ f"Balance: {balance_data['balance']:.2f}".rstrip("0").rstrip(".")
+ "\n"
+ f" - Locked: {balance_data['locked_amount']:.2f}".rstrip("0").rstrip(".")
+ "\n"
+ f" - Available: {balance_data['available_amount']:.2f}".rstrip("0").rstrip(".")
+ "\n"
)
else:
Expand Down
26 changes: 23 additions & 3 deletions src/aleph_client/commands/instance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def validate_ssh_pubkey_file(file: Union[str, Path]) -> Path:
await wait_for_confirmed_flow(account, message.content.payment.receiver)
if flow_hash:
echo(
f"Flow {flow_hash} has been created:\n\t- price/sec: {price.required_tokens:.7f} ALEPH\n\t- receiver: {crn.stream_reward_address}"
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}"
)

# Notify CRN
Expand Down Expand Up @@ -556,21 +556,41 @@ async def _show_instances(messages: List[InstanceMessage], node_list: NodeInfo):
link = f"https://explorer.aleph.im/address/ETH/{message.sender}/message/INSTANCE/{message.item_hash}"
# link = f"{settings.API_HOST}/api/v0/messages/{message.item_hash}"
item_hash_link = Text.from_markup(f"[link={link}]{message.item_hash}[/link]", style="bright_cyan")
is_hold = str(info["payment"]).startswith("hold")
payment = Text.assemble(
"Payment: ",
Text(
str(info["payment"]).capitalize(),
style="red" if str(info["payment"]).startswith("hold") else "orange3",
style="red" if is_hold else "orange3",
),
)
cost: Text | str = ""
if not is_hold:
async with AlephHttpClient(api_server=settings.API_HOST) as client:
price: PriceResponse = await client.get_program_price(message.item_hash)
psec = Text(f"{price.required_tokens:.7f}/sec", style="bright_magenta")
phour = Text(f"{3600*price.required_tokens:.2f}/hour", style="bright_magenta")
pday = Text(f"{86400*price.required_tokens:.2f}/day", style="bright_magenta")
pmonth = Text(f"{2592000*price.required_tokens:.2f}/month", style="bright_magenta")
cost = Text.assemble("Aleph cost: ", psec, " | ", phour, " | ", pday, " | ", pmonth, "\n")
confidential = (
Text.assemble("Type: ", Text("Confidential", style="green"))
if info["confidential"]
else Text.assemble("Type: ", Text("Regular", style="grey50"))
)
chain = Text.assemble("Chain: ", Text(str(info["chain"]), style="cyan"))
instance = Text.assemble(
"Item Hash ↓\t Name: ", name, "\n", item_hash_link, "\n", payment, " ", confidential, "\n", chain
"Item Hash ↓\t Name: ",
name,
"\n",
item_hash_link,
"\n",
payment,
" ",
confidential,
"\n",
cost,
chain,
)
specifications = (
f"vCPUs: {message.content.resources.vcpus}\n"
Expand Down

0 comments on commit 2ecf2f1

Please sign in to comment.