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

[feat] #111 : Send multiple amounts

* modify handle_intermediary_transactions() generate_and_send_transaction() and generate_transaction_document()
* all will now :
	* use the total_tx_amount variable
	* use tx_amounts list
* ! Code is stable, but tests should not pass.
parent d6ebc0d4
No related branches found
No related tags found
No related merge requests found
......@@ -290,23 +290,30 @@ async def get_list_input_for_transaction(pubkey, TXamount):
async def handle_intermediaries_transactions(
key, issuers, AmountTransfered, outputAddresses, Comment="", OutputbackChange=None
key,
issuers,
tx_amounts,
total_tx_amount,
outputAddresses,
Comment="",
OutputbackChange=None,
):
client = ClientInstance().client
while True:
listinput_and_amount = await get_list_input_for_transaction(
issuers, AmountTransfered * len(outputAddresses)
issuers, total_tx_amount
)
intermediatetransaction = listinput_and_amount[2]
if intermediatetransaction:
totalAmountInput = listinput_and_amount[1]
totalAmountInput = [listinput_and_amount[1]]
await generate_and_send_transaction(
key,
issuers,
total_tx_amount,
totalAmountInput,
listinput_and_amount,
issuers,
[issuers],
"Change operation",
)
sleep(1) # wait 1 second before sending a new transaction
......@@ -315,7 +322,8 @@ async def handle_intermediaries_transactions(
await generate_and_send_transaction(
key,
issuers,
AmountTransfered,
total_tx_amount,
tx_amounts,
listinput_and_amount,
outputAddresses,
Comment,
......@@ -328,7 +336,8 @@ async def handle_intermediaries_transactions(
async def generate_and_send_transaction(
key,
issuers,
amount,
total_tx_amount,
tx_amounts,
listinput_and_amount,
outputAddresses,
Comment,
......@@ -344,18 +353,19 @@ async def generate_and_send_transaction(
else:
print("Generate Transaction:")
print(" - From: " + issuers)
if isinstance(outputAddresses, str):
display_sent_tx(outputAddresses, amount)
else:
if len(tx_amounts) == 1:
for outputAddress in outputAddresses:
display_sent_tx(outputAddress, amount)
if len(outputAddresses) > 1:
print(" - Total: " + str(amount / 100 * len(outputAddresses)))
display_sent_tx(outputAddress, tx_amounts[0])
elif len(tx_amounts) > 1:
for tx_amount, outputAddress in zip(tx_amounts, outputAddresses):
display_sent_tx(outputAddress, tx_amount)
print(" - Total: " + str(total_tx_amount / 100))
client = ClientInstance().client
transaction = await generate_transaction_document(
issuers,
amount,
total_tx_amount,
tx_amounts,
listinput_and_amount,
outputAddresses,
Comment,
......@@ -377,15 +387,14 @@ def display_sent_tx(outputAddress, amount):
async def generate_transaction_document(
issuers,
AmountTransfered,
total_tx_amount,
tx_amounts,
listinput_and_amount,
outputAddresses,
Comment="",
OutputbackChange=None,
):
totalAmountTransfered = AmountTransfered * len(outputAddresses)
listinput = listinput_and_amount[0]
totalAmountInput = listinput_and_amount[1]
......@@ -399,22 +408,23 @@ async def generate_transaction_document(
# if it's not a foreign exchange transaction, we remove units after 2 digits after the decimal point.
if issuers not in outputAddresses:
totalAmountTransfered = (
totalAmountTransfered // 10 ** curentUnitBase
total_tx_amount = (
total_tx_amount // 10 ** curentUnitBase
) * 10 ** curentUnitBase
# Generate output
################
listoutput = []
# Outputs to receiver (if not himself)
if isinstance(outputAddresses, str):
generate_output(listoutput, curentUnitBase, AmountTransfered, outputAddresses)
else:
if len(tx_amounts) == 1:
# Outputs to receiver (if not himself)
for outputAddress in outputAddresses:
generate_output(listoutput, curentUnitBase, AmountTransfered, outputAddress)
generate_output(listoutput, curentUnitBase, tx_amounts[0], outputAddress)
else:
for tx_amount, outputAddress in zip(tx_amounts, outputAddresses):
generate_output(listoutput, curentUnitBase, tx_amount, outputAddress)
# Outputs to himself
rest = totalAmountInput - totalAmountTransfered
rest = totalAmountInput - total_tx_amount
generate_output(listoutput, curentUnitBase, rest, OutputbackChange)
# Unlocks
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment