From 1d063d7f6526b50e677c3f137338f5e50a32883c Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Fri, 7 Dec 2018 11:44:29 +0100 Subject: [PATCH] [mod] #72: tx: use generic f() to generate tx outputs. --- silkaj/tx.py | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/silkaj/tx.py b/silkaj/tx.py index b5259dc3..7f62613d 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -252,40 +252,11 @@ def generate_transaction_document( listoutput = [] # Outputs to receiver (if not himself) for outputAddress in outputAddresses: - rest = AmountTransfered - unitbase = curentUnitBase - while rest > 0: - outputAmount = truncBase(rest, unitbase) - rest -= outputAmount - if outputAmount > 0: - outputAmount = int(outputAmount / math.pow(10, unitbase)) - listoutput.append( - str(outputAmount) - + ":" - + str(unitbase) - + ":SIG(" - + outputAddress - + ")" - ) - unitbase = unitbase - 1 + generate_output(listoutput, curentUnitBase, AmountTransfered, outputAddresses) # Outputs to himself - unitbase = curentUnitBase rest = totalAmountInput - totalAmountTransfered - while rest > 0: - outputAmount = truncBase(rest, unitbase) - rest -= outputAmount - if outputAmount > 0: - outputAmount = int(outputAmount / math.pow(10, unitbase)) - listoutput.append( - str(outputAmount) - + ":" - + str(unitbase) - + ":SIG(" - + OutputbackChange - + ")" - ) - unitbase = unitbase - 1 + generate_output(listoutput, curentUnitBase, rest, OutputbackChange) # Generate transaction document ############################## @@ -311,6 +282,23 @@ def generate_transaction_document( return transaction_document +def generate_output(listoutput, unitbase, rest, recipient_address): + while rest > 0: + outputAmount = truncBase(rest, unitbase) + rest -= outputAmount + if outputAmount > 0: + outputAmount = int(outputAmount / math.pow(10, unitbase)) + listoutput.append( + str(outputAmount) + + ":" + + str(unitbase) + + ":SIG(" + + recipient_address + + ")" + ) + unitbase = unitbase - 1 + + def get_list_input_for_transaction(pubkey, TXamount, allinput=False): listinput, amount = get_sources(pubkey) -- GitLab