Commit 25709396 authored by matograine's avatar matograine

* Deal with sources number when creating large numbers of tips

  * modify get_list_input_for_transaction
  * add maxinputsnumber...

* small dialog improvements
parent 3b91c40d
......@@ -44,11 +44,13 @@ class Creating:
#self.transfer = False
if self.key and self.pages <= MAX_PAGES:
print ("Création des Ğ1Dons...")
Generator(self.pdf_output, self.wallets, self.amount, self.date, self.pages).generate()
try:
self.save_json()
transfer = Transfer(self.amount, self.pages, self.wallets, self.date)
if self.amount > 0:
print ("Transferts...")
transfer.transfer(self.key)
except:
self.transfer_error()
......
......@@ -92,7 +92,6 @@ class Retrieve():
for doc in file_list:
i = self.folder + doc
if self.extract_files(i, retrieve_files):
print ("\n")
backup_data(i, doc)
if retrieve_files == None:
message_exit("Aucun don n'est périmé.")
......@@ -139,6 +138,7 @@ class Retrieve():
key_list.append(key)
for key, pubkey in zip(key_list, retrieve_files):
if key is not None:
print("Récupération des pourboires créée par la clef {0}...".format(pubkey))
for content in retrieve_files[pubkey]:
ok = await self.retrieve_wallets(content, key)
if ok is False:
......
......@@ -18,8 +18,7 @@ along with utils.silkaj. If not, see <https://www.gnu.org/licenses/>.
SILKAJ_VERSION = "0.7.3"
G1_SYMBOL = "Ğ1"
GTEST_SYMBOL = "ĞTest"
#G1_DEFAULT_ENDPOINT = "duniter.moul.re", "443" #"g1.duniter.org", "443"
G1_DEFAULT_ENDPOINT = "g1-test.cgeek.fr", "443"
G1_DEFAULT_ENDPOINT = "g1.duniter.org", "443"
G1_TEST_DEFAULT_ENDPOINT = "ts.gt.librelois.fr", "443"
CONNECTION_TIMEOUT = 10
ASYNC_SLEEP = 0.1
......
......@@ -38,6 +38,17 @@ from duniterpy.api.bma.tx import process
from duniterpy.documents import BlockUID, Transaction
from duniterpy.documents.transaction import OutputSource, Unlock, SIGParameter
# max size for tx doc is 100 lines. Formula for accepted field numbers is : (2 * IU + 2 * IS + O) <= ( MAX_LINES - FIX_LINES)
# with IU = inputs/unlocks ; IS = Issuers/Signatures ; O = Outouts.
MAX_LINES_IN_TX_DOC = 100
# 2 lines are necessary, and we block 1 more for the comment
FIX_LINES = 3
# assuming there is only 1 issuer and 2 outputs, max inputs is 46
MAX_INPUTS_PER_TX = 46
# assuming there is 1 issuer and 1 input, max outputs is 93.
MAX_OUTPUTS = 93
"""
#@command("tx", help="Send transaction")
#@option(
......@@ -257,9 +268,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 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
......@@ -268,16 +281,34 @@ async def get_list_input_for_transaction(pubkey, TXamount):
listinputfinal.append(input)
totalAmountInput += amount_in_current_base(input)
TXamount -= 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")
return listinputfinal, totalAmountInput, intermediatetransaction
def max_inputs_number(outputs_number, issuers_number=1, comment=True):
"""
Returns the maximum number of inputs.
This function does not take care of backchange line.
Formula is Inputs_Unlock number <= (MAX_LINES - FIX_LINES - Comment - Output_number - 2* Issuer_Signature_number)/2
"""
if comment == True:
comment = 1
return (
MAX_LINES_IN_TX_DOC
- FIX_LINES
- comment
- (2 * issuers_number)
- outputs_number
) / 2
# Créer une fonction handle_transactions_with_conditions
# qui gèrerait l'ajout de conditions spécifiques pour G1pourboire :
# SIG(0) || SIG(sender_pubkey) && CSV(time)
......@@ -293,7 +324,7 @@ async def handle_intermediaries_transactions(
client = ClientInstance().client
while True:
listinput_and_amount = await get_list_input_for_transaction(
issuers, totalAmount
issuers, totalAmount, len(outputAddresses)
)
intermediatetransaction = listinput_and_amount[2]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment