From df5d6bd3d04c58a66d446f2f89fce4dc911b572d Mon Sep 17 00:00:00 2001 From: matograine <tom.ngr@zaclys.net> Date: Fri, 14 Feb 2020 13:59:13 +0100 Subject: [PATCH] [feat] #281 : limit inputs number * modification of get_list_inputs_for_transaction() to return intermediary tx with as much inputs as possible. * modification of handle_intermediary_transactions() * remove SOURCES_PER_TX constant --- silkaj/tx.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/silkaj/tx.py b/silkaj/tx.py index acaf8ed5..0f7348be 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -28,7 +28,6 @@ from silkaj.tools import message_exit, CurrencySymbol, coroutine from silkaj.auth import auth_method from silkaj import money from silkaj.constants import ( - SOURCES_PER_TX, MINIMAL_TX_AMOUNT, CENT_MULT_TO_UNIT, ABSOLUTE_REF, @@ -279,9 +278,11 @@ async def transaction_confirmation( return tx -async def get_list_input_for_transaction(pubkey, TXamount): +async def get_list_input_for_transaction(pubkey, TXamount, outputs_number): listinput, amount = await money.get_sources(pubkey) + # check max inputs. For now we deal only with one issuer + maxInputsNumber = max_inputs_number(outputs_number, 1) # generate final list source listinputfinal = [] totalAmountInput = 0 @@ -290,11 +291,10 @@ async def get_list_input_for_transaction(pubkey, TXamount): listinputfinal.append(input) totalAmountInput += money.amount_in_current_base(input) TXamount -= money.amount_in_current_base(input) - # if more than 40 sources, it's an intermediate transaction - if len(listinputfinal) >= SOURCES_PER_TX: + # if too much sources, it's an intermediate transaction + if len(listinputfinal) >= maxInputsNumber and not len(listinputfinal) == 1: intermediatetransaction = True - break - if TXamount <= 0: + if (len(listinputfinal) >= MAX_INPUTS_PER_TX) or (TXamount <= 0): break if TXamount > 0 and not intermediatetransaction: message_exit("Error: you don't have enough money") @@ -311,9 +311,10 @@ async def handle_intermediaries_transactions( OutputbackChange=None, ): client = ClientInstance().client + while True: listinput_and_amount = await get_list_input_for_transaction( - issuers, total_tx_amount + issuers, total_tx_amount, (len(outputAddresses) + 1) ) intermediatetransaction = listinput_and_amount[2] -- GitLab