Last active
September 21, 2017 10:04
-
-
Save simform-solutions/4741fd3e34bfcf76a96e940fcdb270e0 to your computer and use it in GitHub Desktop.
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() | |
sorted_transactions = sorted(transfers_data, key=itemgetter('timestamp')) # Sort the transactions by timestamp | |
addresses_with_new_transactions = [] | |
addresses_with_confirmed_transactions = [] | |
all_transactions = [] | |
new_transactions = [] | |
old_confirmed_transactions = [] | |
for addy in sorted_transactions: | |
timestamp = addy['timestamp'] | |
is_confirmed = str(addy['is_confirmed']) | |
if int(current_unix_time) - int(timestamp) < 25200: | |
address = address_checksum(str(addy['address'])) | |
addresses_with_new_transactions.append(address) | |
elif is_confirmed == "True": | |
address = address_checksum(str(addy['address'])) | |
addresses_with_confirmed_transactions.append(address) | |
addresses_with_confirmed_transactions = set(addresses_with_confirmed_transactions) | |
addresses_with_confirmed_transactions = list(addresses_with_confirmed_transactions) | |
addresses_with_new_transactions = set(addresses_with_new_transactions) | |
addresses_with_new_transactions = list(addresses_with_new_transactions) | |
for transaction in sorted_transactions: | |
timestamp = int(transaction['timestamp']) | |
txn_time = datetime.datetime.fromtimestamp( | |
int(timestamp) | |
).strftime('%Y-%m-%d %H:%M:%S') | |
is_confirmed = str(transaction['is_confirmed']) | |
transaction_hash = transaction['transaction_hash'] | |
address = address_checksum(str(transaction['address'])) | |
bundle = transaction['bundle'] | |
tag = transaction['tag'] | |
value = transaction['value'] | |
if full_history: | |
data = {'txn_time': str(txn_time), 'address': str(address), 'transaction_hash': str(transaction_hash), | |
'value': str(value), 'tag': str(tag), 'bundle': str(bundle), 'is_confirmed': str(is_confirmed)} | |
all_transactions.append(data) | |
elif current_unix_time - timestamp < 25200: | |
data = {'txn_time': str(txn_time), 'address': str(address), 'transaction_hash': str(transaction_hash), | |
'value': str(value), 'tag': str(tag), 'bundle': str(bundle), 'is_confirmed': str(is_confirmed)} | |
new_transactions.append(data) | |
elif is_confirmed == "True": | |
data = {'txn_time': str(txn_time), 'transaction_hash': str(transaction_hash), | |
'address': str(address), 'value': str(value), 'bundle': str(bundle), 'tag': str(tag)} | |
old_confirmed_transactions.append(data) | |
if len(new_transactions) > 0 and not full_history: | |
if print_history: | |
print("\n\n\n New Transactions") | |
print("--------------------------------------------------------------------------------------------------------" | |
"---------") | |
for addy in addresses_with_new_transactions: | |
addy = address_checksum(str(addy)) | |
if print_history: | |
print("\nTransactions to/from: " + str(addy) + "\n") | |
for data in new_transactions: | |
address = data['address'] | |
if address == addy: | |
txn_time = data['txn_time'] | |
transaction_hash = data['transaction_hash'] | |
value = data['value'] | |
bundle = data['bundle'] | |
tag = data['tag'] | |
is_confirmed = data['is_confirmed'] | |
if re.search(regex, tag): | |
if bundle not in bundleList: | |
bundleList.append(bundle) | |
execute_command(tag.strip('9')) | |
if print_history: | |
print(" " + txn_time + "\n" + | |
" Txn Hash: " + transaction_hash + " " + str(convert_units(value)) + "\n" + | |
" Bundle: " + bundle + "\n" + | |
" Tag: " + tag.strip( '9' ) + "\n" + | |
" Confirmed: " + is_confirmed + "\n") | |
if len(old_confirmed_transactions) > 0 and not full_history: | |
if print_history: | |
print("\n\n\n Old Confirmed Transactions") | |
print("--------------------------------------------------------------------------------------------------------" | |
"---------") | |
for addy in addresses_with_confirmed_transactions: | |
addy = address_checksum(str(addy)) | |
if print_history: | |
print("\nTransactions to/from: " + str(addy) + "\n") | |
for data in old_confirmed_transactions: | |
address = data['address'] | |
if address == addy: | |
txn_time = data['txn_time'] | |
transaction_hash = data['transaction_hash'] | |
value = data['value'] | |
bundle = data['bundle'] | |
tag = data['tag'] | |
if re.search(regex, tag): | |
if bundle not in bundleList: | |
bundleList.append(bundle) | |
execute_command(tag.strip('9')) | |
if print_history: | |
print(" " + txn_time + "\n" + | |
" Txn Hash: " + transaction_hash + " " + str(convert_units(value)) + "\n" + | |
" Bundle: " + bundle + "\n" + | |
" Tag: " + tag.strip( '9' ) + "\n") | |
if len(new_transactions) == 0 and len(old_confirmed_transactions) == 0 and len(all_transactions) == 0 and print_history: | |
print("No transactions in history!") | |
elif full_history: | |
print("\n\n\n Full transaction history") | |
print("--------------------------------------------------------------------------------------------------------" | |
"---------\n\n") | |
for data in all_transactions: | |
address = data['address'] | |
txn_time = data['txn_time'] | |
transaction_hash = data['transaction_hash'] | |
value = data['value'] | |
bundle = data['bundle'] | |
tag = data['tag'] | |
is_confirmed = data['is_confirmed'] | |
print(" " + txn_time + "\n" + | |
" To/From: " + address + "\n" | |
" Txn Hash: " + transaction_hash + " " + str(convert_units(value)) + "\n" + | |
" Bundle: " + bundle + "\n" + | |
" Tag: " + tag + "\n" + | |
" Confirmed: " + is_confirmed + "\n") | |
account_history_executing = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment