Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simform-solutions/651ae72e1052f691a0f6a0d9e5781ce6 to your computer and use it in GitHub Desktop.
Save simform-solutions/651ae72e1052f691a0f6a0d9e5781ce6 to your computer and use it in GitHub Desktop.
# Gets all necessary data from the user to make one or more transfers
def prepare_transferes():
new_transfer = True
prepared_transferes = []
while new_transfer:
get_recipient_address = True
while get_recipient_address:
recipient_address = raw_input("\nPlease enter the receiving address: ")
if len(recipient_address) == 81:
print("You enterd a address without checksum. Are you sure you want to continiue?")
yes = yes_no_user_input()
if yes:
get_recipient_address = False
else:
print("Good choice! Addresses with checksum are a lot safer to use.")
elif len(recipient_address) == 90:
is_valid = is_valid_address(recipient_address)
if is_valid:
get_recipient_address = False
else:
print("Invalid address!! Please try again!")
else:
print("\nYou enterd a invalid address. Address must be 81 or 90 Char long!")
recipient_address = bytes(recipient_address)
user_message = raw_input("Please enter a message: ")
user_tag = raw_input("Please enter a tag: ")
user_tag = bytes(user_tag)
transfer_value = transfer_value_user_input()
txn = \
ProposedTransaction(
address=Address(
recipient_address
),
message=TryteString.from_string(user_message),
tag=Tag(user_tag),
value=transfer_value,
)
prepared_transferes.append(txn)
print("Do you want to prepare another transfer?")
yes = yes_no_user_input()
if not yes:
new_transfer = False
review_transfers(prepared_transferes)
# Before a transfer is actually sent, it will be displayed and can be canceled or confirmed by the user
def review_transfers(prepared_transferes):
transfers_to_print = ""
for txn in prepared_transferes:
address = str(txn.address)
value = str(convert_units(int(txn.value)))
line = "------------------------------------------------" \
"--------------------------------------------------------------\n"
transfers_to_print += address + " | " + value + "\n" + line
print("\n\n\nDestination: "
" | Value:\n"
"-----------------------------------------------------"
"---------------------------------------------------------")
print(transfers_to_print)
print("\n\nPlease review the transfer(s) carefully!\n")
ask_user = True
while ask_user:
user_input = raw_input("\nEnter \"confirm\" to send the transfer(s)\n"
"Enter \"cancel\" to cancel the transfer(s)")
user_input = user_input.upper()
if user_input == "CONFIRM":
print("\n\nOkay, sending transfer(s) now. This can take a while...")
ask_user = False
try:
send_transfer(prepared_transferes)
except:
print("A error occurred :(")
elif user_input == "CANCEL":
print("\n\nTransfer(s) canceled!")
ask_user = False
else:
print("Ups, I didn't understand that. Please try again!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment