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

[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
parent 45024390
No related branches found
No related tags found
No related merge requests found
......@@ -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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment