diff --git a/silkaj/money.py b/silkaj/money.py index 2da4c89e004ed3851a97142148f72c322efb5331..c032b7dc6b6513201be60c643b9276a1d29dac34 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -120,7 +120,7 @@ async def get_amount_from_pubkey(pubkey): totalAmountInput = 0 for input in listinput: - totalAmountInput += input.amount * 10 ** input.base + totalAmountInput += amount_in_current_base(input) return totalAmountInput, amount @@ -133,7 +133,6 @@ async def get_sources(pubkey): amount = 0 for source in sources["sources"]: if source["conditions"] == "SIG(" + pubkey + ")": - amount += source["amount"] * 10 ** source["base"] listinput.append( InputSource( amount=source["amount"], @@ -143,6 +142,7 @@ async def get_sources(pubkey): index=source["noffset"], ) ) + amount += amount_in_current_base(listinput[-1]) # pending source history = await client(tx.pending, pubkey) @@ -204,3 +204,10 @@ class UDValue(object): NBlastUDblock = blockswithud["result"]["blocks"][-1] lastUDblock = await client(blockchain.block, NBlastUDblock) return lastUDblock["dividend"] * 10 ** lastUDblock["unitbase"] + + +def amount_in_current_base(source): + """ + Get amount in current base from input or output source + """ + return source.amount * 10 ** source.base diff --git a/silkaj/tx.py b/silkaj/tx.py index d4dff0479c72fc80db12fe5a265e125fb23ec56d..48bf5753fe63c96d079c0c492cad36de613fc9d9 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -26,7 +26,12 @@ from silkaj.crypto_tools import check_public_key from silkaj.tools import message_exit, CurrencySymbol, coroutine from silkaj.auth import auth_method from silkaj.wot import get_uid_from_pubkey -from silkaj.money import get_sources, get_amount_from_pubkey, UDValue +from silkaj.money import ( + get_sources, + get_amount_from_pubkey, + UDValue, + amount_in_current_base, +) from silkaj.constants import NO_MATCHING_ID from duniterpy.api.bma.tx import process @@ -326,8 +331,8 @@ async def get_list_input_for_transaction(pubkey, TXamount): intermediatetransaction = False for input in listinput: listinputfinal.append(input) - totalAmountInput += input.amount * 10 ** input.base - TXamount -= input.amount * 10 ** input.base + totalAmountInput += amount_in_current_base(input) + TXamount -= amount_in_current_base(input) # if more 40 sources, it's an intermediate transaction if len(listinputfinal) >= 40: intermediatetransaction = True