diff --git a/silkaj/tx.py b/silkaj/tx.py index ae22ab6558f8eb8a0c5ccbe2b873b3bd1c47e3a0..aab2390a9ccf5d6b933a03f685981f988824ae3e 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -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: