This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------Transaction history------------------------------------------------------------ | |
# Reads the data from the account file and displays it to the user. | |
# If full_history is True it will print all transactions that are saved. | |
# If full_history is false it will print only confirmed transactions unless the transaction is no older then | |
# 6 hours, then it will print the transaction regardless of it's confirmation state | |
def print_transaction_history(full_history=False, print_history=True): | |
regex = r"^(?=.*?[9])(?=.*?[A-Z])[A-Z9_]+$" | |
current_unix_time = time.time() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes the prepared transaction data and sends it to the IOTA node for attaching itto the tangle | |
def send_transfer(prepared_transferes): | |
print("Sending transfer, this can take a while...") | |
change_addy = bytes(get_deposit_address()) | |
api = Iota(iota_node, seed) | |
api.send_transfer( | |
depth=7, | |
transfers=prepared_transferes, | |
change_address=change_addy, | |
min_weight_magnitude=18 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Will ask the user to enter the amount and Units (Iota, MegaIota, GigaIota,etc.) | |
def transfer_value_user_input(): | |
print("\n\nEnter a number and the the unit size.\n" | |
"Avaliable units are \"i\"(Iota), \"ki\"(KiloIota), \"mi\"(MegaIota), " | |
"\"gi\"(GigaIota) and \"ti\"(TerraIota)\n" | |
"Example: If you enter \"12.3 gi\", I will send 12.3 GigaIota\n") | |
ask_user = True | |
while ask_user: | |
user_input = raw_input("Please enter the amount to send: ") | |
user_input = user_input.upper() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Displays all addresses with balance, the total account balance and a deposit address. | |
# In case that there are no saved addresses it will ask if the account should be scanned for balance | |
# If the User answers with no, then it will just generate a deposit address (at index 0) | |
def standard_account_info(): | |
address_count = len(address_data) | |
update_addresses_balance(fal_balance[0]["f_index"]) | |
update_fal_balance() | |
if address_count < 1: | |
find_balance(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Displays all saved addresses and there balance | |
def full_account_info(): | |
update_addresses_balance(fal_balance[0]["f_index"]) | |
update_fal_balance() | |
if len(address_data) > 0: | |
all_address_data = "" | |
for p in address_data: | |
address = p["address"] | |
checksum = p["checksum"] | |
balance = int(p["balance"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gets the first address after the last address with balance. If there is no saved address it will generate a new one | |
def get_deposit_address(): | |
try: | |
l_index = fal_balance[0]["l_index"] | |
if l_index == 0: | |
deposit_address = address_data[0]["address"] | |
return deposit_address | |
for p in address_data: | |
address = p["address"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Writes the index, address and balance, as well as the checksum of address + seed into the account file | |
def write_address_data(index, address, balance): | |
address = address_checksum(address) | |
for p in address_data: | |
if p["address"] == address: | |
p["balance"] = balance | |
with open(file_name, 'w') as account_data: | |
json.dump(raw_account_data, account_data) | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes the f_index and/or the l_index and saves them in the account file | |
# "f_index" is the index of the first address with balance and "l_index" is the index of the last address with balance | |
def write_fal_balance(f_index=0, l_index=0): | |
if f_index > 0 and l_index > 0: | |
fal_balance[0]["f_index"] = f_index | |
fal_balance[0]["l_index"] = l_index | |
elif f_index > 0: | |
fal_balance[0]["f_index"] = f_index | |
elif l_index > 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Updates the f_index and l_index | |
def update_fal_balance(): | |
index_with_value = [] | |
for data in address_data: | |
if data["balance"] > 0: | |
index = data["index"] | |
index_with_value.append(index) | |
if len(index_with_value) > 0: |