Skip to content
Snippets Groups Projects
Commit 4405ee78 authored by matograine's avatar matograine
Browse files

issue #111.

* adding amount_computation() function
* adding check_amount() generic function for --amount and --amountUD
parent eb48b1f9
No related branches found
No related tags found
No related merge requests found
Pipeline #7081 failed
......@@ -81,8 +81,6 @@ async def send_transaction(
outputAddresses = output.split(":")
tx_amounts, total_tx_amount = await transaction_amount(amount, amountud, outputAddresses)
#tx_amounts = tx_amounts_and_total[0]
#total_tx_amount = tx_amounts_and_total[1]
key = auth_method()
issuer_pubkey = key.pubkey
......@@ -130,7 +128,19 @@ async def send_transaction(
)
def amount_computation(amount, multiplicator):
return round( amount * multiplicator) #, -2) # "-2" is for testing on GTest. Change to round (amount * multiplicator) for prod.
return round( amount * multiplicator , -2) # "-2" is for testing on GTest. Change to round (amount * multiplicator) for prod.
def check_amount(amounts, amount, minimal_amount, multiplicator, reference):
for amount in amount.split(":"):
test_amount = amount.split(".")
if ( ( len(test_amount) == 2 and test_amount[1].isdigit() ) or len(test_amount) == 1 ) and test_amount[0].isdigit() and float(amount) >= minimal_amount:
amount = amount_computation(float(amount), multiplicator)
amounts.append(amount)
else:
if reference == "unit":
message_exit ("Error : \"" + str(amount) + "\" is not a number or is inferior to 0.01.")
if reference == "UD":
message_exit ("Error : \"" + str(amount) + "\" is not a number.")
async def transaction_amount(amount, amountUD, outputAddresses):
"""
......@@ -139,28 +149,11 @@ async def transaction_amount(amount, amountUD, outputAddresses):
"""
amounts = list()
if amount:
for amount in amount.split(":"):
try:
amount = float(amount)
assert float(amount) >= MINIMAL_TX_AMOUNT
# if isinstance (amount, (float, int)) and amount >= MINIMAL_TX_AMOUNT:
amount = amount_computation(amount, CENT_MULT_TO_UNIT)
amounts.append(amount)
except:
# else:
message_exit ("Error : \"" + str(amount) + "\" is not a number or is inferior to 0.01.")
check_amount(amounts, amount, MINIMAL_TX_AMOUNT, CENT_MULT_TO_UNIT, "unit")
if amountUD:
for amount in amountUD.split(":"):
try:
amount = float(amount)
# if isinstance (amountUD, (float, int)):
amount = amount_computation(amount, await UDValue().ud_value)
amounts.append(amount)
except:
# else:
message_exit ("Error : \"" + str (amount) + "\" is not a number")
UD_value = await UDValue().ud_value
check_amount (amounts, amountUD, 0, UD_value, "UD")
# calculating the total
if len(amounts) != len(outputAddresses) and len(amounts) != 1:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment