diff --git a/silkaj/tx.py b/silkaj/tx.py index b5259dc3bece15c158d2a7fda5382102a1510e13..7f62613d86835a21098d4a81df6d54d50756a3e2 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)