Improve the wallet output formatting
This commit is contained in:
12
wallet.py
12
wallet.py
@@ -7,7 +7,7 @@ from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat
|
|||||||
def format_address(raw_address):
|
def format_address(raw_address):
|
||||||
return base64.b64encode(raw_address).decode()
|
return base64.b64encode(raw_address).decode()
|
||||||
|
|
||||||
def format_amount(amount, show_plus = True):
|
def format_amount(amount, width, show_plus = True):
|
||||||
color_prefix = ""
|
color_prefix = ""
|
||||||
color_suffix = ""
|
color_suffix = ""
|
||||||
sign = "+ " if show_plus else ""
|
sign = "+ " if show_plus else ""
|
||||||
@@ -17,11 +17,13 @@ def format_amount(amount, show_plus = True):
|
|||||||
sign = "- "
|
sign = "- "
|
||||||
amount = -amount
|
amount = -amount
|
||||||
coins = amount / 100
|
coins = amount / 100
|
||||||
return f"{color_prefix}{sign}{coins:.02f} cc{color_suffix}"
|
amount_str = f"{sign}{coins:.02f}"
|
||||||
|
amount_str = f"{amount_str:>{width}}"
|
||||||
|
return f"{color_prefix}{amount_str} cc{color_suffix}"
|
||||||
|
|
||||||
def write_transaction(timestamp, message, amount):
|
def write_transaction(timestamp, message, amount):
|
||||||
formatted_time = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(timestamp))
|
formatted_time = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(timestamp))
|
||||||
print(f"{formatted_time} {message:<44} {format_amount(amount):>14}")
|
print(f"{formatted_time} {message:<44} {format_amount(amount, 11)}")
|
||||||
|
|
||||||
def show_balance(public_key):
|
def show_balance(public_key):
|
||||||
public_key_raw = public_key.public_bytes(Encoding.Raw, PublicFormat.Raw)
|
public_key_raw = public_key.public_bytes(Encoding.Raw, PublicFormat.Raw)
|
||||||
@@ -50,8 +52,8 @@ def show_balance(public_key):
|
|||||||
write_transaction(timestamp, "mining reward", 100 + fee)
|
write_transaction(timestamp, "mining reward", 100 + fee)
|
||||||
total_amount += 100 + fee
|
total_amount += 100 + fee
|
||||||
print(81 * "\u2500")
|
print(81 * "\u2500")
|
||||||
amount_string = f"\U0001f955 \x1b[1;37m{format_amount(total_amount, False)}\x1b[0m"
|
amount_string = f"\U0001f955 \x1b[1;37m{format_amount(total_amount, 41, False)}\x1b[0m"
|
||||||
print(21 * " " + f"\x1b[1;37mYour balance:\x1b[0m{amount_string:>57}")
|
print(21 * " " + f"\x1b[1;37mYour balance:\x1b[0m{amount_string}")
|
||||||
|
|
||||||
def parse_amount(amount):
|
def parse_amount(amount):
|
||||||
amount = amount.replace(",", ".")
|
amount = amount.replace(",", ".")
|
||||||
|
|||||||
Reference in New Issue
Block a user