Commit 6e53f92f authored by Moul's avatar Moul
Browse files

[enh] #7: Use async for UDValue

parent 17ece06c
......@@ -34,11 +34,11 @@ async def cmd_amount(cli_args):
total = [0, 0]
for pubkey in pubkeys:
value = await get_amount_from_pubkey(pubkey)
show_amount_from_pubkey(pubkey, value)
await show_amount_from_pubkey(pubkey, value)
total[0] += value[0]
total[1] += value[1]
if len(pubkeys) > 1:
show_amount_from_pubkey("Total", total)
await show_amount_from_pubkey("Total", total)
else:
seed = auth_method(cli_args)
pubkey = get_publickey_from_seed(seed)
......@@ -46,13 +46,13 @@ async def cmd_amount(cli_args):
await client.close()
def show_amount_from_pubkey(pubkey, value):
async def show_amount_from_pubkey(pubkey, value):
totalAmountInput = value[0]
amount = value[1]
# output
currency_symbol = CurrencySymbol().symbol
ud_value = UDValue().ud_value
ud_value = await UDValue().ud_value
average, monetary_mass = get_average()
if totalAmountInput - amount != 0:
print("Blockchain:")
......@@ -189,7 +189,11 @@ class UDValue(object):
return UDValue.__instance
def __init__(self):
blockswithud = get_request("blockchain/with/ud")["result"]
NBlastUDblock = blockswithud["blocks"][-1]
lastUDblock = get_request("blockchain/block/" + str(NBlastUDblock))
self.ud_value = lastUDblock["dividend"] * 10 ** lastUDblock["unitbase"]
self.ud_value = self.get_ud_value()
async def get_ud_value(self):
client = ClientInstance().client
blockswithud = await client(blockchain.ud)
NBlastUDblock = blockswithud["result"]["blocks"][-1]
lastUDblock = await client(blockchain.block, NBlastUDblock)
return lastUDblock["dividend"] * 10 ** lastUDblock["unitbase"]
......@@ -38,7 +38,9 @@ async def send_transaction(cli_args):
"""
Main function
"""
tx_amount, output, comment, allSources, outputBackChange = cmd_transaction(cli_args)
tx_amount, output, comment, allSources, outputBackChange = await cmd_transaction(
cli_args
)
seed = auth_method(cli_args)
issuer_pubkey = get_publickey_from_seed(seed)
......@@ -77,7 +79,7 @@ async def send_transaction(cli_args):
)
def cmd_transaction(cli_args):
async def cmd_transaction(cli_args):
"""
Retrieve values from command line interface
"""
......@@ -92,7 +94,9 @@ def cmd_transaction(cli_args):
if cli_args.contains_definitions("amount"):
tx_amount = float(cli_args.get_definition("amount")) * 100
if cli_args.contains_definitions("amountUD"):
tx_amount = float(cli_args.get_definition("amountUD")) * UDValue().ud_value
tx_amount = (
float(cli_args.get_definition("amountUD")) * await UDValue().ud_value
)
output = cli_args.get_definition("output")
comment = (
......@@ -147,7 +151,9 @@ async def transaction_confirmation(
tx.append(
[
"tx amount (relative)",
str(round(tx_amount / UDValue().ud_value, 4)) + " UD " + currency_symbol,
str(round(tx_amount / await UDValue().ud_value, 4))
+ " UD "
+ currency_symbol,
]
)
tx.append(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment